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
/* | |
* https://www.voiceandcode.com/our-insights/2019/7/12/ux-best-practices-minimum-target-size-on-mobile-devices | |
*/ | |
:root { | |
--min-touch-target: 48px; | |
--min-touch-spacing: 10px; | |
} |
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 memoize = <F extends (...args: any) => any>(fn: F) => { | |
const cache = new Map(); | |
return (...args: Parameters<F>): ReturnType<F> => { | |
const key = args.join("-"); | |
if (cache.has(key)) return cache.get(key); | |
const result = fn(...args); |
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
/** @see https://web.dev/articles/optimize-long-tasks */ | |
export const yieldToMainThread = async (): Promise<void> => | |
globalThis.scheduler?.yield ? globalThis.scheduler.yield() : new Promise(resolve => setTimeout(resolve, 0)); |
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 digit = () => (crypto.getRandomValues(new Uint8Array(1)).at(0) ?? 0) % 10; | |
export const batch = (grouping = 5) => [...Array(grouping)].map(() => digit()).join(''); | |
export const otp = (capacity = 10_000, grouping = 5) => [...Array(capacity / grouping)].map(() => batch()).join(' '); |
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
const token = (): string => { | |
const valid = (id: string) => '1234567890'.split('').every(item => id.at(0) !== item); | |
const id = crypto.randomUUID().split('-').join(''); | |
return valid(id) ? id : token() | |
} | |
enum Size { | |
Small = 1, |
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
fixture.componentRef.setInput() |
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
// https://kyleshevlin.com/pattern-matching/ | |
const compass = (x: number): string => { | |
switch (true) { | |
case x < 0: return compass(x + 360); | |
case x === 0: return 'N'; | |
case x === 90: return 'E'; | |
case x === 180: return 'S'; | |
case x === 270: return 'W'; |
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
// https://www.typescriptlang.org/docs/handbook/2/functions.html#call-signatures | |
interface Lazy<T> { | |
(): T | |
} | |
interface WritableLazy<T> extends Lazy<T> { | |
asReadonly: () => Lazy<T> | |
set: (value: T) => void; | |
} |
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 { Buffer } from 'node:buffer'; | |
import { encode, decode } from '@msgpack/msgpack'; | |
export const serialize = <T>(data: T, kind: BufferEncoding = 'base64') => { | |
return typeof Buffer === 'undefined' | |
? btoa(typeof data === 'string' ? data : JSON.stringify(data)) | |
: Buffer.from(encode(data)).toString(kind); | |
}; | |
export const deserialize = <R>(data: string, kind: BufferEncoding = 'base64'): R => { |
NewerOlder