You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
445 B
18 lines
445 B
'use strict';
|
|
|
|
/**
|
|
Escape string and wrap the result in quotes.
|
|
|
|
@param {string} string - The string to be quoted.
|
|
@param {string} quote - The quote character.
|
|
@returns {string} - The quoted and escaped string.
|
|
*/
|
|
module.exports = (string, quote = '\'') => {
|
|
const escaped = string
|
|
.replace(/\\/g, '\\\\')
|
|
.replace(/\r/g, '\\r')
|
|
.replace(/\n/g, '\\n')
|
|
.replace(new RegExp(quote, 'g'), `\\${quote}`);
|
|
return quote + escaped + quote;
|
|
};
|