Socket
Socket
Sign inDemoInstall

slashes

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slashes - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

57

lib/commonjs/add-slashes.js
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSlashes = void 0;
const get_escaped_any_1 = require("./get-escaped-any");
const get_escaped_json_unsafe_1 = require("./get-escaped-json-unsafe");
const addSlashes = (str, { getEscaped = get_escaped_json_unsafe_1.getEscapedJsonUnsafe } = {}) => {
let result = '';
for (const char of str) {
if (char === '\\') {
result += '\\\\';
continue;
var get_escaped_any_1 = require("./get-escaped-any");
var get_escaped_json_unsafe_1 = require("./get-escaped-json-unsafe");
var addSlashes = function (str, _a) {
var e_1, _b;
var _c = _a === void 0 ? {} : _a, _d = _c.getEscaped, getEscaped = _d === void 0 ? get_escaped_json_unsafe_1.getEscapedJsonUnsafe : _d;
var result = '';
try {
for (var str_1 = __values(str), str_1_1 = str_1.next(); !str_1_1.done; str_1_1 = str_1.next()) {
var char = str_1_1.value;
if (char === '\\') {
result += '\\\\';
continue;
}
var escaped = getEscaped(char);
if (!escaped) {
result += char;
}
else if (escaped === true) {
result += (0, get_escaped_any_1.getEscapedAny)(char);
}
else {
result += escaped;
}
}
const escaped = getEscaped(char);
if (!escaped) {
result += char;
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (str_1_1 && !str_1_1.done && (_b = str_1.return)) _b.call(str_1);
}
else if (escaped === true) {
result += (0, get_escaped_any_1.getEscapedAny)(char);
}
else {
result += escaped;
}
finally { if (e_1) throw e_1.error; }
}

@@ -24,0 +47,0 @@ return result;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEscapedAny = void 0;
const getEscapedAny = (char) => {
var getEscapedAny = function (char) {
switch (char) {

@@ -16,8 +16,8 @@ case '\b':

return '\\t';
case `"`:
return `\\${char}`;
case "\"":
return "\\".concat(char);
}
let unicode = '';
for (let index = char.length - 1; index >= 0; index--) {
unicode = `\\u${('000' + char.charCodeAt(index).toString(16)).slice(-4)}${unicode}`;
var unicode = '';
for (var index = char.length - 1; index >= 0; index--) {
unicode = "\\u".concat(('000' + char.charCodeAt(index).toString(16)).slice(-4)).concat(unicode);
}

@@ -24,0 +24,0 @@ return unicode;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEscapedJsonUnsafe = void 0;
const getEscapedJsonUnsafe = (char) => {
var getEscapedJsonUnsafe = function (char) {
switch (char) {

@@ -13,3 +13,3 @@ case '\b':

case '\0':
case `"`:
case "\"":
return true;

@@ -16,0 +16,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUnescapedAny = void 0;
const getUnescapedAny = (sequence, code) => {
var getUnescapedAny = function (sequence, code) {
if (code != null) {

@@ -6,0 +6,0 @@ return String.fromCodePoint(code);

"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripSlashes = exports.removeSlashes = void 0;
const get_unescaped_any_1 = require("./get-unescaped-any");
const removeSlashes = (source, { getUnescaped = get_unescaped_any_1.getUnescapedAny } = {}) => {
const rx = /(?:\\(u([0-9a-f]{4})|u\{([0-9a-f]+)\}|x([0-9a-f]{2})|(\d{1,3})|([\s\S]|$))|[\s\S])/giu;
let match;
let result = '';
var get_unescaped_any_1 = require("./get-unescaped-any");
var removeSlashes = function (source, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.getUnescaped, getUnescaped = _c === void 0 ? get_unescaped_any_1.getUnescapedAny : _c;
var rx = /(?:\\(u([0-9a-f]{4})|u\{([0-9a-f]+)\}|x([0-9a-f]{2})|(\d{1,3})|([\s\S]|$))|[\s\S])/giu;
var match;
var result = '';
while (null != (match = rx.exec(source))) {
const [sequence, escapedFallback, unicode, unicodePoint, hex, octal, char] = match;
var _d = __read(match, 7), sequence = _d[0], escapedFallback = _d[1], unicode = _d[2], unicodePoint = _d[3], hex = _d[4], octal = _d[5], char = _d[6];
try {

@@ -19,3 +36,3 @@ if (char != null) {

else {
const code = unicodePoint || unicode || hex;
var code = unicodePoint || unicode || hex;
if (code) {

@@ -29,3 +46,3 @@ result += getUnescaped(sequence, Number.parseInt(code, 16)) || escapedFallback;

}
catch {
catch (_error) {
result += escapedFallback;

@@ -37,4 +54,4 @@ }

exports.removeSlashes = removeSlashes;
const stripSlashes = removeSlashes;
var stripSlashes = removeSlashes;
exports.stripSlashes = stripSlashes;
//# sourceMappingURL=remove-slashes.js.map

@@ -0,20 +1,43 @@

var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { getEscapedAny } from './get-escaped-any';
import { getEscapedJsonUnsafe } from './get-escaped-json-unsafe';
const addSlashes = (str, { getEscaped = getEscapedJsonUnsafe } = {}) => {
let result = '';
for (const char of str) {
if (char === '\\') {
result += '\\\\';
continue;
var addSlashes = function (str, _a) {
var e_1, _b;
var _c = _a === void 0 ? {} : _a, _d = _c.getEscaped, getEscaped = _d === void 0 ? getEscapedJsonUnsafe : _d;
var result = '';
try {
for (var str_1 = __values(str), str_1_1 = str_1.next(); !str_1_1.done; str_1_1 = str_1.next()) {
var char = str_1_1.value;
if (char === '\\') {
result += '\\\\';
continue;
}
var escaped = getEscaped(char);
if (!escaped) {
result += char;
}
else if (escaped === true) {
result += getEscapedAny(char);
}
else {
result += escaped;
}
}
const escaped = getEscaped(char);
if (!escaped) {
result += char;
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (str_1_1 && !str_1_1.done && (_b = str_1.return)) _b.call(str_1);
}
else if (escaped === true) {
result += getEscapedAny(char);
}
else {
result += escaped;
}
finally { if (e_1) throw e_1.error; }
}

@@ -21,0 +44,0 @@ return result;

@@ -1,2 +0,2 @@

const getEscapedAny = (char) => {
var getEscapedAny = function (char) {
switch (char) {

@@ -13,8 +13,8 @@ case '\b':

return '\\t';
case `"`:
return `\\${char}`;
case "\"":
return "\\".concat(char);
}
let unicode = '';
for (let index = char.length - 1; index >= 0; index--) {
unicode = `\\u${('000' + char.charCodeAt(index).toString(16)).slice(-4)}${unicode}`;
var unicode = '';
for (var index = char.length - 1; index >= 0; index--) {
unicode = "\\u".concat(('000' + char.charCodeAt(index).toString(16)).slice(-4)).concat(unicode);
}

@@ -21,0 +21,0 @@ return unicode;

@@ -1,2 +0,2 @@

const getEscapedJsonUnsafe = (char) => {
var getEscapedJsonUnsafe = function (char) {
switch (char) {

@@ -10,3 +10,3 @@ case '\b':

case '\0':
case `"`:
case "\"":
return true;

@@ -13,0 +13,0 @@ }

@@ -1,2 +0,2 @@

const getUnescapedAny = (sequence, code) => {
var getUnescapedAny = function (sequence, code) {
if (code != null) {

@@ -3,0 +3,0 @@ return String.fromCodePoint(code);

@@ -0,8 +1,25 @@

var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { getUnescapedAny } from './get-unescaped-any';
const removeSlashes = (source, { getUnescaped = getUnescapedAny } = {}) => {
const rx = /(?:\\(u([0-9a-f]{4})|u\{([0-9a-f]+)\}|x([0-9a-f]{2})|(\d{1,3})|([\s\S]|$))|[\s\S])/giu;
let match;
let result = '';
var removeSlashes = function (source, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.getUnescaped, getUnescaped = _c === void 0 ? getUnescapedAny : _c;
var rx = /(?:\\(u([0-9a-f]{4})|u\{([0-9a-f]+)\}|x([0-9a-f]{2})|(\d{1,3})|([\s\S]|$))|[\s\S])/giu;
var match;
var result = '';
while (null != (match = rx.exec(source))) {
const [sequence, escapedFallback, unicode, unicodePoint, hex, octal, char] = match;
var _d = __read(match, 7), sequence = _d[0], escapedFallback = _d[1], unicode = _d[2], unicodePoint = _d[3], hex = _d[4], octal = _d[5], char = _d[6];
try {

@@ -16,3 +33,3 @@ if (char != null) {

else {
const code = unicodePoint || unicode || hex;
var code = unicodePoint || unicode || hex;
if (code) {

@@ -26,3 +43,3 @@ result += getUnescaped(sequence, Number.parseInt(code, 16)) || escapedFallback;

}
catch {
catch (_error) {
result += escapedFallback;

@@ -33,4 +50,4 @@ }

};
const stripSlashes = removeSlashes;
var stripSlashes = removeSlashes;
export { removeSlashes, stripSlashes };
//# sourceMappingURL=remove-slashes.js.map

@@ -9,3 +9,3 @@ {

"license": "ISC",
"version": "3.0.0",
"version": "3.0.1",
"types": "lib/commonjs/index.d.ts",

@@ -22,3 +22,3 @@ "module": "./lib/module/index.js",

"test": "del-cli out && tsc --noEmit && eslint --max-warnings=0 src && jest --no-cache",
"build": "del-cli lib && tsc -p tsconfig.build-commonjs.json && tsc -p tsconfig.build-module.json && tsc -p tsconfig.build-types.json",
"build": "del-cli lib && tsc -p tsconfig.build-commonjs.json && tsc -p tsconfig.build-module.json && tsc -p tsconfig.build-types.json && check-es-compat lib/commonjs",
"clean": "del-cli lib out",

@@ -32,2 +32,3 @@ "modernize": "npm-check-updates -u -x @types/node",

"@types/jest": "^27.4.1",
"check-es-compat": "^2.0.0",
"coveralls": "^3.1.1",

@@ -34,0 +35,0 @@ "del-cli": "^4.0.1",

@@ -37,3 +37,3 @@ import { getUnescapedAny } from './get-unescaped-any';

}
} catch {
} catch (_error) {
result += escapedFallback;

@@ -40,0 +40,0 @@ }

@@ -6,4 +6,4 @@ // Modern code (to be polyfilled) and explicit ambient types.

"module": "ES2020",
"target": "ES2021",
"lib": ["ES2021"],
"target": "ES5",
"lib": ["ES2015"],
"types": ["jest"],

@@ -10,0 +10,0 @@ "strict": true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc