Registry / testing / formatter

formatter

JSON →
library0.4.2jsnpmunverified

A lightweight JavaScript library for simple string variable replacement using double-brace syntax like {{ name }}. Supports positional and named arguments, nested property access, partial application for incomplete argument lists, and a length modifier for padding. Current stable version is 0.4.2. The library is intentionally minimal and not a full templating engine; it compiles template strings into reusable functions. Suitable for cases where you need straightforward string interpolation without dependencies.

npm install formatter
INSTALL
IMPORT
SIG · FORMATTER
F
formatter
testingjavascriptv0.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const formatter = require('formatter');
formatter is a CommonJS module without ESM exports; must use require().
default (ESM)
import formatter from 'formatter';
import { formatter } from 'formatter';
No named export exists; default import works in ESM environments if the package is compatible, but the package is CJS-only.
CLI usage
formatter --name="Value" "text" < template.txt
CLI is available when installed globally; reads from stdin and replaces {{ 0 }}, {{ name }}, etc.

Shows basic usage with named and positional variables using the require import style.

const formatter = require('formatter'); const greet = formatter('Hello, {{ name }}! You are {{ 0 }} years old.'); console.log(greet({ name: 'Alice' }, '30')); // Output: Hello, Alice! You are 30 years old.
Debug
Known issues
gotchaPartial execution only works with indexed arguments ({{ 0 }}, {{ 1 }}), not with named variables.
fix
Use only numeric indices if you need partial application.
affects: >=0.3.x
deprecatedVersion 0.4.2 is the latest but the package has not been updated since 2023; consider using a more actively maintained alternative like Handlebars or hogan.
fix
Switch to a maintained templating library.
affects: >=0.4.0
gotchaNested property access uses dot notation (e.g., {{ user.name }}) but creates a new object for repeated path segments, which may lead to unexpected behavior.
fix
Avoid deeply nested paths; verify the resulting string.
affects: >=0.1.0
gotchaThe library does not handle missing variables gracefully: undefined variables become empty strings, which can hide bugs.
fix
Ensure all variables are provided; alternatively, wrap formatter to detect undefined values.
affects: >=0.0.0
gotchaNo HTML escaping or XSS protection; output must be sanitized manually if used in browser contexts.
fix
Use DOMPurify or escape user input before formatting.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'formatter'
Package not installed or not found in node_modules.
fix
Run 'npm install formatter' or 'npm install --save formatter'.
TypeError: formatter is not a function
Attempted to use formatter via import { formatter } from 'formatter'.
fix
Use 'const formatter = require("formatter");' or 'import formatter from "formatter";'.
Uncaught SyntaxError: Unexpected token '.'
Trying to call formatter('template')({ nested: { prop: 'value' } }) but the template uses dot notation incorrectly.
fix
Use proper dot notation in template, e.g., '... {{ nested.prop }} ...' and ensure nested is an object.
Warning: formatter@0.4.2: This package is not maintained
npm audit warning due to package being old.
fix
Consider replacing with a maintained library like handlebars or mustache.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
formatter — npm install formatter · libregistry