import { curry } from './functions' ; const asciiWords = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g ; const unicodeWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf \t\x0b\f\xa0\n\r]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde])+(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf \t\x0b\f\xa0\n\r]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff])+|[A-Z\xc0-\xd6\xd8-\xde]+|\d+/g ; const hasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/ ; param str returns { RegExpMatchArray | [ ] } export function words ( str ? ) { return ( str && str . match ( hasUnicodeWord . test ( str ) ? unicodeWords : asciiWords ) ) || [ ] ; } function mapWords ( str , wordMapFn , join = '' ) { return words ( str ) . map ( wordMapFn ) . join ( join ) ; } param s returns { string } export function lowerCase ( s ) { return s . toLowerCase ( ) ; } function caseStr ( casing , str ) { return mapWords ( str , lowerCase , casing ) ; } param s returns { string } export const kebabCase = curry ( caseStr ) ( '-' ) ; param s returns { string } export const snakeCase = curry ( caseStr ) ( '_' ) ; param str returns { string } export function capitalize ( str ) { return str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ; } param str returns { string } export function camelCase ( str ) { return mapWords ( str , ( word , i ) => { word = lowerCase ( word ) ; return i === 0 ? word : capitalize ( word ) ; } ) ; } param str returns { string } export function trim ( str ) { return str . trim ( ) ; } param wildcardPattern param flags returns { RegExp } export function wildcardToRegExp ( wildcardPattern , flags ? ) { const regexMatch = /^\/(.+)\/([im]+)?$/ . exec ( wildcardPattern ) ; if ( regexMatch ) { return new RegExp ( regexMatch [ 1 ] , regexMatch [ 2 ] || flags ) ; } const pattern = wildcardPattern . replace ( /[\-\[\]\/{}()?.\\^$|]/g , '\\$&' ) . replace ( /\*/g , '.*?' ) . replace ( /\+/g , '.+?' ) ; return new RegExp ( `^${ pattern }$` , flags ) ; }