export function escapeRegExp ( string ) { return string . replace ( /[.*+?^${}()|[\]\\]/g , '\\$&' ) ; } /**
 * CSS Selector Escape
 */ export function escapeSelector ( str ) { const length = str . length ; let index = - 1 ; let codeUnit ; let result = '' ; const firstCodeUnit = str . charCodeAt ( 0 ) ; while ( ++ index < length ) { codeUnit = str . charCodeAt ( index ) ; if ( codeUnit === 0x0000 ) { result += '\uFFFD' ; continue ; } if ( codeUnit === 44 ) { result += '\\2c ' ; continue ; } if ( ( codeUnit >= 0x0001 && codeUnit <= 0x001F ) || codeUnit === 0x007F || ( index === 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 ) || ( index === 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit === 0x002D ) ) { result += `\\${ codeUnit . toString ( 16 ) } ` ; continue ; } if ( index === 0 && length === 1 && codeUnit === 0x002D ) { result += `\\${ str . charAt ( index ) }` ; continue ; } if ( codeUnit >= 0x0080 || codeUnit === 0x002D || codeUnit === 0x005F || ( codeUnit >= 0x0030 && codeUnit <= 0x0039 ) || ( codeUnit >= 0x0041 && codeUnit <= 0x005A ) || ( codeUnit >= 0x0061 && codeUnit <= 0x007A ) ) { result += str . charAt ( index ) ; continue ; } result += `\\${ str . charAt ( index ) }` ; } return result ; } export const e = escapeSelector ;