import { Nil } from "../types" ; param value export function isDefined < T > ( value ) { return ! ( value == null ) ; } param value export function isNil ( value ) { return value == null ; } param raw export function escapeRegex ( raw ) { return raw . replace ( /[-[\]{}()*+?.,\\^$|#\s]/g , "\\$&" ) ; } param base param prefix param maxTrims export function trimPrefix ( base , prefix , maxTrims = 1 ) { let processed = base ; for ( let i = 0 ; i < maxTrims || maxTrims === - 1 ; ++ i ) { if ( processed . startsWith ( prefix ) ) { processed = processed . slice ( prefix . length ) ; } else { break ; } } return processed ; } param input param regex export function splitFragments ( input , regex ) { const excludedFragments = input . split ( regex ) ; const matchedFragments = allMatches ( input , regex ) ; const sequence = [ ] ; const zippedLength = Math . min ( matchedFragments . length , excludedFragments . length ) ; for ( let i = 0 ; i < zippedLength ; ++ i ) { sequence . push ( excludedFragments [ i ] ) ; sequence . push ( matchedFragments [ i ] ) ; } if ( matchedFragments . length > excludedFragments . length ) { for ( let i = excludedFragments . length ; i < matchedFragments . length ; ++ i ) { sequence . push ( matchedFragments [ i ] ) ; } } else if ( matchedFragments . length < excludedFragments . length ) { for ( let i = matchedFragments . length ; i < excludedFragments . length ; ++ i ) { sequence . push ( excludedFragments [ i ] ) ; } } return sequence ; } param source export function remakeRegex ( source ) { return new RegExp ( source . source , source . flags ) ; } param string param regex export function allMatches ( string , regex ) { const remadeRegex = remakeRegex ( regex ) ; const matches = [ ] ; let currentMatch ; do { currentMatch = remadeRegex . exec ( string ) ; if ( currentMatch ) matches . push ( currentMatch [ 0 ] ) ; } while ( currentMatch ) ; return matches ; } param str export function capitalize ( str ) { if ( str . length === 0 ) return str ; return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ; }