1.1.3 β€’ Published 10 months ago

@httpx/memo-intl v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@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

ScenarioSize 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

LevelCIDescription
Nodeβœ…CI for 18.x, 20.x & 22.x.
Browserβœ…Tested with latest chrome (vitest/playwright)
Browserslistβœ…> 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.
Cloudflareβœ…Ensured with @cloudflare/vitest-pool-workers (see wrangler.toml
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.

1.1.3

10 months ago

1.1.2

11 months ago

1.1.1

12 months ago

1.1.0

1 year ago

1.0.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago