Skip to content

A typescript utility for replacing tokenized items in strings

License

Notifications You must be signed in to change notification settings

thesven/re_place_er

Repository files navigation

RE_PLACE_ER

re_place_er is a simple tool for replacing tokens in a string with their corresponding values. It provides a function that takes a source string and a list of replacements, and returns a new string with the tokens replaced.

Installation

You can install Token Replacer using npm:

npm install @mikesven/re_place_er

Usage

To use Token Replacer, you need to create a ReplacerJob object that contains the source string and a list of replacements. Each replacement is a key-value pair, where the key is the token to be replaced and the value is the replacement value.

import {
  re_place_er,
  ReplacerOptions,
  Replacement,
} from "@mikesven/re_place_er";

const source = "Hello, {{name}}! Your age is {{age}}.";
const replacements: Replacement[] = [
  { name: "John", age: 30 },
  { name: "Jane", age: 25 },
];

const options: ReplacerOptions = {
  openToken: "{{",
  endToken: "}}",
  job: { source, replacements },
};

const result = re_place_er(options);
console.log(result);

This will output:

['Hello, John! Your age is 30.', 'Hello, Jane! Your age is 25.']

About

A typescript utility for replacing tokenized items in strings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published