Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

rodrigo-picanco/dynamic-string

Repository files navigation

Dynamic string

Reuse string interpolation in JavaScript. dynamic-string is a a curried dynamic template string.

You can use it to replace id's in API endpoints, username's in greetings or whatever your imagination leads to :)

Install

yarn add dynamic-string

npm i dynamic-string

Getting started

Import dynamicString from dynamic-string .

import { dynamicString } from 'dynamic-string'

This curried function receives two positional arguments:

  • A string template with '${}' for interpolation
  • An object with the variables to be interpolated as keys.

You can use it directly or not, as in:

const string = dynamicString('https://api.com/${id}', { id: '12101909' }) // https://api.com/12101909

const stringFn = dynamicString('Hey ${name}') // fn ({name}) => `Hey ${name}`

Other examples