Comparing version
@@ -27,1 +27,17 @@ /** | ||
export declare function escString(unsafe: string): string; | ||
/** | ||
* Unified form of {@link escString} and {@link escObject}. | ||
* | ||
* @param value | ||
* @returns | ||
*/ | ||
export declare function esc<T extends string | object>(value: T): T; | ||
/** | ||
* The reverse process to escString. This can be important to | ||
* get back a value that was previously escaped to allow transport | ||
* within markup, for example as data attributes. | ||
* | ||
* @param unsafe | ||
* @returns | ||
*/ | ||
export declare function unEsc(unsafe: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.escString = exports.escObject = void 0; | ||
exports.unEsc = exports.esc = exports.escString = exports.escObject = void 0; | ||
/** | ||
@@ -24,2 +24,18 @@ * Returns an object which escapes properties sourced from it. Escaping markup is a key component of template rendering, | ||
exports.escObject = escObject; | ||
class EscTrap { | ||
constructor() { | ||
this.children = {}; | ||
} | ||
get(target, p) { | ||
if (this.children.hasOwnProperty(p)) | ||
return this.children[p]; | ||
const result = target[p]; | ||
if (typeof result === 'string') | ||
return this.children[p] = escString(result); | ||
else if (typeof result === 'object') | ||
return this.children[p] = escObject(result); | ||
else | ||
return this.children[p] = result; | ||
} | ||
} | ||
/** | ||
@@ -42,17 +58,31 @@ * Escapes special HTML characters in the input (unsafe) string. | ||
exports.escString = escString; | ||
class EscTrap { | ||
constructor() { | ||
this.children = {}; | ||
} | ||
get(target, p) { | ||
if (this.children.hasOwnProperty(p)) | ||
return this.children[p]; | ||
const result = target[p]; | ||
if (typeof result === 'string') | ||
return this.children[p] = escString(result); | ||
else if (typeof result === 'object') | ||
return this.children[p] = escObject(result); | ||
else | ||
return this.children[p] = result; | ||
} | ||
/** | ||
* Unified form of {@link escString} and {@link escObject}. | ||
* | ||
* @param value | ||
* @returns | ||
*/ | ||
function esc(value) { | ||
if (typeof value === 'string') | ||
return escString(value); | ||
else | ||
return escObject(value); | ||
} | ||
exports.esc = esc; | ||
/** | ||
* The reverse process to escString. This can be important to | ||
* get back a value that was previously escaped to allow transport | ||
* within markup, for example as data attributes. | ||
* | ||
* @param unsafe | ||
* @returns | ||
*/ | ||
function unEsc(unsafe) { | ||
return unsafe | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/"/g, '"') | ||
.replace(/'/g, "'"); | ||
} | ||
exports.unEsc = unEsc; |
@@ -27,2 +27,18 @@ /** | ||
export declare function escString(unsafe: string): string; | ||
/** | ||
* Unified form of {@link escString} and {@link escObject}. | ||
* | ||
* @param value | ||
* @returns | ||
*/ | ||
export declare function esc<T extends string | object>(value: T): T; | ||
/** | ||
* The reverse process to escString. This can be important to | ||
* get back a value that was previously escaped to allow transport | ||
* within markup, for example as data attributes. | ||
* | ||
* @param unsafe | ||
* @returns | ||
*/ | ||
export declare function unEsc(unsafe: string): string; | ||
//# sourceMappingURL=esc.d.ts.map |
@@ -20,2 +20,18 @@ /** | ||
} | ||
class EscTrap { | ||
constructor() { | ||
this.children = {}; | ||
} | ||
get(target, p) { | ||
if (this.children.hasOwnProperty(p)) | ||
return this.children[p]; | ||
const result = target[p]; | ||
if (typeof result === 'string') | ||
return this.children[p] = escString(result); | ||
else if (typeof result === 'object') | ||
return this.children[p] = escObject(result); | ||
else | ||
return this.children[p] = result; | ||
} | ||
} | ||
/** | ||
@@ -37,17 +53,29 @@ * Escapes special HTML characters in the input (unsafe) string. | ||
} | ||
class EscTrap { | ||
constructor() { | ||
this.children = {}; | ||
} | ||
get(target, p) { | ||
if (this.children.hasOwnProperty(p)) | ||
return this.children[p]; | ||
const result = target[p]; | ||
if (typeof result === 'string') | ||
return this.children[p] = escString(result); | ||
else if (typeof result === 'object') | ||
return this.children[p] = escObject(result); | ||
else | ||
return this.children[p] = result; | ||
} | ||
/** | ||
* Unified form of {@link escString} and {@link escObject}. | ||
* | ||
* @param value | ||
* @returns | ||
*/ | ||
export function esc(value) { | ||
if (typeof value === 'string') | ||
return escString(value); | ||
else | ||
return escObject(value); | ||
} | ||
/** | ||
* The reverse process to escString. This can be important to | ||
* get back a value that was previously escaped to allow transport | ||
* within markup, for example as data attributes. | ||
* | ||
* @param unsafe | ||
* @returns | ||
*/ | ||
export function unEsc(unsafe) { | ||
return unsafe | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/"/g, '"') | ||
.replace(/'/g, "'"); | ||
} |
{ | ||
"name": "deleight", | ||
"version": "5.7.0", | ||
"version": "5.7.1", | ||
"description": "A library with 9 modules for writing more expressive web applications with traditional HTML, CSS and JavaScript.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
# Deleight (v5.7.0) | ||
# Deleight (v5.7.1) | ||
@@ -3,0 +3,0 @@  |
Sorry, the diff of this file is not supported yet
586870
0.42%16575
0.55%