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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@js-utility/template-engine

v0.0.1005

Published

A lightweight and flexible JavaScript template engine for rendering dynamic content, supporting both CommonJS and ES modules.

Readme

Transform Engine

A lightweight, flexible string transformation engine for JavaScript and TypeScript. Transform Engine enables dynamic string interpolation, inline expressions, and powerful formatting with a clean, customizable syntax.

If this package has been helpful to you, your support goes a long way in helping maintain it, improve its features, and build more open-source tools like it. Buy Me a Coffee ☕


✨ Features

  • Inline Expressions: Use {{ ... }} to embed dynamic expressions directly in your strings.
  • Built-in Methods: Perform calculations, string manipulations, and more with a rich set of built-in methods.
  • Chained Formatters: Pipe results through formatters for advanced formatting.
  • Customizable & Extensible: Easily extend with your own methods and formatters (API coming soon).
  • Zero Dependencies: Lightweight and fast, suitable for any project.
  • AI Generated, well formatted & well tested: Unit tested with automation testing and verified by humans. It is type safe, null safe.

📦 Installation

npm install @js-utility/template-engine

🚀 Usage

import { TransformEngine } from '@js-utility/template-engine';

const input = 'Total: {{ sum:10:20 | currency "US":2 }}';

const output = TransformEngine(input, {});

console.log(output); // Total: $30.00

🧠 Syntax

Each placeholder follows this pattern:

{{ method:param1:param2 | formatter:param1:param2 }}
  • method: The function to execute (e.g., sum, row.name)
  • params: (Optional) Arguments to the method (numbers, strings, variables), separated by colons (:)
  • formatter: (Optional) Pipe output through a formatter (e.g., currency, capitalize)
  • formatParams: (Optional) Arguments to the formatter (numbers, strings, variables), separated by colons (:)

Examples:

{{ sum:2:3 }}                       => 5
{{ row.name | capitalize }}         => John doe
{{ row.amount | currency 'US':2 }}  => $1,234.57
{{ sum:10:20 | number 'US':1 }}     => 30.0
{{ 0.25 | percentage 2 }}           => 25.00%

📘 API

| Function | Description | |----------|-------------| | TransformEngine(text: string, context?: object, options?: object): string | Transforms the input string by evaluating all placeholders. |

Parameters

| Name | Type | Description | |----------|---------|--------------------------------------------------| | text | string | The input string containing placeholders. | | context | object | (Optional) Data object for expression resolution. | | options | object | (Optional) Reference Resolution Parameter, that supports context format to key value pair for references. It is default to off. |

Returns:
string — The transformed string with all placeholders evaluated.


🛠️ Built-in Methods

| Method | Description | |-----------|---------------------------| | sum | Adds all arguments | | subtract | Subtracts numbers | | avg | Returns average | | min | Minimum value | | max | Maximum value | | count | Counts number of items | | multiply | Multiplies all numbers | | divide | Divides numbers | | concat | Concatenates strings | | mod | Modulo | | pow | Exponentiation | | abs | Absolute value | | floor | Rounds down | | ceil | Rounds up | | sqrt | Square root | | log | Natural logarithm | | echo | Returns the first argument | | length | Length of string or array | | size | Alias of length |


🎨 Built-in Formatters

| Formatter | Description | |-------------|-----------------------------------------------------------------------------| | upper | Converts to uppercase | | lower | Converts to lowercase | | round | Rounds to nearest integer | | number | Formats number with fraction points (e.g., number 'US':1:2) | | date | Formats as date | | currency | Formats as currency (e.g., currency "US":0:2 for country and decimals) | | percentage | Formats as percent (e.g., percentage 0:2 for decimals) | | json | Converts to JSON string | | capitalize | Capitalizes the first letter | | trim | Trims whitespace | | length | Gets length of string or array | | camel | Converts to camelCase | | snake | Converts to snake_case | | strip | Removes non-alphanumerics | | prefix | Adds a prefix (e.g., prefix:"ID-") | | suffix | Adds a suffix | | repeat | Repeats a string (e.g., repeat:3) | | title | Converts to Title Case |

Note:

  • currency and number use the same parameter structure:
    formatter alpha_2_country_code:min_fraction:max_fraction
    • alpha_2_country_code: e.g., "US"
    • min_fraction (optional): Minimum Number of decimal places. default to '0'
    • max_fraction (optional): Maximum Number of decimal places. default to 'min_fraction'

🧩 Placeholder Regex

const PLACEHOLDER_REGEX = /\{\{\s*([^\s|}]+)(?:\s+([^|}]*?))?(?:\s*\|\s*([^\s|}]+)(?:\s+([^}]*?))?)?\s*\}\}/g;
  • Supports: {{ method args | formatter params }}
  • Flexible whitespace and quoted string arguments ("...", '...')

📚 Examples

TransformEngine('Hello {{ row.name | capitalize }}!', { row: { name: 'sarah' } });
// => Hello Sarah!

TransformEngine('Price: {{ sum 10:15 | currency "US":2 }}');
// => Price: $25.00

TransformEngine('{{ echo "hello world" | upper }}');
// => HELLO WORLD

TransformEngine('Value: {{ sum 1520.856:864.69 | currency "US":1 }}');
// => Value: $2,385.5

TransformEngine('Percent: {{ 0.8320 | percentage 1 }}');
// => Percent: 83.2%

📘 TypeScript Support

This package is built with full TypeScript support. All functions are type-safe, and type definitions are bundled, so you get autocomplete, inline documentation, and compile-time safety out of the box, no need to install @types.


🧪 Testing

This package is thoroughly tested using Jest, with a focus on correctness, edge cases, and null-safety.


🤝 Contributing

This project is maintained privately. While direct contributions (e.g., pull requests or code changes) are not open to the public, feedback, suggestions, and issue reports are always welcome.

If you notice any bugs, edge cases, or have ideas for improvement, feel free to reach out or open an issue (if access is available). Your input helps make the package more robust and useful for everyone!


💖 Support / Donate

If you find this package useful, consider supporting its development. Your support helps maintain the project, improve documentation, and add new features.

Support as through :


💬 Support & Feedback

Have ideas, suggestions, or found a bug? I'd love to hear from you!

  • Feedback: Whether it’s a feature request or an edge case you'd like handled, your input helps improve the package.
  • Issues: If you run into a bug or unexpected behavior, feel free to open an issue (if the repo is accessible).
  • Reach Out: You can also reach out directly for feedback or discussion via email or the contact details in the repository.

Your feedback helps shape better tools for everyone using this package.