This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as getRandomWord from "random-words"; | |
export const getRandomFloat = <T extends number = number>(min = 0, max = 1): T => { | |
return (Math.random() * (max - min) + min) as T; | |
}; | |
export const getRandomInt = <T extends number = number>(min = 0, max = 1): T => { | |
if (min === max) return min as T; | |
return Math.round(getRandomFloat(min, max)) as T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Effect, | |
Store, | |
combine, | |
guard, | |
createEvent, | |
restore, | |
sample, | |
} from "effector"; | |
import { status as patronumStatus } from "patronum"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { combine, createEvent, createStore, Event, guard, sample, StoreValue } from "effector"; | |
export const createUndoRedo = <S extends unknown>({ defaultState, filter, limit, name }: UndoRedoOptions<S>) => { | |
const storeName = name || "unknown-store"; | |
const $present = createStore(defaultState, { name: `history/${storeName}/present` }); | |
const limitPerTime = Math.round(limit / 2); | |
const $past = createStore<S[]>([], { name: `history/${storeName}/past` }); | |
const $future = createStore<S[]>([], { name: `history/${storeName}/future` }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
// https://github.com/wclr/ts-node-dev/issues/9 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name":"ts-node (src/index.ts)", | |
"type":"node", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Effect, Event, Store, createEvent, combine } from "effector"; | |
import { status } from "patronum"; | |
import { EffectState } from "patronum/status"; | |
export interface FetchingState { | |
loading: boolean; | |
done: boolean; | |
fail: boolean; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, RefObject, useEffect } from "react"; | |
export const useFocused = (inputRef: RefObject<HTMLInputElement>): boolean => { | |
const [isFocused, setFocused] = useState(false); | |
useEffect(() => { | |
if (inputRef.current) { | |
const handleFocus = (): void => setFocused(true); | |
const handleBlur = (): void => setFocused(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param initialValue {T} initial value | |
* @param callback {function} used to update value | |
*/ | |
export const createMemoContainer = <T, ExtraArgs extends unknown[] = []>( | |
initialValue: T, | |
callback: (currentValue: T, ...args: ExtraArgs) => T | null, | |
): ((...args: ExtraArgs) => T) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.hashCode = function() { | |
var hash = 0, i, chr; | |
if (this.length === 0) return hash; | |
for (i = 0; i < this.length; i++) { | |
chr = this.charCodeAt(i); | |
hash = ((hash << 5) - hash) + chr; | |
hash |= 0; // Convert to 32bit integer | |
} | |
return hash; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Node Inspector", | |
"type": "node", | |
"request": "launch", | |
"args": ["${workspaceRoot}/src/service.ts"], | |
"runtimeArgs": ["-r", "ts-node/register"], | |
"cwd": "${workspaceRoot}", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Schema } from "mongoose" | |
const modifierGetters = { | |
'array': input => [{...input}], | |
'required': input => { | |
const inputClone = input instanceof Array ? [{...input[0]}] : {...input} | |
if (inputClone instanceof Array) { | |
inputClone[0].required = true; |