This commit is contained in:
Chris Kruining 2025-03-12 16:50:49 +01:00
parent 97036272dd
commit b1e617e74a
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
11 changed files with 476 additions and 186 deletions

View file

@ -46,6 +46,20 @@ const decodeReplacer = (_: any, char: EncodedChar) => ({
}[char.charAt(0) as ('t' | 'b' | 'n' | 'r' | 'f' | '\'' | '"' | 'u')]);
export const decode = (subject: string): string => subject.replace(decodeRegex, decodeReplacer);
const LAZY_SYMBOL = Symbol('not loaded');
export const lazy = <T>(fn: () => T): (() => T) => {
let value: T | symbol = LAZY_SYMBOL;
return () => {
if (value === LAZY_SYMBOL) {
value = fn();
}
return value as T;
}
};
/** @deprecated just use structuredClone instead */
export const deepCopy = <T>(original: T): T => {
if (typeof original !== 'object' || original === null || original === undefined) {
return original;