Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@formatjs/intl-numberformat
Advanced tools
@formatjs/intl-numberformat is a JavaScript library that provides a robust and flexible way to format numbers according to different locales and formatting options. It leverages the ECMAScript Internationalization API (Intl) to offer a wide range of number formatting capabilities, including currency, percentages, and custom number formats.
Basic Number Formatting
This feature allows you to format numbers according to a specified locale. In this example, the number 1234567.89 is formatted according to the 'en-US' locale.
const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US');
console.log(formatter.format(1234567.89)); // Output: 1,234,567.89
Currency Formatting
This feature allows you to format numbers as currency. In this example, the number 1234567.89 is formatted as USD currency according to the 'en-US' locale.
const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US', { style: 'currency', currency: 'USD' });
console.log(formatter.format(1234567.89)); // Output: $1,234,567.89
Percentage Formatting
This feature allows you to format numbers as percentages. In this example, the number 0.1234 is formatted as a percentage according to the 'en-US' locale.
const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US', { style: 'percent' });
console.log(formatter.format(0.1234)); // Output: 12%
Custom Number Formatting
This feature allows you to customize the number of fraction digits. In this example, the number 1234567.89 is formatted to always show two decimal places according to the 'en-US' locale.
const { NumberFormat } = require('@formatjs/intl-numberformat');
const formatter = new NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
console.log(formatter.format(1234567.89)); // Output: 1,234,567.89
Numeral.js is a library for formatting and manipulating numbers. It provides a wide range of formatting options, including currency, percentages, and custom formats. Unlike @formatjs/intl-numberformat, Numeral.js does not rely on the Intl API and offers its own set of formatting rules.
Accounting.js is a lightweight JavaScript library for number, money, and currency formatting. It is designed to be simple and easy to use, with a focus on financial calculations. While it offers similar functionalities to @formatjs/intl-numberformat, it is more specialized for accounting purposes.
Numbro.js is a JavaScript library for formatting and manipulating numbers. It supports a wide range of locales and provides features for currency, percentages, and custom number formats. Numbro.js is similar to @formatjs/intl-numberformat but offers additional features like parsing and unformatting numbers.
intl-numberformat
We've migrated the docs to https://formatjs.github.io/docs/polyfills/intl-numberformat.
FAQs
Ponyfill for ES2020 Intl.NumberFormat
We found that @formatjs/intl-numberformat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.