@coolgk/string
a javascript / typescript module
npm install @coolgk/string
string utility functions
Report bugs here: https://github.com/coolgk/node-utils/issues
Examples
import { stripTags, escapeHtml, unescapeHtml, prepad0 } from '@coolgk/string';
const str = '<h1>test</h1><script>alert(1)</script>'
console.log(stripTags(str));
console.log(escapeHtml(str));
console.log(unescapeHtml(escapeHtml(str)));
console.log(prepad0(7, 2));
console.log(prepad0(70, 3));
console.log(prepad0(70, 4));
console.log(prepad0(1, 4));
console.log(prepad0(1000, 2));
Functions
- stripTags(a) ⇒
string
strip html tags e.g. "<h1>header</h1><p>message</p>" becomes "header message"
- escapeHtml(value) ⇒
string
escaping user input e.g. html code in a message box
- unescapeHtml(string) ⇒
string
unescaping strings escaped by escapeHtml()
- prepad0(value, length) ⇒
string
use padStart instead
stripTags(a) ⇒ string
strip html tags e.g. "<h1>header</h1><p>message</p>" becomes "header message"
Kind: global function
Returns: string
- - string with tags stripped
Param | Type | Description |
---|
a | string | string |
escapeHtml(value) ⇒ string
escaping user input e.g. html code in a message box
Kind: global function
Param | Type | Description |
---|
value | string | string to escape |
unescapeHtml(string) ⇒ string
unescaping strings escaped by escapeHtml()
Kind: global function
Param | Type | Description |
---|
string | string | string to unescape |
prepad0(value, length) ⇒ string
use padStart instead
Kind: global function
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
Param | Type | Default | Description |
---|
value | number | | an integer in string or number format |
length | number | 2 | length of the output e.g. length = 2, 8 becomes 08. length = 3, 70 = 070. |