usefulTags
A tiny JavaScript library incorporating some useful template tag functions.
Work in progress.
There is currently support for all versions of Node.js/iojs, using both CommonJS and ESModules. It can be installed with npm i usefultags
.
It also supports any version of Deno and ES6 browsers, include https://deno.land/x/usefultags/index.js
in your script.
ES3 browser support is coming soon.
Being in early development, the functions are subject to change. They currently should be used as either a template tag or regular function, and simply accept the string as an argument. Documentation is an early work-in-progress.
Examples:
stripIndent:
const line = stripIndent`
This
is
${"a"}
multi-line
newline
indented
string.
Random number: ${Math.random()}.`;
console.log(line);
Expected Output:
This
is
a
multi-line
newline
indented
string.
Random number: 0.xxxxxxxxxxxxxxxx.`;
stripAllIndents:
const line = stripAllIndents`This
is
${"a"}
multi-line
newline
indented
string.
Random number: ${Math.random()}.`;
console.log(line);
Expected Output:
This
is
a
multi-line
newline
indented
string.
Random number: 0.xxxxxxxxxxxxxxxx.`;
oneLine:
const line = oneLine`
This
is
${"a"}
multi-line
newline
indented
string.
Random number: ${Math.random()}.`;
console.log(line);
Expected Output:
This is a multi-line newline indented string. Random number: 0.xxxxxxxxxxxxxxxx.
oneLineConcatenate:
const line = oneLineConcatenate`
This
is
${"a"}
multi-line
newline
indented
string.
Random number: ${Math.random()}.`;
console.log(line);
Expected Output:
Thisisamulti-linenewlineindented string.Random number: 0.xxxxxxxxxxxxxxxx.`;