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

@httpx/memo-intl

v1.1.1

Published

LRU-based memoizer for Intl constructors.

Downloads

204

Readme

@httpx/memo-intl

LRU-based memoizer for Intl.NumberFormat and Intl.DateFormat constructors.

npm changelog codecov bundles node browserslist size downloads license

Install

$ npm install @httpx/memo-intl
$ yarn add @httpx/memo-intl
$ pnpm add @httpx/memo-intl

Features

  • 👉  Don't re-create the same Intl instance for the same options (memoized).
  • 👉  Keep the Intl api untouched. Just replace new Intl.NumberFormat by MIntl.NumberFormat...
  • 👉  Up to 20x faster than non-memoized Intl constructors.
  • 👉  Decrease memory usage, unwanted memory leaks and garbage collection pressure.
  • 👉  Max out 50 cache instances by default with quick-lru.
  • 👉  Lightweight. Node, browser and edge support.

Documentation

👉 Official website or Github Readme

Usage

MIntl.NumberFormat

import { MIntl } from '@httpx/memo-intl';

// Notice: `new Intl.NumberFormat` vs `MIntl.NumberFormat`
const formattedPrice = MIntl.NumberFormat('fr-FR', {
   style: 'currency',
   currency: 'EUR',
   notation: 'compact',
   minimumFractionDigits: 2,
}).format(row.price);

MIntl.DateTimeFormat

import { MIntl } from '@httpx/memo-intl';

// Notice: `new Intl.DateTimeFormat` vs `MIntl.DateTimeFormat
const formatter = MIntl.DateTimeFormat('fr-FR', {
    dateStyle: 'full',
    timeStyle: 'full',
    timeZone: 'UTC'
});
const date = Date.parse('2024-05-29T07:42:43.230Z');
expect(formatter.format(date)).toBe(
    'mercredi 29 mai 2024 à 07:42:43 temps universel coordonné'
);
expectTypeOf(formatter).toEqualTypeOf<Intl.DateTimeFormat>();

Benchmarks

Performance is monitored with codspeed.io.

CodSpeed Badge

IntlNumberFormat(locale, options) x 10_000, see bench for details.

 RUN  v1.6.0 /home/sebastien/github/httpx/packages/memo-intl

 ✓ bench/m-intl.bench.ts (2) 3626ms
   ✓ MIntl benchmarks (2) 3624ms
     name                                                  hz     min      max    mean     p75      p99     p995     p999     rme  samples
   · With memoization `MIntl.NumberFormat()`        108.24  8.6995  10.5676  9.2388  9.8779  10.5676  10.5676  10.5676  ±5.22%       10   fastest
   · Without memoization `new Intl.NumberFormat()`  5.0021  192.58   210.78  199.92  201.81   210.78   210.78   210.78  ±1.81%       10


 BENCH  Summary

  With memoization `MIntl.NumberFormatter()` - bench/m-intl.bench.ts > MIntl benchmarks
    21.64x faster than Without memoization `new Intl.NumberFormatter()`

Bundle size

Bundle size is tracked by a size-limit configuration

| Scenario | Size with deps (compressed) | |------------------------------------------------|----------------------------:| | `import { MIntl } from '@httpx/memo-intl' | ~ 1.2kB |

Note that per-se the library weigths less than 300 bytes, the quick-lru dependency makes the difference. For CJS usage (not recommended) track the size on bundlephobia.

Compatibility

| Level | CI | Description | |------------|----|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Node | ✅ | CI for 18.x, 20.x & 22.x. | | Browsers | ✅ | > 96% on 12/2023. Mins to Chrome 96+, Firefox 90+, Edge 19+, iOS 12+, Safari 12+, Opera 77+ | | Edge | ✅ | Ensured on CI with @vercel/edge-runtime. | | Typescript | ✅ | TS 5.0 + / are-the-type-wrong checks on CI. | | ES2022 | ✅ | Dist files checked with es-check | | Performance| ✅ | Monitored with with codspeed.io |

For older browsers: most frontend frameworks can transpile the library (ie: nextjs...)

Contributors

Contributions are warmly appreciated. Have a look to the CONTRIBUTING document.

Sponsors

If my OSS work brightens your day, let's take it to new heights together! Sponsor, coffee, or star – any gesture of support fuels my passion to improve. Thanks for being awesome! 🙏❤️

Special thanks to

License

MIT © belgattitude and contributors.