usefulTags

A tiny JavaScript library incorporating some useful template tag functions.


GitHub code size in bytes License: MIT Release CodeFactor Grade code style: prettier

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.mjs in your script.

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.

Examples:

stripIndent:

const line = stripIndent`
        This
        is
        ${"a"}
        multi-line
        newline
         
            indented  
        string.
        Random number: ${Math.random()}.`;
console.log(line);

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);

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);

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);

Output:

Thisisamulti-linenewlineindented  string.Random number: 0.xxxxxxxxxxxxxxxx.`;