twreporter-react
Version:
React-Redux site for The Reporter Foundation in Taiwan
17 lines (16 loc) • 481 B
JavaScript
;
module.exports = function (str) {
return str.replace(/(?:\\*)?"([^"\\]*\\.)*[^"]*"/g, function (match) {
return match
// unescape double-quotes
.replace(/\\"/g, '"')
// escape escapes
.replace(/(^|[^\\])(\\+)'/g, '$1$2\\\'')
// escape single-quotes - round 1
.replace(/([^\\])'/g, '$1\\\'')
// escape single-quotes - round 2 (for consecutive single-quotes)
.replace(/([^\\])'/g, '$1\\\'')
// convert
.replace(/^"|"$/g, '\'');
});
};