npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devdesignersid/forger

v1.0.1

Published

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.

Downloads

14

Readme

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: '[email protected]',
  },
};

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

console.log(result);
// Output: "Hello, John Doe! Your email is [email protected]."

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.