You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@messageformat/core

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@messageformat/core

PluralFormat and SelectFormat Message and i18n Tool - A JavaScript Implemenation of the ICU standards.


Version published
Maintainers
1
Created

Package description

What is @messageformat/core?

@messageformat/core is a JavaScript library that provides tools for handling message formatting in applications. It supports ICU MessageFormat syntax, which allows for complex message formatting including pluralization, gender, and other locale-specific variations.

What are @messageformat/core's main functionalities?

Basic Message Formatting

This feature allows you to format basic messages with variable interpolation. The example shows how to create a message template and compile it with a variable.

const { MessageFormat } = require('@messageformat/core');
const mf = new MessageFormat('en');
const message = mf.compile('Hello, {name}!');
console.log(message({ name: 'Alice' })); // Output: Hello, Alice!

Pluralization

This feature supports pluralization based on the count of items. The example demonstrates how to handle singular and plural forms of a word based on the count.

const { MessageFormat } = require('@messageformat/core');
const mf = new MessageFormat('en');
const message = mf.compile('{count, plural, one {# item} other {# items}}');
console.log(message({ count: 1 })); // Output: 1 item
console.log(message({ count: 5 })); // Output: 5 items

Gender Formatting

This feature allows for gender-based message formatting. The example shows how to format messages differently based on the gender of the subject.

const { MessageFormat } = require('@messageformat/core');
const mf = new MessageFormat('en');
const message = mf.compile('{gender, select, male {He} female {She} other {They}} will respond soon.');
console.log(message({ gender: 'male' })); // Output: He will respond soon.
console.log(message({ gender: 'female' })); // Output: She will respond soon.

Custom Formatting

This feature allows you to define custom formatting functions. The example demonstrates how to add a custom formatter that converts text to uppercase.

const { MessageFormat } = require('@messageformat/core');
const mf = new MessageFormat('en');
mf.addFormat('uppercase', (v) => v.toUpperCase());
const message = mf.compile('This is {value, uppercase}');
console.log(message({ value: 'custom' })); // Output: This is CUSTOM

Other packages similar to @messageformat/core

Readme

Source

messageformat

The experience and subtlety of your program's text is important. The messageformat project provides a complete set of tools for handling all the messages of your application, for both front-end and back-end environments; for both runtime and build-time use. It's built around the ICU MessageFormat standard and supports all the languages included in the Unicode CLDR, but it can be just as useful if you're dealing with only one of them.

ICU MessageFormat is a mechanism for handling both pluralization and gender in your applications. This is the core compiler of a JavaScript project supports and extends all parts of the official Java/C++ implementation, with the exception of the deprecated ChoiceFormat. In addition to compiling messages into JavaScript functions, it also provides tooling for making their use easy during both the build and runtime of your site or application.

For more details, please see the project's documentation site: http://messageformat.github.io/

This package was previously named messageformat.


Messageformat is an OpenJS Foundation project, and we follow its Code of Conduct.

Copyright OpenJS Foundation and messageformat contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Browser testing provided by:

BrowserStack

Keywords

FAQs

Package last updated on 14 Nov 2023

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc