Registry / productivity / string-object-formatter

string-object-formatter

JSON →
library4.0.1jsnpmunverified

A Python-inspired named template formatter for JavaScript strings. Current stable version is 4.0.1, with infrequent releases. It allows replacing placeholders in strings using object properties, supporting default `{}` delimiters or custom delimiters. The class-based API supports optional silent mode to suppress errors for missing keys. Ships TypeScript types. Differentiator: simple, lightweight, no dependencies, and supports custom delimiters, unlike similar libraries that may only support default syntax.

npm install string-object-formatter
INSTALL
IMPORT
SIG · STRING-OBJECT-FORM
S
string-object-formatter
productivityjavascriptv4.0.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.

Formatter
import Formatter from 'string-object-formatter'
import { Formatter } from 'string-object-formatter'
Default export only; named import will fail. Use default import.
Formatter (class)
const Formatter = require('string-object-formatter')
const { Formatter } = require('string-object-formatter')
CommonJS usage: the entire module is the constructor, not a named export.
Formatter (with custom delimiters)
const formatter = new Formatter('{{', '}}')
const formatter = new Formatter({ start: '{{', end: '}}' })
Constructor takes two string arguments (startDelimiter, endDelimiter), not an options object.

Demonstrates basic usage: instantiate Formatter and call format() with a template string and object.

import Formatter from 'string-object-formatter'; const formatter = new Formatter(); const template = "Hello {name}, you are {age} years old."; const result = formatter.format(template, { name: 'Alice', age: 30 }); console.log(result); // Hello Alice, you are 30 years old.
Debug
Known issues
gotchaDefault export only. Importing as named export will result in undefined or runtime error.
fix
Use default import: import Formatter from 'string-object-formatter'
affects: *
gotchaCustom delimiters are passed as two separate string arguments, not an object.
fix
Use new Formatter('{{', '}}') instead of passing an object.
affects: *
gotchaIn silent mode (third constructor argument), missing keys are silently ignored. This can hide bugs if not intended.
fix
Explicitly set silent: true only if you want to ignore missing keys; otherwise omit or set false.
affects: *
Errors
Common errors & fixes
TypeError: Formatter is not a constructor
Importing as named export instead of default.
fix
Use 'import Formatter from "string-object-formatter"'
Formatter is not defined
In CommonJS, using destructuring require for non-existent export.
fix
Use 'const Formatter = require("string-object-formatter")'
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources