export function slugify ( str ) { return str . replace ( /([a-z])([A-Z])/g , '$1-$2' ) . replace ( /[\s_]+/g , '-' ) . replace ( /[^\w\s-]/ , '' ) . toLowerCase ( ) ; } export function join ( array , separator = ',' ) { return array . join ( separator ) ; } export function keys ( object ) { return Object . keys ( object ) ; } export function reduce ( array , reducer , initialValue ) { return array . reduce ( reducer , initialValue ) ; } export function flatten ( array , depth = 1 , result = [ ] ) { if ( array == null || ! Array . isArray ( array ) ) { throw Error ( 'Argument must be an array!' ) ; } if ( ! array . length ) { return [ ] ; } for ( const value of array ) { if ( ! Array . isArray ( value ) ) { result . push ( value ) ; } else if ( depth > 0 ) { if ( depth > 1 ) { flatten ( value , depth - 1 , result ) ; } else { result . push ( ... value ) ; } } else { result [ result . length ] = value ; } } return result ; } export function add ( first , ... values ) { let allValues = Array . isArray ( first ) ? first : [ first , ... values ] ; return allValues . reduce < number > ( ( total , value ) => { let v = typeof value === 'string' ? parseFloat ( value ) : typeof value === 'number' ? value : null ; if ( v == null || isNaN ( v ) ) { throw Error ( 'Invalid argument type' ) ; } return v + total ; } , 0 ) ; }