@@ -42,7 +42,7 @@ export function sortLength(a: string, b: string): number {
4242 * Quote a string for use in regular expressions
4343 *
4444 * @param {string } text The text whose regex characters are to be quoted
45- * @returns {string } The quoted string
45+ * @returns {string } The quoted string
4646 */
4747export function quotePattern ( text : string ) : string {
4848 return text . replace ( / ( [ \^ $ ( ) { } . + * ? \- | [ \] : \\ ] ) / g, '\\$1' ) ;
@@ -52,7 +52,7 @@ export function quotePattern(text: string): string {
5252 * Convert a UTF-8 string to an array of unicode code points
5353 *
5454 * @param {string } text The string to be turned into unicode positions
55- * @returns {number[] } Array of numbers representing the string's unicode character positions
55+ * @returns {number[] } Array of numbers representing the string's unicode character positions
5656 */
5757export function unicodeChars ( text : string ) : number [ ] {
5858 return Array . from ( text ) . map ( ( c ) => c . codePointAt ( 0 ) ) ;
@@ -62,7 +62,7 @@ export function unicodeChars(text: string): number[] {
6262 * Convert an array of unicode code points to a string
6363 *
6464 * @param {number[] } data The array of unicode code points
65- * @returns {string } The string consisting of the characters at those points
65+ * @returns {string } The string consisting of the characters at those points
6666 */
6767export function unicodeString ( data : number [ ] ) : string {
6868 return String . fromCodePoint ( ...data ) ;
@@ -71,7 +71,7 @@ export function unicodeString(data: number[]): string {
7171/**
7272 * Test if a value is a percentage
7373 *
74- * @param {string } x The string to test
74+ * @param {string } x The string to test
7575 * @returns {boolean } True if the string ends with a percent sign
7676 */
7777export function isPercent ( x : string ) : boolean {
@@ -81,23 +81,24 @@ export function isPercent(x: string): boolean {
8181/**
8282 * Split a space-separated string of values
8383 *
84- * @param {string } x The string to be split
84+ * @param {string } x The string to be split
8585 * @returns {string[] } The list of white-space-separated "words" in the string
8686 */
8787export function split ( x : string ) : string [ ] {
8888 return x . trim ( ) . split ( / \s + / ) ;
8989}
9090
9191/**
92- * Replace \U{...} with the specified unicode character
92+ * Replace \U{...} with the specified unicode character and \\ with \
9393 *
94- * @param {string } text The string to be scanned for \U{...}
95- * @returns {string } The string with the unicode characters in place of \U{...}
94+ * @param {string } text The string to be scanned for \U{...} and \\
95+ * @returns {string } The string with the unicode characters in place of \U{...}
9696 */
9797export function replaceUnicode ( text : string ) : string {
9898 return text . replace (
99- / ( (?: ^ | [ ^ \\ ] ) (?: \\ \\ ) * ) \\ U (?: ( [ 0 - 9 A - F a - f ] { 4 } ) | \{ \s * ( [ 0 - 9 A - F a - f ] { 1 , 6 } ) \s * \} ) / g,
100- ( _m , pre , h1 , h2 ) => pre + String . fromCodePoint ( parseInt ( h1 || h2 , 16 ) )
99+ / \\ U (?: ( [ 0 - 9 A - F a - f ] { 4 } ) | \{ \s * ( [ 0 - 9 A - F a - f ] { 1 , 6 } ) \s * \} ) | \\ ./ g,
100+ ( m , h1 , h2 ) =>
101+ m === '\\\\' ? '\\' : String . fromCodePoint ( parseInt ( h1 || h2 , 16 ) )
101102 ) ;
102103}
103104
0 commit comments