Registry / devops / custom-string-formatter

custom-string-formatter

JSON →
library1.2.1jsnpmunverified

Customizable String Formatter is a lightweight library for replacing variables in strings with custom value formatting. Version 1.2.1 supports Node.js 18+ and all modern browsers. It features a flexible variable syntax including nested properties, filter pipelines, and filter arguments. The library is ESM-only, ships TypeScript definitions, and emphasizes performance with fast value resolution. Key differentiators include support for multiple variable syntaxes (${}, $(), $<>), chained filters with arguments, and custom formatter/filter interfaces.

npm install custom-string-formatter
INSTALL
IMPORT
SIG · CUSTOM-STRING-FORM
C
custom-string-formatter
devopsjavascriptv1.2.1
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.

createFormatter
import { createFormatter } from 'custom-string-formatter'
const { createFormatter } = require('custom-string-formatter')
Package is ESM-only; CommonJS require is not supported
IFormatter
import type { IFormatter } from 'custom-string-formatter'
import { IFormatter } from 'custom-string-formatter'
IFormatter is a TypeScript interface; use type-only import to avoid runtime overhead
IFilter
import type { IFilter } from 'custom-string-formatter'
import { IFilter } from 'custom-string-formatter'
IFilter is a TypeScript interface; use type-only import

Create a custom formatter and use it to replace variables in a string with values from an object.

import { createFormatter } from 'custom-string-formatter'; const format = createFormatter({ format: (value) => (value ?? 'null').toString() }); const result = format('Hello ${title} ${name}!', { title: 'Mr.', name: 'Foreman' }); console.log(result); // Hello Mr. Foreman!
Debug
Known issues
breakingESM-only package: CommonJS require() will fail with ERR_REQUIRE_ESM
fix
Use dynamic import() or switch to ESM (type: 'module' in package.json)
affects: >=1.0.0
gotchaVariable syntax with mixed opener-closer pairs is invalid: ${propertyName) will not be recognized
fix
Ensure matching pairs: ${...}, $(...), or $<...>
affects: >=1.0.0
deprecatedFilter arguments syntax with colon-separated values may be deprecated in future versions
fix
Use JSON object as argument if complex filtering is needed
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Package is ESM-only but CommonJS require is used
fix
Use dynamic import: import('custom-string-formatter') or enable ESM in your project
TypeError: createFormatter is not a function
Incorrect import: importing default instead of named
fix
Use named import: import { createFormatter } from 'custom-string-formatter'
Cannot find module 'custom-string-formatter'
Package not installed or incorrect path
fix
Run: npm install custom-string-formatter
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
dayjsoptionalOptional peer dependency for date formatting examples in documentation
Agent activity
6 hits · last 30 days
node
6
Resources
custom-string-formatter — npm install custom-string-formatter · libregistry