dyna-template-string
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

dynaTemplateString

Works like JS Template String.

The test is string, you don't use the ``` symbol and the variables are passed as a object.

Example

dynaTemplateString({
  text: 'Hello ${name}! How are you ${name} today?',
  variables: {
    name: 'John',
  },
})

Returns:

Hello John! How are you John today?

If the variable is not passed in variables object the ${varName} will remain on the output, indicating that this variable is missing.

For Instance

dynaTemplateString({
  text: 'Hello ${salutation} ${firstName} ${lastName}.',
  variables: {
    salutation: 'Mr',
    lastName: 'Smith',
    // firstName is missing!
  },
})

Returns:

Hello Mr ${firstName} Smith.

API

export const dynaTemplateString = (
  args: {
    text: string;
    variables: {
      [variableName: string]: string;
    };
  },
): string

Package Sidebar

Install

npm i dyna-template-string

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

31 kB

Total Files

56

Last publish

Collaborators

  • dennisat