0.2.0 • Published 1 year ago

@rasch/interject v0.2.0

Weekly downloads
-
License
0BSD
Repository
-
Last release
1 year ago

interject

interject is a JavaScript module for basic string interpolation.

import { interject } from "@rasch/interject"

const user = {
  firstName: "Quinn",
  lastName: "Jones",
  email: "qjones@example.com",
}

const template = interject("{firstName} {lastName} <{email}>")

template(user)
// => 'Quinn Jones <qjones@example.com>'

Installation

npm install @rasch/interject

API

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'
0.2.0

1 year ago

0.1.0

1 year ago