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

variable-injector

v1.0.1

Published

A simple and powerful string replacement utility for TypeScript/Javascript. With this package, you can replace variables in a string with their corresponding values from an object. It supports fully customizable variable identifiers and can handle spaces

Downloads

142

Readme

Welcome to the Variable Injector

The variable-injector package is a powerful tool for replacing variables in strings. It allows you to easily replace variables in a string with their corresponding values, using a flexible and customizable syntax.

Features

  • Flexible variable syntax: The Replacer package supports any variable syntax you want to use, whether it's {{variable}}, #variable#, or %variable%. Simply pass in your desired syntax as the second argument to the injector() function.
  • Supports any data type: The Replacer package can handle any data type as values for the variables, whether it's a string, number, or even an object.
  • Easy to use: The Replacer package is designed to be easy to use, with a simple and intuitive API.

Installation

To install the Replacer package, simply run the following command:

npm install variable-injector

API Documentation

injector(data: string, variables: { [key: string]: any }, variableIdentifiers: string[] = ["#_#", "{{_}}", "%_%"]): string

This function takes in 3 arguments, the string which needs to be modified, the variables which needs to replace in the string and the variable identifier which is used to find the variables in the string.

Arguments

  • data (string): The string which needs to be modified.
  • variables (object): An object containing key-value pairs of variables to be replaced in the string. The keys should match the variables used in the data string.
  • variableIdentifiers (string[]): An array of strings that should be used as variable identifiers in the data string. The default value is ["#_#", "{{_}}", "%_%"].
Returns
  • (string): The modified string with replaced variables.

Examples

import injector from "variable-injector";

const data = "My name is #name# and I am #age# years old";
const variables = { name: "Rayhan", age: 25 };
const modifiedData = injector(data, variables);
console.log(modifiedData);
// Output: "My name is Rayhan and I am 25 years old"
import injector from "variable-injector";

const data = "My name is #name# and I am #age# years old";
const variables = { name: "Rayhan", age: 25 };
const modifiedData = injector(data, variables, ["#_#", "{{_}}"]);
console.log(modifiedData);
// Output: "My name is Rayhan and I am 25 years old"

Testing

To test the package, you can use the jest package. Run the command

npm run test

This package is built using TypeScript and it is well documented and tested.

Contributing

We welcome contributions to the Replacer package. If you have an idea for a new feature or find a bug, please open an issue or submit a pull request on the GitHub repository.

License

The Replacer package is open-source software licensed under the MIT license.

Conclusion

The Replacer package is a powerful and flexible tool for replacing variables in strings. It's easy to use, supports any data type, and allows you to customize the variable syntax to your liking. Give it a try and see how it can help you in your projects!