str-literals

0.1.2 • Public • Published

str-literals

Dynamic string template with simple expressions support.

The idea to use format similar to JS template literals, but be able to get it dynamically.

You can use all global functions and objects unless you don't using "{" and/or "}" inside "${}".

Be carreful when using this module, expression evaluation using eval function.

npm install str-literals

Examples

Simple variable:

const template = require('str-literals')
// const who = 'World'
// console.log( `Hello, ${who}!`)
console.log( template('Hello, ${who}!', {who: 'World'}))

Output:

Hello, World!

No variables:

const template = require('str-literals')
console.log( template('Total: ${1+1}') )

Output:

Total: 2

JS Array expression

const template = require('str-literals')
console.log( template('Note: ${arr.join("")}', {arr: ['Hello, ', 'World', '!']}))

Output:

Note: Hello, World!

Numeric expression

const template = require('str-literals')
console.log( template('Total : ${10 + a - b}', {a: 10, b: 5}))

Output:

Total : 15

License

MIT © Oleg Imanilov

/str-literals/

    Package Sidebar

    Install

    npm i str-literals

    Weekly Downloads

    1

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    4.6 kB

    Total Files

    7

    Last publish

    Collaborators

    • nosyara