@rasch/interject
v0.2.0
Published
a string interpolation module
Maintainers
Readme
interject
interject is a JavaScript module for basic string interpolation.
import { interject } from "@rasch/interject"
const user = {
firstName: "Quinn",
lastName: "Jones",
email: "[email protected]",
}
const template = interject("{firstName} {lastName} <{email}>")
template(user)
// => 'Quinn Jones <[email protected]>'Installation
npm install @rasch/interjectAPI
Include the module.
import { interject } from "@rasch/interject"Use function parameters to pass individual positional substitutions.
interject('{0}, {1}')('Hello', 'world')
// => 'Hello, world'Use an array to pass positional substitutions.
interject('{0}, {1}')(['Hello', 'world'])
// => 'Hello, world'Use an object to pass named substitutions.
interject('{greeting}, {thing}')({ greeting: 'Hello', thing: 'world'})
// => 'Hello, world'