Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@messageformat/runtime
Advanced tools
@messageformat/runtime is a runtime library for handling message formatting in JavaScript. It allows for the creation of localized messages using ICU MessageFormat syntax, which supports pluralization, gender, and other complex message formatting needs.
Basic Message Formatting
This feature allows you to create and compile basic messages with placeholders that can be replaced with dynamic values.
const { MessageFormat } = require('@messageformat/runtime');
const mf = new MessageFormat('en');
const msg = mf.compile('Hello, {name}!');
console.log(msg({ name: 'Alice' })); // Output: Hello, Alice!
Pluralization
This feature supports pluralization, allowing you to format messages differently based on the quantity of items.
const { MessageFormat } = require('@messageformat/runtime');
const mf = new MessageFormat('en');
const msg = mf.compile('{count, plural, one {# item} other {# items}}');
console.log(msg({ count: 1 })); // Output: 1 item
console.log(msg({ count: 5 })); // Output: 5 items
Gender Formatting
This feature allows for gender-based message formatting, enabling different messages based on the gender of the subject.
const { MessageFormat } = require('@messageformat/runtime');
const mf = new MessageFormat('en');
const msg = mf.compile('{gender, select, male {He} female {She} other {They}} will respond soon.');
console.log(msg({ gender: 'male' })); // Output: He will respond soon.
console.log(msg({ gender: 'female' })); // Output: She will respond soon.
intl-messageformat is a library for formatting ICU MessageFormat strings. It provides similar functionality to @messageformat/runtime, including support for pluralization and gender formatting. However, it is part of the larger FormatJS suite, which offers additional tools for internationalization.
i18next is a comprehensive internationalization framework for JavaScript. It supports message formatting, including pluralization and gender, but also offers features like language detection, interpolation, and more. It is more feature-rich compared to @messageformat/runtime, but may be overkill for simple message formatting needs.
react-intl is a library specifically designed for internationalizing React applications. It provides components and APIs for formatting dates, numbers, and messages, including support for ICU MessageFormat. It is more specialized for React, whereas @messageformat/runtime is a more general-purpose solution.
A collection of messageformat runtime utility functions.
npm install @messageformat/runtime
This package should be marked as a dependency for any package that publishes the output of compileModule(), as the compiled ES source output may include references to it.
For applications that bundle their output using e.g. Webpack this is not necessary.
The Messages
accessor class is a completely optional addition.
See also @messageformat/react for a React-specific solution.
This package was previously named messageformat-runtime.
Messageformat is an OpenJS Foundation project, and we follow its Code of Conduct.
FAQs
Runtime components of messageformat
We found that @messageformat/runtime 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.