Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@messageformat/number-skeleton
Advanced tools
A parser & formatter for ICU NumberFormat skeleton strings & patterns
@messageformat/number-skeleton is a utility for working with ICU Number Skeletons, which are a way to format numbers in a locale-aware manner. This package allows you to create, parse, and manipulate number skeletons to format numbers according to various internationalization (i18n) rules.
Creating Number Skeletons
This feature allows you to create a number skeleton for a specific format, such as currency. The code sample demonstrates creating a number skeleton for USD currency and formatting a number accordingly.
const { NumberSkeleton } = require('@messageformat/number-skeleton');
const skeleton = new NumberSkeleton('currency/USD');
console.log(skeleton.format(1234.56)); // $1,234.56
Parsing Number Skeletons
This feature allows you to parse a number skeleton string into a usable format. The code sample shows how to parse a number skeleton string and use it to format a number.
const { parseNumberSkeleton } = require('@messageformat/number-skeleton');
const skeleton = parseNumberSkeleton('currency/USD unit-width-narrow');
console.log(skeleton.format(1234.56)); // $1,234.56
Custom Number Formatting
This feature allows you to create custom number formats using number skeletons. The code sample demonstrates creating a number skeleton for percentage formatting with integer precision.
const { NumberSkeleton } = require('@messageformat/number-skeleton');
const skeleton = new NumberSkeleton('percent precision-integer');
console.log(skeleton.format(0.1234)); // 12%
The 'intl' package provides a comprehensive set of internationalization features, including number formatting. It is a more general-purpose library compared to @messageformat/number-skeleton, which is specialized for number skeletons.
The 'numeral' package is a library for formatting and manipulating numbers. It offers a wide range of formatting options but does not specifically focus on ICU Number Skeletons like @messageformat/number-skeleton.
The 'numbro' package is another library for formatting and manipulating numbers. It supports various locales and formats but does not provide the same level of integration with ICU Number Skeletons as @messageformat/number-skeleton.
Tools for working with ICU NumberFormat skeletons and patterns.
import {
getNumberFormatter,
getNumberFormatterSource,
NumberFormatError,
parseNumberPattern,
parseNumberSkeleton,
Skeleton, // TS only
Unit // TS only
} from '@messageformat/number-skeleton';
The package is released as an ES module only. If using from a CommonJS context, you may need to import()
it, or use a module loader like esm.
Uses Intl.NumberFormat internally, including features provided by the Unified API Proposal.
Class | Description |
---|---|
NumberFormatError | Base class for errors. In addition to a code and a human-friendly message , may also includes the token stem as well as other fields. |
Function | Description |
---|---|
getNumberFormatter(locales, skeleton, currency, onError) | Returns a number formatter function for the given locales and number skeleton |
getNumberFormatterSource(locales, skeleton, currency, onError) | Returns a string of JavaScript source that evaluates to a number formatter function with the same (value: number) => string signature as the function returned by getNumberFormatter(). |
parseNumberPattern(src, currency, onError) | Parse an ICU NumberFormatter pattern string into a Skeleton structure. |
parseNumberSkeleton(src, onError) | Parse an ICU NumberFormatter skeleton string into a Skeleton structure. |
Interface | Description |
---|---|
Skeleton | An object representation of a parsed string skeleton, with token values grouped by type. |
Type Alias | Description |
---|---|
Unit | Measurement units defined by the Unicode CLDR |
Messageformat is an OpenJS Foundation project, and we follow its Code of Conduct.
FAQs
A parser & formatter for ICU NumberFormat skeleton strings & patterns
The npm package @messageformat/number-skeleton receives a total of 306,614 weekly downloads. As such, @messageformat/number-skeleton popularity was classified as popular.
We found that @messageformat/number-skeleton demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.