Skip to content
Permalink
758835d67a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Robert Brignull replace jest with ava
Latest commit 0347b72 May 4, 2020 History
0 contributors

Users who have contributed to this file

22 lines (22 sloc) 644 Bytes
module.exports = function (string) {
return ('' + string).replace(/["'\\\n\r\u2028\u2029]/g, function (character) {
// Escape all characters not included in SingleStringCharacters and
// DoubleStringCharacters on
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
switch (character) {
case '"':
case "'":
case '\\':
return '\\' + character
// Four possible LineTerminator characters need to be escaped:
case '\n':
return '\\n'
case '\r':
return '\\r'
case '\u2028':
return '\\u2028'
case '\u2029':
return '\\u2029'
}
})
}