Socket
Socket
Sign inDemoInstall

@devdesignersid/forger

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @devdesignersid/forger

A lightweight TypeScript library for crafting dynamic strings by seamlessly replacing placeholders in templates with values from data objects. Simplify string generation in your projects with Forger.


Version published
Weekly downloads
17
decreased by-10.53%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Forger

Forger is an elegant TypeScript library designed to effortlessly craft dynamic strings by seamlessly replacing placeholders within a template with values from a data object. It offers a streamlined and versatile solution for generating text with finesse.

Installation

You can integrate Forger into your project with ease using npm or yarn:

npm install @devdesignersid/forger
# or
yarn add @devdesignersid/forger

Usage

Unlock the power of Forger in your TypeScript/JavaScript project with this simple example:

import Forger from '@devdesignersid/forger';

// Create a template string with placeholders
const emailTemplate = 'Hello, {{user.name}}! Your email is {{user.email}}.';

// Instantiate a Forger instance with the template
const emailForger = new Forger(template);

// Define a data object with values to replace the placeholders
const data = {
  user: {
    name: 'John Doe',
    email: 'john@example.com',
  },
};

// Forge the string by replacing placeholders with data values
const result = emailForger.forge(data);

console.log(result);
// Output: "Hello, John Doe! Your email is john@example.com."

Escaping Placeholders

You have the option to escape placeholders by using double backslashes (\\) before the opening and closing braces. For example:

const template = 'This is an escaped placeholder: \\{{escaped\\}}';

Error Handling

Forger is vigilant about placeholders. If a placeholder in the template doesn't have a corresponding value in the data object, it will gracefully raise an error. Ensure your data object contains all the necessary values to maintain a smooth runtime.

API Reference

Forger(template: string)

Creates a new Forger instance with the specified template.

  • template (string): The template string containing placeholders.

forge(data: T): string

Generates a new string by replacing placeholders in the template with values from the data object.

  • data (T): The data object containing values to replace placeholders.
  • Returns: A string with placeholders replaced by data values.

License

This library operates under the MIT License. Delve into the LICENSE file for detailed information.

Issues and Feedback

Should you encounter any issues or have valuable feedback to offer, kindly create an issue on our GitHub repository.

Keywords

FAQs

Last updated on 04 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc