Registry / devops / intl-format-cache

intl-format-cache

JSON →
library4.3.1jsnpmunverified

A memoizer factory for Intl format constructors (Intl.NumberFormat, Intl.DateTimeFormat, IntlMessageFormat, IntlRelativeFormat). Current version 4.3.1, part of the FormatJS suite. Creates cache keys via JSON.stringify of arguments, including ordered options keys. Benchmark shows competitive performance vs fast-memoize, especially on get operations. Intended to be used internally by FormatJS packages; direct use may be redundant if using @formatjs/intl. Ships TypeScript declarations. Stable but low churn.

npm install intl-format-cache
INSTALL
IMPORT
SIG · INTL-FORMAT-CACHE
I
intl-format-cache
devopsjavascriptv4.3.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.

default
import memoizeFormatConstructor from 'intl-format-cache'
const { memoizeFormatConstructor } = require('intl-format-cache')
Default export only; named export does not exist.
memoizeFormatConstructor
const memoizeFormatConstructor = require('intl-format-cache')
import { memoizeFormatConstructor } from 'intl-format-cache'
CommonJS require returns the default export directly, not an object.
memoizeFormatConstructor
import memoizeFormatConstructor from 'intl-format-cache'
import * as m from 'intl-format-cache'
Namespace import gives an object with default property: m.default.

Demonstrates memoizing Intl.NumberFormat constructor and reusing cached instances for same locale.

import memoizeFormatConstructor from 'intl-format-cache'; const getNumberFormat = memoizeFormatConstructor(Intl.NumberFormat); const nf1 = getNumberFormat('en'); const nf2 = getNumberFormat('en'); const nf3 = getNumberFormat('fr'); console.log(nf1 === nf2); // true (cached) console.log(nf1 === nf3); // false (different locale) console.log(nf1.format(1000)); // "1,000" console.log(nf3.format(1000)); // "1 000"
Debug
Known issues
deprecatedAs of FormatJS monorepo v3, this package is deprecated in favor of direct use of @formatjs/intl utilities which include caching internally.
fix
Consider using @formatjs/intl which provides built-in memoization.
affects: >=4.0.0
gotchaCache key is created via JSON.stringify(arguments) including options object. Order of keys in options object is normalized but undefined properties or functions will break memoization.
fix
Ensure options objects have stable key order and no undefined values.
affects: *
gotchaThe function passed to memoizeFormatConstructor must be a constructor (newable). Using arrow functions or non-constructable objects will throw.
fix
Only pass Intl.NumberFormat, Intl.DateTimeFormat, etc. or other constructors.
affects: *
gotchaThe memoized function returns the same instance for repeated calls with the same locale/options. Mutating the returned instance will affect subsequent callers.
fix
Do not mutate the returned format instance; treat it as immutable.
affects: *
Errors
Common errors & fixes
Uncaught TypeError: memoizeFormatConstructor is not a function
Using named import or require incorrectly, e.g., import { memoizeFormatConstructor } from 'intl-format-cache'
fix
Use default import: import memoizeFormatConstructor from 'intl-format-cache'
TypeError: Class constructors must be invoked with 'new'
Passing a non-constructable or arrow function as argument to memoizeFormatConstructor
fix
Pass Intl.NumberFormat or similar constructor, not a regular function.
Upgrade
Version history
4.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
intl-format-cache — npm install intl-format-cache · libregistry