Registry / devops / messageformat-date-skeleton

messageformat-date-skeleton

JSON →
library0.1.1jsnpmunverified

A parser and formatter for ICU DateFormat skeleton strings, version 0.1.1, released as an ES module only. It provides functions to parse date skeletons into tokens, create date formatters using Intl.DateTimeFormat, and generate formatter source code. Unlike ICU DateFormat pattern strings, it only supports skeletons (not positional patterns) since they map directly to Intl.DateTimeFormat options. Suitable for use in messageformat or standalone date formatting with locale support.

npm install messageformat-date-skeleton
INSTALL
IMPORT
SIG · MESSAGEFORMAT-DATE
M
messageformat-date-skeleton
devopsjavascriptv0.1.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.

getDateFormatter
import { getDateFormatter } from 'messageformat-date-skeleton'
const getDateFormatter = require('messageformat-date-skeleton')
Package is ESM-only; CommonJS require() will not work, use dynamic import() or wrapper.
parseDateTokens
import { parseDateTokens } from 'messageformat-date-skeleton'
import { parseDateTokens } from 'messageformat-date-skeleton/index.mjs'
Import from the package root, not a subpath.
DateToken (TypeScript type)
import type { DateToken } from 'messageformat-date-skeleton'
import { DateToken } from 'messageformat-date-skeleton'
DateToken is a type-only export; use import type in TypeScript to avoid runtime errors.

Parses an ICU DateFormat skeleton and creates a formatter using Intl.DateTimeFormat with locale en-US.

import { parseDateTokens, getDateFormatter } from 'messageformat-date-skeleton'; // Parse a skeleton const tokens = parseDateTokens('yMMMd'); console.log(tokens); // Output: [ { type: 'year', width: 'numeric' }, { type: 'month', width: 'abbreviated' }, { type: 'day', width: 'numeric' } ] // Create a formatter const fmt = getDateFormatter('en-US', tokens); const date = new Date(2025, 0, 15); console.log(fmt(date)); // Output: 'Jan 15, 2025' // Formatter can also take a number (milliseconds since epoch) console.log(fmt(date.getTime()));
Debug
Known issues
gotchaThe package does not support ICU DateFormat patterns (e.g., 'yyyy-MM-dd'). Only skeletons (e.g., 'yMd') are supported. Using patterns will throw an error.
fix
Use only skeleton strings per ICU specification.
affects: >=0.1.0
gotchagetDateFormatterSource returns JavaScript source as a string for a date formatter function, not a direct function.
fix
Use getDateFormatter for a function object, or evaluate the source via eval/Function constructor.
affects: >=0.1.0
deprecatedNo deprecated APIs in current version.
affects: 0.1.1
breakingPackage is ESM-only, no CJS support.
fix
Use import() for CommonJS or set module resolution appropriately.
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using ESM import in a CommonJS context without proper configuration.
fix
Add "type": "module" to package.json or use dynamic import().
TypeError: getDateFormatter is not a function
Importing from wrong path or using require() for ESM-only package.
fix
Use import { getDateFormatter } from 'messageformat-date-skeleton' in an ESM context.
Error: Invalid skeleton pattern
Using ICU DateFormat pattern (e.g., 'yyyy-MM-dd') instead of skeleton (e.g., 'yMd').
fix
Use skeleton format: e.g., 'yMd', 'yMMMd' etc.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
messageformat-date-skeleton — npm install messageformat-date-skeleton · libregistry