import { customAlphabet } from 'nanoid' ; import { NanoID } from '../Dimension' ; param obj param params export const pick = < T , K extends keyof T > ( obj , ... params ) : Pick < T , K > => { const picked = { } ; params . forEach ( ( key ) => { picked [ key ] = obj [ key ] ; } ) ; return picked ; } ; const ALPHA_NUM_STRING = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ; const idGenFunctionMap = new Map ( ) ; for ( let i = 4 ; i <= 22 ; i ++ ) { idGenFunctionMap . set ( i , customAlphabet ( ALPHA_NUM_STRING , i ) ) ; } param n export const genID = ( n ) : NanoID => { return idGenFunctionMap . get ( n ) ( ) ; } ; export const stripFunctions = < T extends { [ x in string ] : any ; } > ( object ) : NoFunctions < T > => { const seen = new Set < any > ( ) ; const helper = ( object ) : NoFunctions < T > => { for ( const key in object ) { if ( ! seen . has ( key ) ) { seen . add ( key ) ; if ( typeof object [ key ] === 'function' ) { delete object [ key ] ; continue ; } else if ( object [ key ] !== null && object [ key ] !== undefined && object [ key ] . constructor . name === 'Array' ) { continue ; } helper ( object [ key ] ) ; } } return object ; } ; return helper ( object ) ; } ; export type NoFunctions < T > = T extends object ? T extends Function ? null : { [ K in keyof T ] : NoFunctions < T [ K ] > ; } : T ; export const stripNull = < T extends { [ x in string ] : any ; } > ( object ) : T => { const seen = new Set < any > ( ) ; const helper = ( object ) : T => { for ( const key in object ) { if ( ! seen . has ( key ) ) { seen . add ( key ) ; if ( object [ key ] === null ) { delete object [ key ] ; } else { helper ( object [ key ] ) ; } } } return object ; } ; return helper ( object ) ; } ; param ms export const sleep = async ( ms ) : Promise < void > => { return new Promise ( ( resolve ) => { setTimeout ( ( ) => { resolve ( ) ; } , ms ) ; } ) ; } ; export const noop = ( ) : void => { } ;