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

intl-format-cache

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intl-format-cache

A memoizer factory for Intl format constructors.

4.3.1
latest
Version published
Weekly downloads
435K
1%
Maintainers
6
Weekly downloads
 
Created

What is intl-format-cache?

The intl-format-cache npm package is a utility for caching instances of Intl formatters, such as Intl.DateTimeFormat, Intl.NumberFormat, and Intl.RelativeTimeFormat. This can improve performance by reusing formatter instances instead of creating new ones each time formatting is needed.

What are intl-format-cache's main functionalities?

Caching DateTimeFormat instances

This feature allows you to cache instances of Intl.DateTimeFormat. The code sample demonstrates how to create and reuse a DateTimeFormat instance for formatting dates in 'en-US' locale.

const { getDateTimeFormat } = require('intl-format-cache');
const dateTimeFormat = getDateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
console.log(dateTimeFormat.format(new Date()));

Caching NumberFormat instances

This feature allows you to cache instances of Intl.NumberFormat. The code sample demonstrates how to create and reuse a NumberFormat instance for formatting numbers as currency in 'en-US' locale.

const { getNumberFormat } = require('intl-format-cache');
const numberFormat = getNumberFormat('en-US', { style: 'currency', currency: 'USD' });
console.log(numberFormat.format(123456.789));

Caching RelativeTimeFormat instances

This feature allows you to cache instances of Intl.RelativeTimeFormat. The code sample demonstrates how to create and reuse a RelativeTimeFormat instance for formatting relative time in 'en-US' locale.

const { getRelativeTimeFormat } = require('intl-format-cache');
const relativeTimeFormat = getRelativeTimeFormat('en-US');
console.log(relativeTimeFormat.format(-1, 'day'));

Other packages similar to intl-format-cache

Keywords

FAQs

Package last updated on 24 Jul 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