A simple and lightweight Node.js package for formatting strings with parameter interpolation.
npm install string-formatter
const StringFormatter = require('string-formatter');
const formatter = new StringFormatter();
const template = 'Hello, ${name}! You are ${age} years old.';
const params = { name: 'John', age: 30 };
const result = formatter.format(template, params);
console.log(result); // Output: Hello, John! You are 30 years old.
The main class exported by this package.
Formats the given template string by replacing placeholders with corresponding values from the params object.
-
template
: A string containing placeholders in the format${key}
. -
params
: An object containing key-value pairs for interpolation.
Returns the formatted string.
MIT