export function capitalize ( text ) { if ( text . length === 0 ) return '' ; return text [ 0 ] . toUpperCase ( ) + text . slice ( 1 ) . toLowerCase ( ) ; } export function sanitize ( text ) { return text . replace ( /[@+!#$%^&*()[\]./<>{}]/g , '' ) . normalize ( 'NFD' ) . replace ( /[\u0300-\u036f]/g , '' ) ; } export interface NormalizeOptions { alphanumeric ? : boolean ; allowSpaces ? : boolean ; allowUnderscore ? : boolean ; allowHyphens ? : boolean ; } export function normalize ( text , { alphanumeric = true , allowSpaces = false , allowUnderscore = true , allowHyphens = true , } = { } ) { if ( alphanumeric ) { text = text . replace ( /[^0-9a-zA-Z-_\s]/g , '' ) ; } if ( ! allowUnderscore ) { text = text . replace ( /_/g , '-' ) ; } if ( ! allowHyphens ) { text = text . replace ( /-/g , allowUnderscore ? '_' : ' ' ) ; } if ( ! allowSpaces ) { text = text . replace ( /\s/g , '' ) ; } text = text . replace ( /[-_\s]+$/ , '' ) ; return text ; } export function upper ( word ) { return word . toUpperCase ( ) ; } export function lower ( word ) { return word . toLowerCase ( ) ; } export function stem ( word ) { return word . replace ( /[aiueo]$/ , '' ) ; } export function germanify ( word ) { return word . replace ( 'c' , 'k' ) . replace ( 'C' , 'K' ) ; } export function njoin ( lhs , rhs , { elision = true } = { } ) { return elision ? lhs + rhs . replace ( new RegExp ( `^${ lhs [ - 1 ] }` , 'i' ) , '' ) : lhs + rhs ; }