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
/** | |
* Creates an array of elements split into groups the length of size | |
* | |
* @template T | |
* @param {T[]} input | |
* @param {number} size | |
* @returns {T[][]} | |
*/ | |
export const chunk = <T>(input: T[], size: number): T[][] => { | |
return input.reduce((array, item, index) => { |
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 RequireOnlyOne<T, Keys extends keyof T = keyof T> = | |
Pick<T, Exclude<keyof T, Keys>> | |
& { | |
[K in Keys]-?: | |
Required<Pick<T, K>> | |
& Partial<Record<Exclude<Keys, K>, undefined>> | |
}[Keys] |
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 RequireAtLeastOne<T, Keys extends keyof T = keyof T> = | |
Pick<T, Exclude<keyof T, Keys>> | |
& { | |
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> | |
}[Keys] |
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
export const hasKey = <T>(object: T, key: keyof any): key is keyof T => key in object |
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
export default <T>(value: T | null | undefined): value is T => !!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
import { useState, useCallback } from 'react' | |
export type Counter = { | |
count: number | |
increment: (value?: number | undefined) => void | |
decrement: (value?: number | undefined) => void | |
reset: (value?: number | undefined) => void | |
} | |
export default (initialValue: number = 0): Counter => { |
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 { useEffect, useState } from 'react'; | |
type Callback = (element?: string | number) => void | |
type TargetKey = string | number | Array<string|number> | |
const isNumber = (value: unknown): value is number => typeof value === 'number'; | |
const isString = (value: unknown): value is string => typeof value === 'string'; | |
const isNumberArray = (object: unknown): object is number[] => | |
Array.isArray(object) && object.every(e => isNumber(e)); |
NewerOlder