export const noop = ( ) => { } ; export const tick = ( fn = noop ) : Promise < undefined > => new Promise ( ( resolve ) => setTimeout ( resolve ) ) . then ( fn ) ; export const memo = ( fn , invalidate ? ) => { const cache = new Map ( ) ; return ( ... args ) => { let key ; if ( typeof invalidate === 'function' ) { const validOrKey = invalidate . apply ( fn , args ) ; if ( validOrKey === false ) { key = JSON . stringify ( args ) ; cache . delete ( key ) ; } else if ( validOrKey !== true ) { key = validOrKey ; } } if ( key === undefined ) { key = JSON . stringify ( args ) ; } if ( cache . has ( key ) ) { return cache . get ( key ) ; } const result = fn . apply ( fn , args ) ; cache . set ( key , result ) ; return result ; } ; } ; export function attrToVal ( str ) { if ( str === 'true' || str === 'false' ) { return str === 'true' ; } else if ( str === 'null' ) { return null ; } else if ( str === 'undefined' ) { return undefined ; } else if ( str !== '' && ! isNaN ( Number ( str ) ) ) { return Number ( str ) ; } else { try { return JSON . parse ( str ) ; } catch ( e ) { } } return str ; } export function camelCase ( str , pascal = false ) { const camel = str . replace ( /-([a-z])/g , ( _ , w ) => w . toUpperCase ( ) ) ; return pascal ? camel . replace ( /^\w/ , s => s . toUpperCase ( ) ) : camel ; } export function kebabCase ( str ) { return str . replace ( /[A-Z]/g , '-$&' ) . toLowerCase ( ) ; }