Every line of 'replace special characters in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
1 export function escapeSpecialChars(str) { 2 return str 3 .replace(/&/g, "&") 4 .replace(//g, ">") 5 .replace(/"/g, """) 6 .replace(/'/g, "'"); 7 }
151 function escape(code) { 152 return code.replace(/}
31 function escape ( string ) { 32 return string.replace( /[^]/g, char => { 33 const code = char.charCodeAt(); 34 35 if ( code < 256 ) return char; 36 37 const escape = code.toString(16); 38 const long = escape.length > 2; 39 return `\\${long ? 'u' : 'x'}${('0000' + escape).slice( long ? -4 : -2 )}`; 40 }); 41 }
1215 function _UnescapeSpecialChars (text) { 1216 // 1217 // Swap back in all the special characters we've hidden. 1218 // 1219 text = text.replace(/~E(\d+)E/g, 1220 function (wholeMatch, m1) { 1221 var charCodeToReplace = parseInt(m1) 1222 return String.fromCharCode(charCodeToReplace) 1223 } 1224 ) 1225 return text 1226 }
94 function escapeCode(code) { 95 var str = code; 96 str = str.replace(//g, ">"); 97 return str; 98 }
406 function escape(input) { 407 if (typeof input !== 'string') { 408 // Backup check for non-strings 409 return input; 410 } 411 412 const output = input.replace(/[<>&'"]/g, char => { 413 switch (char) { 414 case '<': 415 return '<'; 416 417 case '>': 418 return '>'; 419 420 case '&': 421 return '&'; 422 423 case `'`: 424 return '''; 425 426 case '"': 427 return '"'; 428 } 429 }); 430 return output; 431 }
23 function escape(str: string): string { 24 return str.replace(/"/g, '"', ) 25 .replace(/&/g, '&') 26 .replace(//g, '>') 27 }
62 function escape(str) { 63 str = str.replace(/'/g, "\\'"); 64 return str; 65 }
29 export function escape(str: string): string { 30 return ('' + str).replace( 31 UNSAFE_CHARS_REGEX, 32 match => ESCAPED_CHARS[match.charCodeAt(0)] 33 ); 34 }
21 function escape(str: string): string { 22 return str.replace(UNSAFE_CHAR, s => { 23 return '\\u' + ('000' + s.charCodeAt(0).toString(16)).substr(-4); 24 }); 25 }