UNPKG

deleight

Version:

A library with 9 modules for writing more expressive web applications with traditional HTML, CSS and JavaScript.

43 lines (42 loc) 1.43 kB
/** * Returns an object which escapes properties sourced from it. Escaping markup is a key component of template rendering, * so this is an important function to have here. * * NB: there are no tests yet. Please report any bugs. * * @example * import { esc } from 'deleight/apriori' * const obj = { a: 1, b: 'no special chars', c: '<p>But I am a paragraph</p>', d: { e: '<p>"esc" will still work here</p>' } } * const escObj = esc(obj); * console.log(escObj.c); // &lt;p&gt;But I am a paragraph&lt;/p&gt; * console.log(escObj.d.e); // &lt;p&gt;&quot;esc&quot; will still work here&lt;/p&gt; * * * @param {*} object */ export declare function escObject<T extends object>(object: T): T; /** * Escapes special HTML characters in the input (unsafe) string. * * Credits 'bjornd' (https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript) * * @param {*} unsafe * @returns */ 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;