Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

messageformat-parser

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messageformat-parser

A PEG.js parser for ICU MessageFormat strings

  • 4.1.3
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
549K
decreased by-10.01%
Maintainers
2
Weekly downloads
 
Created

What is messageformat-parser?

The messageformat-parser npm package is a tool for parsing ICU MessageFormat strings. It is used to handle internationalization (i18n) by parsing messages that can include variables, plurals, and select statements. This package is particularly useful for applications that need to support multiple languages and complex message formatting.

What are messageformat-parser's main functionalities?

Parsing Simple Messages

This feature allows you to parse simple messages with placeholders. The `parse` function takes a message string and returns an abstract syntax tree (AST) representing the structure of the message.

const { parse } = require('messageformat-parser');
const message = 'Hello, {name}!';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Handling Plurals

This feature allows you to parse messages that include pluralization. The `parse` function can handle ICU MessageFormat plural syntax, making it easier to manage messages that need to change based on quantity.

const { parse } = require('messageformat-parser');
const message = '{count, plural, one {# item} other {# items}}';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Handling Select Statements

This feature allows you to parse messages that include select statements. The `parse` function can handle ICU MessageFormat select syntax, which is useful for gender-specific or other conditional messages.

const { parse } = require('messageformat-parser');
const message = '{gender, select, male {He} female {She} other {They}} will respond soon.';
const parsed = parse(message);
console.log(JSON.stringify(parsed, null, 2));

Other packages similar to messageformat-parser

Keywords

FAQs

Package last updated on 12 Apr 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc