string-utils
A collection of utilities for JavaScript strings.
Installation
Via npm:
npm install @ultraq/string-utils
API
escapeHtml(string)
Escapes special HTML characters in a string with their entity code equivalents. Returns a string safe to use as text within an HTML document.
- string: string to escape.
format(template, ...values)
Returns the replacement of each placeholder in a template string with a corresponding replacement value.
- template: template string containing placeholders in the format or
{n}
wheren
is the corresponding index value to have filled-in. - ...values: argument list of values to fill in the placeholders in the template string with.