import { timestamp } from './timestamp' ; import path from 'path' ; import minimatch from 'minimatch' ; import _ from 'lodash' ; export function isString ( value ) { return typeof value === 'string' ; } export function isNumber ( value ) { return typeof value === 'number' ; } export function isFunction < T > ( value ) { return typeof value === 'function' ; } export function isArray < T > ( value ) { return Array . isArray ( value ) ; } export function isEmpty ( value ) { if ( value ) { return isArray ( value ) ? value . length === 0 : false ; } else { return true ; } } export function isUndefinedOrNull ( value ) { return value === undefined || value === null ; } export function keyBy < T > ( value , key ) { const result = { } ; ( value || [ ] ) . forEach ( item => { result [ item [ `${ key }` ] ] = item ; } ) ; return result ; } export function sortByOrderMap < T extends object > ( items , ordersMap ) { return items . sort ( ( a , b ) => { const aOrder = isNumber ( ordersMap . get ( a ) ) ? ordersMap . get ( a ) : Number . MAX_SAFE_INTEGER ; const bOrder = isNumber ( ordersMap . get ( b ) ) ? ordersMap . get ( b ) : Number . MAX_SAFE_INTEGER ; return aOrder > bOrder ? 1 : aOrder === bOrder ? 0 : - 1 ; } ) ; } export function extractExtname ( p , removeDot = false ) { const extname = path . extname ( p ) ; return removeDot ? extname . replace ( '.' , '' ) : extname ; } export function matchGlob ( target , pattern , options ? ) { if ( isArray ( pattern ) ) { return ! ! pattern . find ( item => { return minimatch ( target , item , options ) ; } ) ; } else { return minimatch ( target , pattern , options ) ; } } export function coerceArray < T > ( value ) { return Array . isArray ( value ) ? value : [ value ] ; } export function random ( lower = 0 , upper = 1 , floating = false ) { return _ . random ( lower , upper , floating ) ; } export function sample < T > ( collection ) { return _ . sample ( collection ) ; } export function uniq < T > ( collection ) { return _ . uniq ( collection ) ; } export function some < T > ( collection , predicate ) { return _ . some ( collection , predicate ) ; } export function wait ( milliseconds ) { return new Promise < void > ( resolve => { setTimeout ( ( ) => { return resolve ( ) ; } , milliseconds ) ; } ) ; } export * from './path' ; export { timestamp } ;