Registry / productivity / messageformat-number-skeleton

messageformat-number-skeleton

JSON →
library0.2.1jsnpmunverified

Parser and formatter for ICU NumberFormat skeleton strings and patterns. Version 0.2.1. Part of the Messageformat project under OpenJS Foundation. Parses ICU skeleton strings like 'compact-short currency/GBP' and number patterns, converting them into structured Skeleton objects, and provides formatters via getNumberFormatter() using Intl.NumberFormat internally. Differentiates from raw Intl.NumberFormat by accepting human-readable skeleton syntax and enabling pre-compilation for Messageformat and similar template engines. Low release cadence but stable API.

npm install messageformat-number-skeleton
INSTALL
IMPORT
SIG · MESSAGEFORMAT-NUMB
M
messageformat-number-skeleton
productivityjavascriptv0.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.

getNumberFormatter
import { getNumberFormatter } from 'messageformat-number-skeleton'
const { getNumberFormatter } = require('messageformat-number-skeleton')
Package is ESM-only; cannot use require(). Use dynamic import() from CJS.
parseNumberSkeleton
import { parseNumberSkeleton } from 'messageformat-number-skeleton'
import { parseNumberSkeleton } from 'messageformat-number-skeleton/src'
Do not import from src/; the package exports directly.
Skeleton (TS type)
import type { Skeleton } from 'messageformat-number-skeleton'
import { Skeleton } from 'messageformat-number-skeleton'
Skeleton is a TypeScript interface; use type import to avoid runtime errors.

Parses an ICU number skeleton and uses it to format numbers with locale-specific Intl.NumberFormat.

import { getNumberFormatter, parseNumberSkeleton } from 'messageformat-number-skeleton'; const skeleton = 'compact-short currency/GBP'; const parsed = parseNumberSkeleton(skeleton); console.log(parsed); // { notation: 'compact', unit: { type: 'currency', value: 'GBP' } } const formatter = getNumberFormatter('en-GB', skeleton); console.log(formatter(12345.67)); // '£12K' // With custom currency code const formatter2 = getNumberFormatter('en-US', 'percent scale/100', 'USD', (err) => console.warn(err)); console.log(formatter2(0.25)); // '25%'
Debug
Known issues
gotchaPackage is ESM-only; cannot be required() with CommonJS. Use dynamic import() or a bundler.
fix
Use import() or switch to an ESM environment.
affects: >=0.1
gotchaIntl.NumberFormat Unified API features (e.g., compact notation, unit) require a modern runtime (Node 14+). Older runtimes may produce unexpected results.
fix
Use polyfill for Intl.NumberFormat or target modern environments.
affects: >=0.1
gotchaSkeleton and Unit are TypeScript-only types; importing them as values causes runtime error.
fix
Use import type { Skeleton } from 'messageformat-number-skeleton'
affects: >=0.1
gotchaparseNumberSkeleton and parseNumberPattern return a Skeleton object; the structure may change between minor versions (pre-1.0).
fix
Pin version and test after upgrades.
affects: >=0.1
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() on an ESM-only package.
fix
Replace require() with dynamic import(): const m = await import('messageformat-number-skeleton');
TypeError: Class extends value undefined is not a constructor or null
Importing Symbol (which is a TS type) as a value.
fix
Use import type { Skeleton } from 'messageformat-number-skeleton'
TypeError: Intl.NumberFormat is not a constructor
Intl.NumberFormat not available in runtime (e.g., older Node.js or browser without polyfill).
fix
Install intl polyfill or upgrade runtime.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
intloptionalProvides Intl.NumberFormat (Unified API Proposal) for formatting; not mandatory if runtime already supports it.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources