This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+141
View File
@@ -0,0 +1,141 @@
# Slashes
Add or strip backslashes.
If you were previously using v1, see the [migration](https://github.com/ChrisAckerman/slashes/blob/master/MIGRATION.md) document for guidance on switching to v2.
# Getting Started
```ts
import { addSlashes, stripSlashes } from 'slashes';
// Or using CommonJS require.
const { addSlashes, stripSlashes } = require('slashes');
addSlashes(`foo\nbar`) === `foo\\nbar`; // true
stripSlashes(`foo\\nbar`) === `foo\nbar`; // true
```
You can also experiment using a pre-configured REPL by running the `npm start` command.
# API
## Adding Slashes
### **Function** `addSlashes(str: string): string`
Returns a string with the following default characters escaped:
- backspace (`"\b"` -> `"\\b"`)
- form feed (`"\f"` -> `"\\f"`)
- newline (`"\n"` -> `"\\n"`)
- carriage return (`"\r"` -> `"\\r"`)
- horizontal tab (`"\t"` -> `"\\t"`)
- vertical tab (`"\v"` -> `"\\v"`)
- null (`"\0"` -> `"\\0"`)
- single quote (`"'"` -> `"\\'"`)
- double quote (`"\""` -> `"\\\""`)
- backslash (`"\\"` -> `"\\\\"`)
All `addSlashes` overloads use the above as the default character set to escape if no explicit character set is given.
```ts
addSlashes(`\b\f\n\r\t\v\0'"\\`) === `\\b\\f\\n\\r\\t\\v\\0\\'\\"\\\\`; // true
```
### **Function** `addSlashes(str: string, characters: string): string`
An `addSlashes` overload which returns a string with _only_ the characters in the `characters` string escaped. The explicit characters completely override the default character set. The default characters string is: `"\b\f\n\r\t\v\0'\"\\"`.
```ts
addSlashes(`foo\nbar`, `oa`) === `f\\o\\o\nb\\ar`; // true
```
Characters in the unicode supplementary range (code points > 65535) are _always_ converted to a unicode escape surrogate pairs. This is because Javascript strings are UTF-16, which actually sees these as two characters (`"😊".length === 2`). So, using 😊 in the `characters` string is actually setting two escapable characters which are _not valid individually._ If the "😊" character were not escaped to two unicode escape sequences, you would end up with a string containing invalid characters which would print like this: `"\\\\"`, instead of valid characters: `"\\ud83d\\ude0a"`.
```ts
addSlashes(`foo😊bar`, `😊`) === `foo\\ud83d\\ude0abar`; // true
```
### **Function** `addSlashes(str: string, count: number): string`
An `addSlashes` overload which returns a string with `count` layers of slashes added to the default escape character set. This is the same as recursively invoking this function `count` times.
```ts
addSlashes(`"foo\nbar"`, 2) === `\\\\\\"foo\\\\nbar\\\\\\"`; // true
addSlashes(addSlashes(`"foo\nbar"`)) === `\\\\\\"foo\\\\nbar\\\\\\"`; // true
addSlashes(`"foo\nbar"`, 2) === addSlashes(addSlashes(`"foo\nbar"`)); // true
```
### **Function** `addSlashes(str: string, count: number, characters: string): string`
An `addSlashes` overload which accepts both a `count` and `characters` parameter.
### **Function** `addSlashes(str: string, options: IAddSlashesOptions): string`
An `addSlashes` overload which accepts an options object.
- `options` Configurable options for adding slashes to a string. Can have the following fields:
- `count` Number of times to add slashes to the string.
- `characters` A string of characters that should be escaped with slashes.
- `escapeNonAscii` When true, all non-ASCII characters (unicode code points > 127) will be converted to `\x` or `\u` escape sequences.
```ts
addSlashes(`†©`, { count: 2, characters: `†©\\`, escapeNonAscii: true }) === `\\\\u2020\\\\xa9`; // true
```
## Stripping Slashes
### **Function** `stripSlashes(str: string): string`
Returns a string with one layer of slashes removed. It will convert all ES6 escape sequences into their corresponding characters. Slashes which are not part of a recognized escape sequence are removed, and the following character is left in place.
```ts
stripSlashes(`\\b\\f\\n\\r\\t\\v\\0\\xa9\\u2020\\u{1f60a}\\a\\\\`) === `\b\f\n\r\t\v\0©†😊a\\`; // true
```
If a `\u{...}` escape sequence has a code point greater than 0x10ffff, the slash is removed and the `u{...}` suffix is left as a literal string.
```ts
stripSlashes(`\\u{110000}`) === `u{110000}`; // true
```
### **Function** `stripSlashes(str: string, count: number): string`
A `stripSlashes` overload which returns a string with `count` layers of slashes removed. This is the same as recursively invoking this function `count` times.
```ts
stripSlashes(`\\\\n\\\\a\\\\\\\\`, 2) === `\na\\`; // true
stripSlashes(stripSlashes(`\\\\n\\\\a\\\\\\\\`)) === `\na\\`; // true
stripSlashes(`\\\\n\\\\a\\\\\\\\`, 2) === stripSlashes(stripSlashes(`\\\\n\\\\a\\\\\\\\`)); // true
```
### **Function** `stripSlashes(str: string, options: IStripSlashesOptions): string`
A `stripSlashes` overload which accepts an options object.
- `options` Configurable options for stripping slashes from a string. Can have the following fields:
- `count` Number of times to strip slashes from the string.
- `defaultEscapeValue` The default value for all escape options (b, f, n, r, t, v, 0, x, u, and uEs6). When true, escape options must be explicitly disabled. When false, escape options must be explicitly enabled. Defaults to true.
- `b` True to convert `"\\b"` escapes into backspace characters. Defaults to `defaultEscapeValue`.
- `f` True to convert `"\\f"` escapes into form feed characters. Defaults to `defaultEscapeValue`.
- `n` True to convert `"\\n"` escapes into newline (line feed) characters. Defaults to `defaultEscapeValue`.
- `r` True to convert `"\\r"` escapes into carriage return characters. Defaults to `defaultEscapeValue`.
- `t` True to convert `"\\t"` escapes into horizontal tab characters. Defaults to `defaultEscapeValue`.
- `v` True to convert `"\\v"` escapes into vertical tab characters. Defaults to `defaultEscapeValue`.
- `0` True to convert `"\\0"` escapes into null characters. Defaults to `defaultEscapeValue`.
- `x` True to convert `"\\x##"` escapes (where `##` is a hex single byte unicode code point) into unicode characters. Defaults to `defaultEscapeValue`.
- `u` True to convert `"\\u####"` escapes (where `####` is a hex two byte unicode code point) into unicode characters. Defaults to `defaultEscapeValue`.
- `uEs6` True to convert `"\\u{#...}"` escapes (where `#...` is a hex unicode code point) into unicode characters. Defaults to `u`.
If an escape option is false, then the corresponding escape sequence will be treated like any other backslash before a non-escape character. The backslash will be removed, and all trailing characters left untouched.
```ts
stripSlashes(`\\\\tfoo\\\\nbar`, {
// Strip slashes twice.
count: 2,
// All escape sequences are disabled by default.
defaultEscapeValue: false,
// Enable newlines escapes explicitly.
n: true
}) === `tfoo\nbar`; // true
```
+73
View File
@@ -0,0 +1,73 @@
export interface IAddSlashesOptions {
/**
* Number of times to add slashes. Equivalent to invoking the function
* `count` times. Defaults to 1.
*/
count?: number;
/**
* Characters to escape. Defaults to all single character escape sequence
* characters (i.e. `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\0`, `\'`, `\"`,
* and `\\`).
*/
characters?: string;
/**
* Use escape sequences (e.g. `"\xa9"` or `"\u2020"`) for non-ascii
* characters (i.e. unicode code point 0x0080 and greater). Defaults to
* false.
*
* _NOTE: Escaped code points over 2 bytes (Unicode supplementary planes),
* are **always** encoded using two escape sequences as a surrogate pair
* (e.g. `"\\ud83d\\ude0a"`), so that the output doesn't contain invalid
* UTF-16 characters._
*/
escapeNonAscii?: boolean;
}
/**
* Escape all single character escapable sequences (i.e. `\b`, `\f`, `\n`,
* `\r`, `\t`, `\v`, `\0`, `\'`, `\"`, and `\\`).
*
* @param str String in which to escape characters.
* @param options Options for which characters to add slashes to, how many
* slashes to add, and whether to use escape sequences for non-ascii
* characters.
*/
export declare function addSlashes(str: string, options?: IAddSlashesOptions): string;
/**
* Escape all single character escapable sequences (i.e. `\b`, `\f`, `\n`,
* `\r`, `\t`, `\v`, `\0`, `\'`, `\"`, and `\\`).
*
* _NOTE: Escaped code points over 2 bytes (Unicode supplementary planes),
* are **always** encoded using two escape sequences as a surrogate pair
* (e.g. `"\\ud83d\\ude0a"`), so that the output doesn't contain invalid
* UTF-16 characters._
*
* @param str String in which to escape characters.
* @param characters Characters to escape. Defaults to all single character
* escape sequence characters (i.e. `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\0`,
* `\'`, `\"`, and `\\`).
*/
export declare function addSlashes(str: string, characters?: string): string;
/**
* Escape specific characters.
*
* _NOTE: Escaped code points over 2 bytes (Unicode supplementary planes),
* are **always** encoded using two escape sequences as a surrogate pair
* (e.g. `"\\ud83d\\ude0a"`), so that the output doesn't contain invalid
* UTF-16 characters._
*
* @param str String to add slashes to.
* @param count Number of times to add slashes. Equivalent to invoking the
* function `count` times. Defaults to 1.
* @param characters Characters to escape. Defaults to all single character
* escape sequence characters (i.e. `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\0`,
* `\'`, `\"`, and `\\`).
*/
export declare function addSlashes(str: string, count?: number, characters?: string): string;
/**
* @deprecated Use `addSlashes()` instead.
*
* Maintains the legacy behavior of only adding slashes to newlines (`"\n"`),
* carriage returns (`"\r"`), nulls (`"\0"`), single quotes (`"'"`), double
* quotes (`"\""`), and backslashes (`"\\"`).
*/
export declare const add: (str: string, count?: number | undefined) => string;
+79
View File
@@ -0,0 +1,79 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addSlashes = addSlashes;
exports.add = void 0;
var _deprecated = require("./deprecated");
var _escapes = require("./escapes");
function addSlashes(str, countOrCharactersOrOptions, characters = `\b\f\n\r\t\v\0'"\\`) {
let count = 1;
let escapeNonAscii = false;
if (typeof countOrCharactersOrOptions === 'number') {
count = countOrCharactersOrOptions;
} else if (countOrCharactersOrOptions) {
if (typeof countOrCharactersOrOptions === 'object') {
({
count = count,
characters = characters,
escapeNonAscii = escapeNonAscii
} = countOrCharactersOrOptions);
} else {
characters = countOrCharactersOrOptions;
}
}
const rx = new RegExp(`[${characters.replace(/[\]\\^]/g, '\\$&')}]`, 'g');
for (let i = Math.max(1, count >> 0); i > 0; --i) {
str = str.replace(rx, char => {
const escape = _escapes.CHAR_TO_ESCAPE.get(char);
if (escape) {
return escape;
}
const charCode = char.charCodeAt(0);
if (charCode >= 0xd800 && charCode <= 0xf8ff) {
const hex = charCode.toString(16);
return `\\u${hex}`;
} else if (escapeNonAscii && charCode > 0x7f) {
let hex = charCode.toString(16);
if (charCode <= 0xff) {
return `\\x${hex}`;
} else {
while (hex.length < 4) hex = `0${hex}`;
return `\\u${hex}`;
}
}
return `\\${char}`;
});
}
return str;
}
/**
* @deprecated Use `addSlashes()` instead.
*
* Maintains the legacy behavior of only adding slashes to newlines (`"\n"`),
* carriage returns (`"\r"`), nulls (`"\0"`), single quotes (`"'"`), double
* quotes (`"\""`), and backslashes (`"\\"`).
*/
const add = (str, count) => {
(0, _deprecated.deprecated)('The add() function is deprecated and should be replaced with addSlashes().');
return addSlashes(str, count, `\n\0'"\\`);
};
exports.add = add;
//# sourceMappingURL=addSlashes.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export declare function deprecated(message: string): void;
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.deprecated = deprecated;
const guard = new Set();
function deprecated(message) {
if (!guard.has(message)) {
guard.add(message);
console.warn(message);
}
}
//# sourceMappingURL=deprecated.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/deprecated.ts"],"names":["guard","Set","deprecated","message","has","add","console","warn"],"mappings":";;;;;;AAAA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;;AAEO,SAASC,UAAT,CAAoBC,OAApB,EAAqC;AAC1C,MAAI,CAACH,KAAK,CAACI,GAAN,CAAUD,OAAV,CAAL,EAAyB;AACvBH,IAAAA,KAAK,CAACK,GAAN,CAAUF,OAAV;AACAG,IAAAA,OAAO,CAACC,IAAR,CAAaJ,OAAb;AACD;AACF","sourcesContent":["const guard = new Set<string>();\n\nexport function deprecated(message: string) {\n if (!guard.has(message)) {\n guard.add(message);\n console.warn(message);\n }\n}\n"],"file":"deprecated.js"}
+3
View File
@@ -0,0 +1,3 @@
export declare function getSingleCharEscapes(): Map<string, string>;
export declare const SINGLE_CHAR_ESCAPES: ReadonlyMap<string, string>;
export declare const CHAR_TO_ESCAPE: ReadonlyMap<string, string>;
+24
View File
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSingleCharEscapes = getSingleCharEscapes;
exports.CHAR_TO_ESCAPE = exports.SINGLE_CHAR_ESCAPES = void 0;
function getSingleCharEscapes() {
return [['b', '\b'], ['f', '\f'], ['n', '\n'], ['r', '\r'], ['t', '\t'], ['v', '\v'], ['0', '\0']].reduce((map, [key, value]) => {
map.set(key, value);
return map;
}, new Map());
}
const SINGLE_CHAR_ESCAPES = getSingleCharEscapes();
exports.SINGLE_CHAR_ESCAPES = SINGLE_CHAR_ESCAPES;
const CHAR_TO_ESCAPE = [...SINGLE_CHAR_ESCAPES.keys()].reduce((map, code) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
map.set(SINGLE_CHAR_ESCAPES.get(code), `\\${code}`);
return map;
}, new Map());
exports.CHAR_TO_ESCAPE = CHAR_TO_ESCAPE;
//# sourceMappingURL=escapes.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/escapes.ts"],"names":["getSingleCharEscapes","reduce","map","key","value","set","Map","SINGLE_CHAR_ESCAPES","CHAR_TO_ESCAPE","keys","code","get"],"mappings":";;;;;;;;AAAO,SAASA,oBAAT,GAAqD;AAC1D,SAAO,CACL,CAAC,GAAD,EAAM,IAAN,CADK,EAEL,CAAC,GAAD,EAAM,IAAN,CAFK,EAGL,CAAC,GAAD,EAAM,IAAN,CAHK,EAIL,CAAC,GAAD,EAAM,IAAN,CAJK,EAKL,CAAC,GAAD,EAAM,IAAN,CALK,EAML,CAAC,GAAD,EAAM,IAAN,CANK,EAOL,CAAC,GAAD,EAAM,IAAN,CAPK,EAQLC,MARK,CAQE,CAACC,GAAD,EAAM,CAACC,GAAD,EAAMC,KAAN,CAAN,KAAuB;AAC9BF,IAAAA,GAAG,CAACG,GAAJ,CAAQF,GAAR,EAAaC,KAAb;AACA,WAAOF,GAAP;AACD,GAXM,EAWJ,IAAII,GAAJ,EAXI,CAAP;AAYD;;AAEM,MAAMC,mBAAgD,GAAGP,oBAAoB,EAA7E;;AAEA,MAAMQ,cAA2C,GAAG,CAAC,GAAGD,mBAAmB,CAACE,IAApB,EAAJ,EAAgCR,MAAhC,CAAuC,CAACC,GAAD,EAAMQ,IAAN,KAAe;AAC/G;AACAR,EAAAA,GAAG,CAACG,GAAJ,CAAQE,mBAAmB,CAACI,GAApB,CAAwBD,IAAxB,CAAR,EAAyC,KAAIA,IAAK,EAAlD;AACA,SAAOR,GAAP;AACD,CAJ0D,EAIxD,IAAII,GAAJ,EAJwD,CAApD","sourcesContent":["export function getSingleCharEscapes(): Map<string, string> {\n return [\n ['b', '\\b'],\n ['f', '\\f'],\n ['n', '\\n'],\n ['r', '\\r'],\n ['t', '\\t'],\n ['v', '\\v'],\n ['0', '\\0']\n ].reduce((map, [key, value]) => {\n map.set(key, value);\n return map;\n }, new Map());\n}\n\nexport const SINGLE_CHAR_ESCAPES: ReadonlyMap<string, string> = getSingleCharEscapes();\n\nexport const CHAR_TO_ESCAPE: ReadonlyMap<string, string> = [...SINGLE_CHAR_ESCAPES.keys()].reduce((map, code) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n map.set(SINGLE_CHAR_ESCAPES.get(code)!, `\\\\${code}`);\n return map;\n}, new Map<string, string>());\n"],"file":"escapes.js"}
+2
View File
@@ -0,0 +1,2 @@
export * from './addSlashes';
export * from './stripSlashes';
+30
View File
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _addSlashes = require("./addSlashes");
Object.keys(_addSlashes).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _addSlashes[key];
}
});
});
var _stripSlashes = require("./stripSlashes");
Object.keys(_stripSlashes).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _stripSlashes[key];
}
});
});
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './addSlashes';\nexport * from './stripSlashes';\n"],"file":"index.js"}
+1
View File
@@ -0,0 +1 @@
export {};
+31
View File
@@ -0,0 +1,31 @@
"use strict";
var _repl = _interopRequireDefault(require("repl"));
var slashes = _interopRequireWildcard(require("./"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const context = _objectSpread({
slashes
}, slashes);
console.log();
console.log('The library API has been added to the REPL context:');
Object.keys(context).forEach(key => console.log(` ${key}`));
console.log();
const r = _repl.default.start();
Object.assign(r.context, context);
//# sourceMappingURL=repl.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/repl.ts"],"names":["context","slashes","console","log","Object","keys","forEach","key","r","repl","start","assign"],"mappings":";;AACA;;AAEA;;;;;;;;;;;;;;AAEA,MAAMA,OAAO;AAAKC,EAAAA;AAAL,GAAiBA,OAAjB,CAAb;;AAEAC,OAAO,CAACC,GAAR;AACAD,OAAO,CAACC,GAAR,CAAY,qDAAZ;AACAC,MAAM,CAACC,IAAP,CAAYL,OAAZ,EAAqBM,OAArB,CAA6BC,GAAG,IAAIL,OAAO,CAACC,GAAR,CAAa,KAAII,GAAI,EAArB,CAApC;AACAL,OAAO,CAACC,GAAR;;AAEA,MAAMK,CAAC,GAAGC,cAAKC,KAAL,EAAV;;AAEAN,MAAM,CAACO,MAAP,CAAcH,CAAC,CAACR,OAAhB,EAAyBA,OAAzB","sourcesContent":["/* istanbul ignore file */\nimport repl from 'repl';\n\nimport * as slashes from './';\n\nconst context = { slashes, ...slashes };\n\nconsole.log();\nconsole.log('The library API has been added to the REPL context:');\nObject.keys(context).forEach(key => console.log(` ${key}`));\nconsole.log();\n\nconst r = repl.start();\n\nObject.assign(r.context, context);\n"],"file":"repl.js"}
+81
View File
@@ -0,0 +1,81 @@
export interface IStripSlashesOptions {
/**
* Number of times to strip slashes. Equivalent to invoking the function
* `count` times. Defaults to 1.
*/
readonly count?: number;
/**
* The default value for all escape options (b, f, n, r, t, v, 0, x, u, and
* uEs6). When true, escape options must be explicitly disabled. When false,
* escape options must be explicitly enabled. Defaults to true.
*/
readonly defaultEscapeValue?: boolean;
/**
* Unescape `"\\b"` to a backspace character.
*/
readonly b?: boolean;
/**
* Unescape `"\\f"` to a form feed character.
*/
readonly f?: boolean;
/**
* Unescape `"\\n"` to a newline (line feed) character.
*/
readonly n?: boolean;
/**
* Unescape `"\\r"` to a carriage return character.
*/
readonly r?: boolean;
/**
* Unescape `"\\t"` to a tag character.
*/
readonly t?: boolean;
/**
* Unescape `"\\v"` to a vertical tab character.
*/
readonly v?: boolean;
/**
* Unescape `"\\0"` to a null character.
*/
readonly '0'?: boolean;
/**
* Unescape hex escape sequences (e.g. `"\\xa9"`).
*/
readonly x?: boolean;
/**
* Unescape basic unicode escape sequences (e.g. `"\\u2020"`).
*/
readonly u?: boolean;
/**
* Unescape ES6 unicode code point escape sequences (e.g. `"\\u{1F60a}"`).
*/
readonly uEs6?: boolean;
}
/**
* Remove one layer of slashes. All escape sequences will be transformed into
* the character indicated by the sequence (e.g. `"\\n"` will become a
* newline).
*
* @param str String to remove slashes from.
* @param options Options for which escape sequences to recognize. Defaults to
* recognizing all single character, hex, and unicode escape sequences
*/
export declare function stripSlashes(str: string, options?: IStripSlashesOptions): string;
/**
* Remove one layer of slashes. All escape sequences will be transformed into
* the character indicated by the sequence (e.g. `"\\n"` will become a
* newline).
*
* @param str String to remove slashes from.
* @param count Number of times to strip slashes. Equivalent to invoking the
* function `count` times. Defaults to 1.
*/
export declare function stripSlashes(str: string, count?: number): string;
/**
* @deprecated Use `stripSlashes()` instead.
*
* Maintains legacy behavior of _only_ recognizing newline (`"\n"`) and null
* escape sequences (`"\0"`). Other slashes will not consume any trailing
* characters (e.g. `"\\r"` becomes `"r"`, _not a carriage return_).
*/
export declare const strip: (str: string, count?: number | undefined) => string;
+110
View File
@@ -0,0 +1,110 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.stripSlashes = stripSlashes;
exports.strip = void 0;
var _deprecated = require("./deprecated");
var _escapes = require("./escapes");
function stripSlashes(str, countOrOptions) {
let options;
if (typeof countOrOptions === 'number') {
options = {
count: countOrOptions
};
} else if (countOrOptions && typeof countOrOptions === 'object') {
options = countOrOptions;
} else {
options = {};
}
const {
count = 1,
defaultEscapeValue = true,
b = defaultEscapeValue,
f = defaultEscapeValue,
n = defaultEscapeValue,
r = defaultEscapeValue,
t = defaultEscapeValue,
v = defaultEscapeValue,
'0': nul = defaultEscapeValue,
x = defaultEscapeValue,
u = defaultEscapeValue,
uEs6 = u
} = options;
const singleCharEscapes = (0, _escapes.getSingleCharEscapes)();
if (!b) singleCharEscapes.delete('b');
if (!f) singleCharEscapes.delete('f');
if (!n) singleCharEscapes.delete('n');
if (!r) singleCharEscapes.delete('r');
if (!t) singleCharEscapes.delete('t');
if (!v) singleCharEscapes.delete('v');
if (!nul) singleCharEscapes.delete('0');
const patterns = [];
if (x) patterns.push('x[a-fA-F0-9]{2}');
if (u) patterns.push('u[a-fA-F0-9]{4}');
if (uEs6) patterns.push('u{[a-fA-F0-9]+}');
const rx = new RegExp(`\\\\(${[...patterns, '.', '$'].join('|')})`, 'g');
for (let i = Math.max(1, count >> 0); i > 0; --i) {
str = str.replace(rx, (...[, g1]) => {
const suffix = g1;
if (suffix.length > 1) {
if (suffix[0] === 'x') {
return String.fromCharCode(Number.parseInt(suffix.slice(1), 16));
} else if (suffix[0] === 'u') {
if (suffix[1] === '{') {
const codePointStr = suffix.slice(2, -1);
const codePoint = Number.parseInt(codePointStr, 16);
if (codePoint > 0x10ffff) {
// Not valid unicode, so just remove the slash, leaving the
// trailing characters in place.
return suffix;
} else if (codePoint >= 0x10000) {
const u = codePoint - 0x10000;
const s1 = 0xd800 + (u >> 10);
const s2 = 0xdc00 + (u & 0x3ff);
return `${String.fromCharCode(s1, s2)}`;
}
return String.fromCharCode(codePoint);
}
return String.fromCharCode(Number.parseInt(suffix.slice(1), 16));
}
}
return singleCharEscapes.get(suffix) || suffix;
});
}
return str;
}
/**
* @deprecated Use `stripSlashes()` instead.
*
* Maintains legacy behavior of _only_ recognizing newline (`"\n"`) and null
* escape sequences (`"\0"`). Other slashes will not consume any trailing
* characters (e.g. `"\\r"` becomes `"r"`, _not a carriage return_).
*/
const strip = (str, count) => {
(0, _deprecated.deprecated)('The strip() function is deprecated and should be replaced with stripSlashes().');
return stripSlashes(str, {
count,
defaultEscapeValue: false,
n: true,
'0': true
});
};
exports.strip = strip;
//# sourceMappingURL=stripSlashes.js.map
File diff suppressed because one or more lines are too long
+73
View File
@@ -0,0 +1,73 @@
export interface IAddSlashesOptions {
/**
* Number of times to add slashes. Equivalent to invoking the function
* `count` times. Defaults to 1.
*/
count?: number;
/**
* Characters to escape. Defaults to all single character escape sequence
* characters (i.e. `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\0`, `\'`, `\"`,
* and `\\`).
*/
characters?: string;
/**
* Use escape sequences (e.g. `"\xa9"` or `"\u2020"`) for non-ascii
* characters (i.e. unicode code point 0x0080 and greater). Defaults to
* false.
*
* _NOTE: Escaped code points over 2 bytes (Unicode supplementary planes),
* are **always** encoded using two escape sequences as a surrogate pair
* (e.g. `"\\ud83d\\ude0a"`), so that the output doesn't contain invalid
* UTF-16 characters._
*/
escapeNonAscii?: boolean;
}
/**
* Escape all single character escapable sequences (i.e. `\b`, `\f`, `\n`,
* `\r`, `\t`, `\v`, `\0`, `\'`, `\"`, and `\\`).
*
* @param str String in which to escape characters.
* @param options Options for which characters to add slashes to, how many
* slashes to add, and whether to use escape sequences for non-ascii
* characters.
*/
export declare function addSlashes(str: string, options?: IAddSlashesOptions): string;
/**
* Escape all single character escapable sequences (i.e. `\b`, `\f`, `\n`,
* `\r`, `\t`, `\v`, `\0`, `\'`, `\"`, and `\\`).
*
* _NOTE: Escaped code points over 2 bytes (Unicode supplementary planes),
* are **always** encoded using two escape sequences as a surrogate pair
* (e.g. `"\\ud83d\\ude0a"`), so that the output doesn't contain invalid
* UTF-16 characters._
*
* @param str String in which to escape characters.
* @param characters Characters to escape. Defaults to all single character
* escape sequence characters (i.e. `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\0`,
* `\'`, `\"`, and `\\`).
*/
export declare function addSlashes(str: string, characters?: string): string;
/**
* Escape specific characters.
*
* _NOTE: Escaped code points over 2 bytes (Unicode supplementary planes),
* are **always** encoded using two escape sequences as a surrogate pair
* (e.g. `"\\ud83d\\ude0a"`), so that the output doesn't contain invalid
* UTF-16 characters._
*
* @param str String to add slashes to.
* @param count Number of times to add slashes. Equivalent to invoking the
* function `count` times. Defaults to 1.
* @param characters Characters to escape. Defaults to all single character
* escape sequence characters (i.e. `\b`, `\f`, `\n`, `\r`, `\t`, `\v`, `\0`,
* `\'`, `\"`, and `\\`).
*/
export declare function addSlashes(str: string, count?: number, characters?: string): string;
/**
* @deprecated Use `addSlashes()` instead.
*
* Maintains the legacy behavior of only adding slashes to newlines (`"\n"`),
* carriage returns (`"\r"`), nulls (`"\0"`), single quotes (`"'"`), double
* quotes (`"\""`), and backslashes (`"\\"`).
*/
export declare const add: (str: string, count?: number | undefined) => string;
+66
View File
@@ -0,0 +1,66 @@
import { deprecated } from './deprecated';
import { CHAR_TO_ESCAPE } from './escapes';
export function addSlashes(str, countOrCharactersOrOptions, characters = `\b\f\n\r\t\v\0'"\\`) {
let count = 1;
let escapeNonAscii = false;
if (typeof countOrCharactersOrOptions === 'number') {
count = countOrCharactersOrOptions;
} else if (countOrCharactersOrOptions) {
if (typeof countOrCharactersOrOptions === 'object') {
({
count = count,
characters = characters,
escapeNonAscii = escapeNonAscii
} = countOrCharactersOrOptions);
} else {
characters = countOrCharactersOrOptions;
}
}
const rx = new RegExp(`[${characters.replace(/[\]\\^]/g, '\\$&')}]`, 'g');
for (let i = Math.max(1, count >> 0); i > 0; --i) {
str = str.replace(rx, char => {
const escape = CHAR_TO_ESCAPE.get(char);
if (escape) {
return escape;
}
const charCode = char.charCodeAt(0);
if (charCode >= 0xd800 && charCode <= 0xf8ff) {
const hex = charCode.toString(16);
return `\\u${hex}`;
} else if (escapeNonAscii && charCode > 0x7f) {
let hex = charCode.toString(16);
if (charCode <= 0xff) {
return `\\x${hex}`;
} else {
while (hex.length < 4) hex = `0${hex}`;
return `\\u${hex}`;
}
}
return `\\${char}`;
});
}
return str;
}
/**
* @deprecated Use `addSlashes()` instead.
*
* Maintains the legacy behavior of only adding slashes to newlines (`"\n"`),
* carriage returns (`"\r"`), nulls (`"\0"`), single quotes (`"'"`), double
* quotes (`"\""`), and backslashes (`"\\"`).
*/
export const add = (str, count) => {
deprecated('The add() function is deprecated and should be replaced with addSlashes().');
return addSlashes(str, count, `\n\0'"\\`);
};
//# sourceMappingURL=addSlashes.js.map
+1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export declare function deprecated(message: string): void;
+8
View File
@@ -0,0 +1,8 @@
const guard = new Set();
export function deprecated(message) {
if (!guard.has(message)) {
guard.add(message);
console.warn(message);
}
}
//# sourceMappingURL=deprecated.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/deprecated.ts"],"names":["guard","Set","deprecated","message","has","add","console","warn"],"mappings":"AAAA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA,OAAO,SAASC,UAAT,CAAoBC,OAApB,EAAqC;AAC1C,MAAI,CAACH,KAAK,CAACI,GAAN,CAAUD,OAAV,CAAL,EAAyB;AACvBH,IAAAA,KAAK,CAACK,GAAN,CAAUF,OAAV;AACAG,IAAAA,OAAO,CAACC,IAAR,CAAaJ,OAAb;AACD;AACF","sourcesContent":["const guard = new Set<string>();\n\nexport function deprecated(message: string) {\n if (!guard.has(message)) {\n guard.add(message);\n console.warn(message);\n }\n}\n"],"file":"deprecated.js"}
+3
View File
@@ -0,0 +1,3 @@
export declare function getSingleCharEscapes(): Map<string, string>;
export declare const SINGLE_CHAR_ESCAPES: ReadonlyMap<string, string>;
export declare const CHAR_TO_ESCAPE: ReadonlyMap<string, string>;
+13
View File
@@ -0,0 +1,13 @@
export function getSingleCharEscapes() {
return [['b', '\b'], ['f', '\f'], ['n', '\n'], ['r', '\r'], ['t', '\t'], ['v', '\v'], ['0', '\0']].reduce((map, [key, value]) => {
map.set(key, value);
return map;
}, new Map());
}
export const SINGLE_CHAR_ESCAPES = getSingleCharEscapes();
export const CHAR_TO_ESCAPE = [...SINGLE_CHAR_ESCAPES.keys()].reduce((map, code) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
map.set(SINGLE_CHAR_ESCAPES.get(code), `\\${code}`);
return map;
}, new Map());
//# sourceMappingURL=escapes.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/escapes.ts"],"names":["getSingleCharEscapes","reduce","map","key","value","set","Map","SINGLE_CHAR_ESCAPES","CHAR_TO_ESCAPE","keys","code","get"],"mappings":"AAAA,OAAO,SAASA,oBAAT,GAAqD;AAC1D,SAAO,CACL,CAAC,GAAD,EAAM,IAAN,CADK,EAEL,CAAC,GAAD,EAAM,IAAN,CAFK,EAGL,CAAC,GAAD,EAAM,IAAN,CAHK,EAIL,CAAC,GAAD,EAAM,IAAN,CAJK,EAKL,CAAC,GAAD,EAAM,IAAN,CALK,EAML,CAAC,GAAD,EAAM,IAAN,CANK,EAOL,CAAC,GAAD,EAAM,IAAN,CAPK,EAQLC,MARK,CAQE,CAACC,GAAD,EAAM,CAACC,GAAD,EAAMC,KAAN,CAAN,KAAuB;AAC9BF,IAAAA,GAAG,CAACG,GAAJ,CAAQF,GAAR,EAAaC,KAAb;AACA,WAAOF,GAAP;AACD,GAXM,EAWJ,IAAII,GAAJ,EAXI,CAAP;AAYD;AAED,OAAO,MAAMC,mBAAgD,GAAGP,oBAAoB,EAA7E;AAEP,OAAO,MAAMQ,cAA2C,GAAG,CAAC,GAAGD,mBAAmB,CAACE,IAApB,EAAJ,EAAgCR,MAAhC,CAAuC,CAACC,GAAD,EAAMQ,IAAN,KAAe;AAC/G;AACAR,EAAAA,GAAG,CAACG,GAAJ,CAAQE,mBAAmB,CAACI,GAApB,CAAwBD,IAAxB,CAAR,EAAyC,KAAIA,IAAK,EAAlD;AACA,SAAOR,GAAP;AACD,CAJ0D,EAIxD,IAAII,GAAJ,EAJwD,CAApD","sourcesContent":["export function getSingleCharEscapes(): Map<string, string> {\n return [\n ['b', '\\b'],\n ['f', '\\f'],\n ['n', '\\n'],\n ['r', '\\r'],\n ['t', '\\t'],\n ['v', '\\v'],\n ['0', '\\0']\n ].reduce((map, [key, value]) => {\n map.set(key, value);\n return map;\n }, new Map());\n}\n\nexport const SINGLE_CHAR_ESCAPES: ReadonlyMap<string, string> = getSingleCharEscapes();\n\nexport const CHAR_TO_ESCAPE: ReadonlyMap<string, string> = [...SINGLE_CHAR_ESCAPES.keys()].reduce((map, code) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n map.set(SINGLE_CHAR_ESCAPES.get(code)!, `\\\\${code}`);\n return map;\n}, new Map<string, string>());\n"],"file":"escapes.js"}
+2
View File
@@ -0,0 +1,2 @@
export * from './addSlashes';
export * from './stripSlashes';
+3
View File
@@ -0,0 +1,3 @@
export * from './addSlashes';
export * from './stripSlashes';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,gBAAd","sourcesContent":["export * from './addSlashes';\nexport * from './stripSlashes';\n"],"file":"index.js"}
+1
View File
@@ -0,0 +1 @@
export {};
+21
View File
@@ -0,0 +1,21 @@
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/* istanbul ignore file */
import repl from 'repl';
import * as slashes from './';
const context = _objectSpread({
slashes
}, slashes);
console.log();
console.log('The library API has been added to the REPL context:');
Object.keys(context).forEach(key => console.log(` ${key}`));
console.log();
const r = repl.start();
Object.assign(r.context, context);
//# sourceMappingURL=repl.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/repl.ts"],"names":["repl","slashes","context","console","log","Object","keys","forEach","key","r","start","assign"],"mappings":";;;;;;AAAA;AACA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,OAAO,KAAKC,OAAZ,MAAyB,IAAzB;;AAEA,MAAMC,OAAO;AAAKD,EAAAA;AAAL,GAAiBA,OAAjB,CAAb;;AAEAE,OAAO,CAACC,GAAR;AACAD,OAAO,CAACC,GAAR,CAAY,qDAAZ;AACAC,MAAM,CAACC,IAAP,CAAYJ,OAAZ,EAAqBK,OAArB,CAA6BC,GAAG,IAAIL,OAAO,CAACC,GAAR,CAAa,KAAII,GAAI,EAArB,CAApC;AACAL,OAAO,CAACC,GAAR;AAEA,MAAMK,CAAC,GAAGT,IAAI,CAACU,KAAL,EAAV;AAEAL,MAAM,CAACM,MAAP,CAAcF,CAAC,CAACP,OAAhB,EAAyBA,OAAzB","sourcesContent":["/* istanbul ignore file */\nimport repl from 'repl';\n\nimport * as slashes from './';\n\nconst context = { slashes, ...slashes };\n\nconsole.log();\nconsole.log('The library API has been added to the REPL context:');\nObject.keys(context).forEach(key => console.log(` ${key}`));\nconsole.log();\n\nconst r = repl.start();\n\nObject.assign(r.context, context);\n"],"file":"repl.js"}
+81
View File
@@ -0,0 +1,81 @@
export interface IStripSlashesOptions {
/**
* Number of times to strip slashes. Equivalent to invoking the function
* `count` times. Defaults to 1.
*/
readonly count?: number;
/**
* The default value for all escape options (b, f, n, r, t, v, 0, x, u, and
* uEs6). When true, escape options must be explicitly disabled. When false,
* escape options must be explicitly enabled. Defaults to true.
*/
readonly defaultEscapeValue?: boolean;
/**
* Unescape `"\\b"` to a backspace character.
*/
readonly b?: boolean;
/**
* Unescape `"\\f"` to a form feed character.
*/
readonly f?: boolean;
/**
* Unescape `"\\n"` to a newline (line feed) character.
*/
readonly n?: boolean;
/**
* Unescape `"\\r"` to a carriage return character.
*/
readonly r?: boolean;
/**
* Unescape `"\\t"` to a tag character.
*/
readonly t?: boolean;
/**
* Unescape `"\\v"` to a vertical tab character.
*/
readonly v?: boolean;
/**
* Unescape `"\\0"` to a null character.
*/
readonly '0'?: boolean;
/**
* Unescape hex escape sequences (e.g. `"\\xa9"`).
*/
readonly x?: boolean;
/**
* Unescape basic unicode escape sequences (e.g. `"\\u2020"`).
*/
readonly u?: boolean;
/**
* Unescape ES6 unicode code point escape sequences (e.g. `"\\u{1F60a}"`).
*/
readonly uEs6?: boolean;
}
/**
* Remove one layer of slashes. All escape sequences will be transformed into
* the character indicated by the sequence (e.g. `"\\n"` will become a
* newline).
*
* @param str String to remove slashes from.
* @param options Options for which escape sequences to recognize. Defaults to
* recognizing all single character, hex, and unicode escape sequences
*/
export declare function stripSlashes(str: string, options?: IStripSlashesOptions): string;
/**
* Remove one layer of slashes. All escape sequences will be transformed into
* the character indicated by the sequence (e.g. `"\\n"` will become a
* newline).
*
* @param str String to remove slashes from.
* @param count Number of times to strip slashes. Equivalent to invoking the
* function `count` times. Defaults to 1.
*/
export declare function stripSlashes(str: string, count?: number): string;
/**
* @deprecated Use `stripSlashes()` instead.
*
* Maintains legacy behavior of _only_ recognizing newline (`"\n"`) and null
* escape sequences (`"\0"`). Other slashes will not consume any trailing
* characters (e.g. `"\\r"` becomes `"r"`, _not a carriage return_).
*/
export declare const strip: (str: string, count?: number | undefined) => string;
+97
View File
@@ -0,0 +1,97 @@
import { deprecated } from './deprecated';
import { getSingleCharEscapes } from './escapes';
export function stripSlashes(str, countOrOptions) {
let options;
if (typeof countOrOptions === 'number') {
options = {
count: countOrOptions
};
} else if (countOrOptions && typeof countOrOptions === 'object') {
options = countOrOptions;
} else {
options = {};
}
const {
count = 1,
defaultEscapeValue = true,
b = defaultEscapeValue,
f = defaultEscapeValue,
n = defaultEscapeValue,
r = defaultEscapeValue,
t = defaultEscapeValue,
v = defaultEscapeValue,
'0': nul = defaultEscapeValue,
x = defaultEscapeValue,
u = defaultEscapeValue,
uEs6 = u
} = options;
const singleCharEscapes = getSingleCharEscapes();
if (!b) singleCharEscapes.delete('b');
if (!f) singleCharEscapes.delete('f');
if (!n) singleCharEscapes.delete('n');
if (!r) singleCharEscapes.delete('r');
if (!t) singleCharEscapes.delete('t');
if (!v) singleCharEscapes.delete('v');
if (!nul) singleCharEscapes.delete('0');
const patterns = [];
if (x) patterns.push('x[a-fA-F0-9]{2}');
if (u) patterns.push('u[a-fA-F0-9]{4}');
if (uEs6) patterns.push('u{[a-fA-F0-9]+}');
const rx = new RegExp(`\\\\(${[...patterns, '.', '$'].join('|')})`, 'g');
for (let i = Math.max(1, count >> 0); i > 0; --i) {
str = str.replace(rx, (...[, g1]) => {
const suffix = g1;
if (suffix.length > 1) {
if (suffix[0] === 'x') {
return String.fromCharCode(Number.parseInt(suffix.slice(1), 16));
} else if (suffix[0] === 'u') {
if (suffix[1] === '{') {
const codePointStr = suffix.slice(2, -1);
const codePoint = Number.parseInt(codePointStr, 16);
if (codePoint > 0x10ffff) {
// Not valid unicode, so just remove the slash, leaving the
// trailing characters in place.
return suffix;
} else if (codePoint >= 0x10000) {
const u = codePoint - 0x10000;
const s1 = 0xd800 + (u >> 10);
const s2 = 0xdc00 + (u & 0x3ff);
return `${String.fromCharCode(s1, s2)}`;
}
return String.fromCharCode(codePoint);
}
return String.fromCharCode(Number.parseInt(suffix.slice(1), 16));
}
}
return singleCharEscapes.get(suffix) || suffix;
});
}
return str;
}
/**
* @deprecated Use `stripSlashes()` instead.
*
* Maintains legacy behavior of _only_ recognizing newline (`"\n"`) and null
* escape sequences (`"\0"`). Other slashes will not consume any trailing
* characters (e.g. `"\\r"` becomes `"r"`, _not a carriage return_).
*/
export const strip = (str, count) => {
deprecated('The strip() function is deprecated and should be replaced with stripSlashes().');
return stripSlashes(str, {
count,
defaultEscapeValue: false,
n: true,
'0': true
});
};
//# sourceMappingURL=stripSlashes.js.map
+1
View File
File diff suppressed because one or more lines are too long
+92
View File
@@ -0,0 +1,92 @@
{
"name": "slashes",
"description": "Add or strip backslashes.",
"version": "2.0.2",
"license": "ISC",
"author": {
"name": "Chris Ackerman",
"email": "chris@topher.land"
},
"repository": {
"type": "git",
"url": "git://github.com:ChrisAckerman/slashes"
},
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"files": [
"README.md",
"css/",
"dist/",
"lib-commonjs/",
"lib/",
"scss/"
],
"scripts": {
"start": "run-script build:commonjs && node ./lib-commonjs/repl.js",
"test": "run-script eslint && run-script tsc --noEmit && run-script jest",
"clean": "del-cli lib lib-commonjs dist css coverage && jest --clearCache",
"build": "run-script clean && run-script build:js && run-script build:commonjs && run-script build:d.ts && run-script build:cleanup",
"build:cleanup": "del-cli \"lib?(-*)/**/@(__demo__|__snapshots__|?(*.)test.@(ts|tsx|js|jsx))\"",
"build:commonjs": "cross-env NODE_ENV=production BABEL_MODULES=cjs babel src --out-dir lib-commonjs --extensions .ts,.tsx,.js,.jsx --copy-files --source-maps",
"build:d.ts": "run-script tsc --emitDeclarationOnly && run-script tsc --emitDeclarationOnly --outDir lib-commonjs",
"build:js": "cross-env NODE_ENV=production BABEL_MODULES=false babel src --out-dir lib --extensions .ts,.tsx,.js,.jsx --copy-files --source-maps",
"eslint": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --ignore-pattern \"/__demo__/\" --no-error-on-unmatched-pattern",
"jest": "cross-env NODE_ENV=test jest --passWithNoTests",
"prepack": "run-script build",
"prepublishOnly": "run-script test",
"reformat": "run-script eslint --fix --quiet",
"tsc": "tsc"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/generator": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-transform-typescript": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@types/jest": "^25.1.3",
"@types/node": "^13.7.4",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"@xornot/run-script": "^0.1.2",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^25.1.0",
"babel-plugin-const-enum": "^0.0.5",
"cross-env": "^7.0.0",
"del-cli": "^3.0.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"typescript": "^3.8.2"
},
"keywords": [
"escape",
"unescape",
"slashes",
"php",
"strip",
"sequence",
"encode",
"decode",
"backslash",
"slash",
"unicode",
"ascii",
"utf8",
"utf16",
"control",
"char",
"character",
"unprintable",
"printable",
"codepoint",
"codeblock",
"supplemental",
"supplementary"
]
}