template-string-replacer
v1.0.2
Published
A simple utility to replace placeholders in a template string
Maintainers
Readme
template-string-replacer
A simple utility to replace placeholders in a template string with dynamic values. 🚀
📌 Features
- Lightweight and dependency-free
- Supports dynamic placeholder replacement using
{{key}}format - Easy to use with TypeScript & JavaScript
- Works in both Node.js and browser environments
📦 Installation
Using npm
npm install template-string-replacerUsing yarn
yarn add template-string-replacer🚀 Usage
Basic Example
const { alterContentBody } = require("template-string-replacer");
const template = "Hello, {{name}}! Welcome to {{platform}}.";
const values = { name: "John", platform: "NPM" };
console.log(alterContentBody(template, values));
// Output: "Hello, John! Welcome to NPM."TypeScript Example
import { alterContentBody } from "template-string-replacer";
const template = "Hi, {{user}}! Your order ID is {{orderId}}.";
const values = { user: "Alice", orderId: "12345" };
console.log(alterContentBody(template, values));
// Output: "Hi, Alice! Your order ID is 12345."🎯 API Reference
alterContentBody(contentBody: string, replacements: { [key: string]: string }): string
| Parameter | Type | Description |
|---------------|------------------|------------------------------------------------|
| contentBody | string | The template string containing {{placeholders}}. |
| replacements | { [key: string]: string } | An object mapping keys to their replacement values. |
Returns
- A new string with all
{{placeholders}}replaced by their corresponding values.
📜 Changelog
v1.0.0
- Initial release with core functionality.
🛠️ Contributing
Contributions are welcome!
- Fork the repo
- Create a feature branch (
git checkout -b feature-xyz) - Commit changes (
git commit -m "Added new feature") - Push to branch (
git push origin feature-xyz) - Open a Pull Request
📝 License
This project is licensed under the MIT License. See LICENSE for details.
