🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@messageformat/parser

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@messageformat/parser

An AST parser for ICU MessageFormat strings

5.1.1
latest
Source
npm
Version published
Weekly downloads
697K
-8.69%
Maintainers
0
Weekly downloads
 
Created

What is @messageformat/parser?

@messageformat/parser is a library for parsing ICU MessageFormat strings. It allows developers to handle complex internationalization (i18n) scenarios by parsing and formatting messages with pluralization, gender, and other language-specific rules.

What are @messageformat/parser's main functionalities?

Parsing MessageFormat strings

This feature allows you to parse a MessageFormat string into an abstract syntax tree (AST). The example demonstrates parsing a message that handles pluralization based on the count.

const { parse } = require('@messageformat/parser');
const message = 'You have {count, plural, one {# message} other {# messages}}.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Handling nested messages

This feature allows you to parse messages with nested structures, such as gender-based selection combined with pluralization. The example demonstrates parsing a message that handles both gender and pluralization.

const { parse } = require('@messageformat/parser');
const message = '{gender, select, male {He} female {She} other {They}} liked {count, plural, one {# message} other {# messages}}.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Custom formatting

This feature allows you to parse messages with custom formatting options, such as currency formatting. The example demonstrates parsing a message that formats a number as a currency.

const { parse } = require('@messageformat/parser');
const message = 'The price is {price, number, ::currency/USD}.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Other packages similar to @messageformat/parser

Keywords

icu

FAQs

Package last updated on 28 Dec 2024

Did you know?

Socket

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.

Install

Related posts