UNPKG

japanese-string-utils

Version:

The utils convert Japanese strings to other forms, such as Hiragana, Katakana, Full-width, Half-width, numeric and others.

17 lines (10 loc) 373 B
export function addCommas( numericString: string ): string { const rgx = /(\d+)(\d{3})/; const x = String( numericString ).split( '.' ); let integerPart = x[ 0 ]; const fractionalPart = x.length > 1 ? '.' + x[ 1 ] : ''; while ( rgx.test( integerPart ) ) { integerPart = integerPart.replace( rgx, '$1' + ',' + '$2' ); } return integerPart + fractionalPart; }