/**
 * Debounce
 */ var now = ( ) => new Date ( ) . getTime ( ) ; export function debounce < T extends Function > ( func , milliseconds , immediate = false ) { var timeout , args , context , timestamp , result ; var wait = milliseconds ; var later = function ( ) { var last = now ( ) - timestamp ; if ( last < wait && last > 0 ) { timeout = setTimeout ( later , wait - last ) ; } else { timeout = null ; if ( ! immediate ) { result = func . apply ( context , args ) ; if ( ! timeout ) context = args = null ; } } } ; return < any > function ( ) { context = this ; args = arguments ; timestamp = now ( ) ; var callNow = immediate && ! timeout ; if ( ! timeout ) timeout = setTimeout ( later , wait ) ; if ( callNow ) { result = func . apply ( context , args ) ; context = args = null ; } return result ; } ; } ; type MapKey = string | number ; type MapableArray = MapKey [ ] ; export type TruthTable = { [ string ] : boolean ; [ number ] : boolean ; } ; /**
 * Create a quick lookup map from list
 */ export function createMap ( arr ) { return arr . reduce ( ( result , key ) => { result [ key ] = true ; return result ; } , < { [ string ] : boolean ; } > { } ) ; } export function throttle < T extends Function > ( func , milliseconds , options ? ) { var context , args , result ; var timeout = null ; var previous = 0 ; if ( ! options ) options = { } ; let gnow = now ; var later = function ( ) { previous = options . leading === false ? 0 : gnow ( ) ; timeout = null ; result = func . apply ( context , args ) ; if ( ! timeout ) context = args = null ; } ; return function ( ) { var now = gnow ( ) ; if ( ! previous && options . leading === false ) previous = now ; var remaining = milliseconds - ( now - previous ) ; context = this ; args = arguments ; if ( remaining <= 0 || remaining > milliseconds ) { if ( timeout ) { clearTimeout ( timeout ) ; timeout = null ; } previous = now ; result = func . apply ( context , args ) ; if ( ! timeout ) context = args = null ; } else if ( ! timeout && options . trailing !== false ) { timeout = setTimeout ( later , remaining ) ; } return result ; } as any ; } ; /** Useful for various editor related stuff e.g. completions */ var punctuations = createMap ( [ ';' , '{' , '}' , '(' , ')' , '.' , ':' , '<' , '>' , "'" , '"' ] ) ; /** Does the prefix end in punctuation */ export var prefixEndsInPunctuation = ( prefix ) => prefix . length && prefix . trim ( ) . length && punctuations [ prefix . trim ( ) [ prefix . trim ( ) . length - 1 ] ] ; /**
 * Promise.resolve is something I call the time (allows you to take x|promise and return promise ... aka make sync prog async if needed)
 */ export var resolve = Promise . resolve . bind ( Promise ) ;