import { get } from './object' ; /** Converts string to kebab-case notation */ export const toKebabCase = ( str ) : string => { return str . replace ( /([a-z])([A-Z])/g , '$1-$2' ) . replace ( /[\s_]+/g , '-' ) . toLowerCase ( ) ; } ; /** Converts string to camelCase notation */ export const toCamelCase = ( str ) : string => { return str . trim ( ) . replace ( /[\s-,_]+([a-zA-Z0-9]?)/g , ( match , word ) => word . toUpperCase ( ) ) ; } ; /** Makes the first non-indent (space, tab, newline) letter in the string capitalized */ export const capitalize = ( str ) : string => { let i = 0 ; while ( i < str . length && ( str [ i ] === ' ' || str [ i ] === '\t' || str [ i ] === '\n' ) ) i ++ ; return str . slice ( 0 , i ) + str . charAt ( i ) . toUpperCase ( ) + str . slice ( i + 1 ) ; } ; /** Unwraps string from parenthesis */ export const unwrapParenthesis = ( str ) : string => { return str . trim ( ) . replace ( /^\((.*)\)$/ , '$1' ) . trim ( ) ; } ; /**
 * Parses number with the ability to pass an alternative fallback for NaN.
 * Note: falsy values except 0 are treated as NaN
 */ export const parseNumber = ( str , nanValue ? ) : number | undefined => { if ( str === 0 ) return 0 ; const value = + ( str || NaN ) ; return isNaN ( value ) ? nanValue : value ; } ; example param str returns export function parseAspectRatio ( str ) { const [ w , h ] = str . split ( /[:/]/ ) ; if ( typeof h !== 'undefined' ) return + w / + h ; return + w || 0 ; } /** Evaluates passed string or returns `defaultValue` */ export function evaluate ( str , defaultValue ? ) { try { return str ? ( new Function ( `return ${ str }` ) ) ( ) : defaultValue ; } catch ( e ) { console . warn ( 'Cannot parse value ' , str , e ) ; return defaultValue ; } } /** Default RegExp to match replacements in the string for the  format function  export const DEF_FORMAT_MATCHER = /{[{%]?([\w.]+)[%}]?}/g ; /** Replaces `{key}` patterns in the string from the source object */ export function format ( str , source , matcher = DEF_FORMAT_MATCHER ) { return str . replace ( matcher , ( match , key ) => { const val = get ( source , key ) ; return val === undefined ? match : val ; } ) ; }