Comparing version
import { type EscapeSequence } from './types/escape-sequence'; | ||
declare type AddSlashesOptions = { | ||
readonly getEscaped?: (char: string) => EscapeSequence | boolean | ''; | ||
readonly getEscaped?: (char: string) => EscapeSequence | boolean; | ||
}; | ||
declare const addSlashes: (str: string, { getEscaped }?: AddSlashesOptions) => string; | ||
export { type AddSlashesOptions, addSlashes }; |
@@ -9,6 +9,2 @@ "use strict"; | ||
for (const char of str) { | ||
if (char === '\\') { | ||
result += '\\\\'; | ||
continue; | ||
} | ||
const escaped = getEscaped(char); | ||
@@ -18,4 +14,4 @@ if (!escaped) { | ||
} | ||
else if (escaped === true) { | ||
result += (0, get_escaped_any_1.getEscapedAny)(char); | ||
else if (escaped === true || escaped.length < 2) { | ||
result += (0, get_escaped_any_1.getEscapedAny)(char) || char; | ||
} | ||
@@ -22,0 +18,0 @@ else { |
import { type EscapeSequence } from './types/escape-sequence'; | ||
declare const getEscapedAny: (char: string) => EscapeSequence | ''; | ||
declare const getEscapedAny: (char: string) => EscapeSequence | false; | ||
export { getEscapedAny }; |
@@ -17,2 +17,3 @@ "use strict"; | ||
case `"`: | ||
case '\\': | ||
return `\\${char}`; | ||
@@ -24,5 +25,5 @@ } | ||
} | ||
return unicode; | ||
return unicode || false; | ||
}; | ||
exports.getEscapedAny = getEscapedAny; | ||
//# sourceMappingURL=get-escaped-any.js.map |
@@ -14,2 +14,3 @@ "use strict"; | ||
case `"`: | ||
case '\\': | ||
return true; | ||
@@ -16,0 +17,0 @@ } |
import { type EscapeSequence } from './types/escape-sequence'; | ||
declare type AddSlashesOptions = { | ||
readonly getEscaped?: (char: string) => EscapeSequence | boolean | ''; | ||
readonly getEscaped?: (char: string) => EscapeSequence | boolean; | ||
}; | ||
declare const addSlashes: (str: string, { getEscaped }?: AddSlashesOptions) => string; | ||
export { type AddSlashesOptions, addSlashes }; |
@@ -6,6 +6,2 @@ import { getEscapedAny } from './get-escaped-any'; | ||
for (const char of str) { | ||
if (char === '\\') { | ||
result += '\\\\'; | ||
continue; | ||
} | ||
const escaped = getEscaped(char); | ||
@@ -15,4 +11,4 @@ if (!escaped) { | ||
} | ||
else if (escaped === true) { | ||
result += getEscapedAny(char); | ||
else if (escaped === true || escaped.length < 2) { | ||
result += getEscapedAny(char) || char; | ||
} | ||
@@ -19,0 +15,0 @@ else { |
import { type EscapeSequence } from './types/escape-sequence'; | ||
declare const getEscapedAny: (char: string) => EscapeSequence | ''; | ||
declare const getEscapedAny: (char: string) => EscapeSequence | false; | ||
export { getEscapedAny }; |
@@ -14,2 +14,3 @@ const getEscapedAny = (char) => { | ||
case `"`: | ||
case '\\': | ||
return `\\${char}`; | ||
@@ -21,5 +22,5 @@ } | ||
} | ||
return unicode; | ||
return unicode || false; | ||
}; | ||
export { getEscapedAny }; | ||
//# sourceMappingURL=get-escaped-any.js.map |
@@ -11,2 +11,3 @@ const getEscapedJsonUnsafe = (char) => { | ||
case `"`: | ||
case '\\': | ||
return true; | ||
@@ -13,0 +14,0 @@ } |
@@ -10,3 +10,3 @@ import { type EscapeSequence } from './types/escape-sequence'; | ||
*/ | ||
readonly getEscaped?: (char: string) => EscapeSequence | boolean | ''; | ||
readonly getEscaped?: (char: string) => EscapeSequence | boolean; | ||
}; | ||
@@ -13,0 +13,0 @@ /** |
@@ -6,3 +6,3 @@ import { type EscapeSequence } from './types/escape-sequence'; | ||
*/ | ||
declare const getEscapedAny: (char: string) => EscapeSequence | ''; | ||
declare const getEscapedAny: (char: string) => EscapeSequence | false; | ||
export { getEscapedAny }; |
{ | ||
"name": "slashes", | ||
"description": "Add or remove backslashes (escape or unescape).", | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"license": "ISC", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -62,3 +62,3 @@ # Slashes | ||
A custom `getEscaped` receives one character (may be unicode) at a time. It can return `true` to use the standard escape sequence, `false` to not escape the character, or a string to provide a custom escape sequence (must begin with a backslash). | ||
A custom `getEscaped` receives one character (may be Unicode > 2 bytes) at a time. It can return `true` to use the standard escape sequence, `false` to not escape the character, or a string to provide a custom escape sequence (must begin with a backslash and be at least 2 characters long). | ||
@@ -65,0 +65,0 @@ ```ts |
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
29300
0.16%423
-0.94%