This file contains hidden or 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
| /** | |
| * Create delay promise | |
| * @param timeout Timeout delay in MS | |
| * @param value Value to resolve after timeout | |
| */ | |
| export async function delay<T>(timeout: number, value?: T) { | |
| return new Promise((resolve) => { | |
| const timeoutId = setTimeout(() => { | |
| resolve(value); | |
| clearTimeout(timeoutId); |
This file contains hidden or 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
| /** | |
| * Create new array | |
| * @param args | |
| */ | |
| export const create = <T>(...args: T[]): T[] => [...args]; | |
| /** | |
| * Push item to the list | |
| * @param item | |
| */ |
This file contains hidden or 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
| type Func<P = any, R = any> = (...args: P[]) => R; | |
| /** | |
| * Identity function | |
| * Return the given value all the time | |
| * @param value | |
| */ | |
| export function identity<T = any>(value: T): T { | |
| return value; | |
| } |
This file contains hidden or 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
| function distinctReducer<T>(key: keyof T, map: Map<any, boolean> = new Map<any, boolean>()) { | |
| return function (acc: T[], item: T) { | |
| if (!map.has(item[key])) { | |
| map.set(item[key], true); | |
| return [...acc, item]; | |
| } | |
| return acc; | |
| }; | |
| } |
This file contains hidden or 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 React from 'react'; | |
| export const enum TaskStatus { | |
| IDLE = 'IDLE', | |
| PROCESSING = 'PROCESSING', | |
| DONE = 'DONE', | |
| ERROR = 'ERROR', | |
| } | |
| export type Tasks<T> = Array<() => Promise<T>>; |
This file contains hidden or 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
| interface Result<T> { | |
| [key: string]: T[]; | |
| } | |
| function groupBy<T>(array: T[], key: keyof T): Result<T> { | |
| return array.reduce((acc: Result<T>, current: T) => { | |
| const currentKey = (current[key] as unknown) as string; | |
| acc[currentKey] = [...(acc[currentKey] || []), current]; | |
| return acc; | |
| }, {}); |
This file contains hidden or 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 React from "react"; | |
| /** | |
| * Type definition for merge reducer | |
| */ | |
| type MergeReducer<T> = (oldValue: T, newValue: Partial<T>) => T; | |
| /** | |
| * Merge two objects | |
| * @param oldValue Old state |
This file contains hidden or 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 React from 'react'; | |
| import { mount } from 'enzyme'; | |
| export function createCompoundComponent<T, U = any>(Parent: React.FC<T>, ...components: (React.FC<U> | string)[]) { | |
| return function Compound(props: React.PropsWithChildren<T>) { | |
| const { children, ...newProps } = props; | |
| let newChildren = React.Children | |
| .toArray(children) | |
| .filter(({ type }: any) => components.some(component => type === component)) |
This file contains hidden or 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 strict'; | |
| const fs = require('fs'); | |
| /** | |
| * Reducer for each line | |
| * @param {Object} conf Return value | |
| * @param {string} line env config line | |
| */ | |
| const reducer = (conf, line) => { | |
| const [key, value] = line.split('='); |
This file contains hidden or 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
| { | |
| "workbench.iconTheme": "material-icon-theme", | |
| "workbench.colorTheme": "Palenight Theme", | |
| "editor.fontFamily": "'Source Code Pro', 'Dank Mono','Cascadia Code', 'Source Code Pro', 'Fira Code', Consolas, 'Courier New', monospace", | |
| "editor.tabSize": 2, | |
| "editor.renderWhitespace": "boundary", | |
| "window.zoomLevel": 1, | |
| "editor.fontSize": 12, | |
| "editor.formatOnType": true, | |
| "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe", |