npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@poppinss/intl-formatter

v3.0.3

Published

Memoized API for Intl (To be used within Node)

Downloads

18,289

Readme

@poppinss/intl-formatter

Memoized API for Intl (To be used within Node.js)

gh-workflow-image typescript-image npm-image license-image

The intl-formatter package ships with the memoized version of the Intl API. Creating new instances of the new Intl.<AnyFormatter> is painfully slow (see benchmarks), and this package caches those instances for re-use.

  • The API is 100% identical to the official spec, instead of writing new Intl.DateTimeFormat(), you write formatters.date(), and the rest is all the same.
  • All arguments are deeply compared during memoization.

Usage

Install the package from the npm registry as follows:

npm i @poppinss/intl-formatter

# Yarn friends
yarn add @poppinss/intl-formatter

And use it as follows:

import formatters from '@poppinss/intl-formatter'

const amount = formatters
  .number('en-in', { style: 'currency', currency: 'INR' })
  .format(10)

console.log(amount)

Available formatters

Why not use FormatJS?

FormatJS is a great and popular library for Internationalization. However, it has a large set of polyfills for different platforms (especially for browsers) that do not have complete support for Intl.

This package relies on the native Intl APIs available in Node.js runtime and caches the instances for re-use and performance.

Benchmarks

DateTimeFormat

DateTimeFormat@memoize x 1,115,507 ops/sec ±0.22% (94 runs sampled)
DateTimeFormat x 20,042 ops/sec ±20.76% (75 runs sampled)

Fastest is DateTimeFormat@memoize

NumberFormat

NumberFormat@memoize x 2,874,842 ops/sec ±0.28% (97 runs sampled)
NumberFormat x 74,720 ops/sec ±1.14% (97 runs sampled)

Fastest is NumberFormat@memoize

PluralRules

PluralRules@memoize x 2,381,739 ops/sec ±0.63% (97 runs sampled)
PluralRules x 62,113 ops/sec ±2.88% (91 runs sampled)

Fastest is PluralRules@memoize

RelativeTimeFormat

RelativeTimeFormat@memoize x 2,426,178 ops/sec ±1.11% (92 runs sampled)
RelativeTimeFormat x 89,485 ops/sec ±3.48% (84 runs sampled)

Fastest is RelativeTimeFormat@memoize

ListFormat

ListFormat@memoize x 1,501,976 ops/sec ±1.94% (97 runs sampled)
ListFormat x 244,943 ops/sec ±0.93% (97 runs sampled)

Fastest is ListFormat@memoize

DisplayNames

DisplayNames@memoize x 299,573 ops/sec ±0.56% (93 runs sampled)
DisplayNames x 106,279 ops/sec ±1.32% (94 runs sampled)

Fastest is DisplayNames@memoize