Socket
Socket
Sign inDemoInstall

intl-format-cache

Package Overview
Dependencies
Maintainers
4
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intl-format-cache - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

CHANGELOG.md

2

dist/index.d.ts

@@ -16,3 +16,3 @@ interface RelativeTimeFormat {

}
declare var RelativeTimeFormat: {
declare let RelativeTimeFormat: {
new (locales?: string | string[], opts?: RelativeTimeFormatOptions): RelativeTimeFormat;

@@ -19,0 +19,0 @@ (locales?: string | string[], opts?: RelativeTimeFormatOptions): RelativeTimeFormat;

@@ -23,4 +23,4 @@ "use strict";

}
var memoizeFormatConstructor = function (FormatConstructor) {
var cache = {};
var memoizeFormatConstructor = function (FormatConstructor, cache) {
if (cache === void 0) { cache = {}; }
return function () {

@@ -27,0 +27,0 @@ var _a;

@@ -16,3 +16,3 @@ interface RelativeTimeFormat {

}
declare var RelativeTimeFormat: {
declare let RelativeTimeFormat: {
new (locales?: string | string[], opts?: RelativeTimeFormatOptions): RelativeTimeFormat;

@@ -19,0 +19,0 @@ (locales?: string | string[], opts?: RelativeTimeFormatOptions): RelativeTimeFormat;

@@ -21,4 +21,4 @@ /*

}
var memoizeFormatConstructor = function (FormatConstructor) {
var cache = {};
var memoizeFormatConstructor = function (FormatConstructor, cache) {
if (cache === void 0) { cache = {}; }
return function () {

@@ -25,0 +25,0 @@ var _a;

{
"name": "intl-format-cache",
"version": "2.2.1",
"version": "2.2.2",
"description": "A memoizer factory for Intl format constructors.",

@@ -9,2 +9,3 @@ "main": "index.js",

"scripts": {
"benchmark": "ts-node --project tests/tsconfig.json tests/benchmark",
"build": "tsc -p src && tsc -p src/tsconfig.cjs.json",

@@ -32,4 +33,4 @@ "clean": "rimraf lib dist",

"devDependencies": {
"intl-messageformat": "^3.1.2",
"intl-relativeformat": "^2.1.0"
"intl-messageformat": "^3.1.3",
"intl-relativeformat": "^2.1.1"
},

@@ -39,3 +40,3 @@ "prettier": {

},
"gitHead": "45cf9119c119c26a0d0b939560d3fd9af6b4ef37"
"gitHead": "caf647be47c191d9fdcf48be4cdb214ed846a917"
}

@@ -18,3 +18,3 @@ Intl Format Cache

Under the hood, this package creates a cache key based on the arguments passed to the memoized constructor (it will even order the keys of the `options` argument) it uses `JSON.stringify()` to create the string key. If the runtime does not have built-in or polyfilled support for `JSON`, new instances will be created each time the memoizer function is called.
Under the hood, this package creates a cache key based on the arguments passed to the memoized constructor (it will even order the keys of the `options` argument) it uses `JSON.stringify()` to create the string key.

@@ -53,3 +53,38 @@

# Benchmark
```
fast-memoize x 19,610 ops/sec ±1.86% (73 runs sampled)
intl-format-cache x 18,854 ops/sec ±4.95% (81 runs sampled)
--- NumberFormat cache set: Fastest is fast-memoize,intl-format-cache ---
fast-memoize x 1,051,977 ops/sec ±1.53% (89 runs sampled)
intl-format-cache x 1,134,171 ops/sec ±1.19% (91 runs sampled)
not cached x 23,002 ops/sec ±2.23% (83 runs sampled)
--- NumberFormat cache get: Fastest is intl-format-cache ---
fast-memoize x 6,466 ops/sec ±6.56% (72 runs sampled)
intl-format-cache x 7,384 ops/sec ±50.43% (64 runs sampled)
--- DateTimeFormat cache set: Fastest is fast-memoize ---
fast-memoize x 965,874 ops/sec ±17.87% (90 runs sampled)
intl-format-cache x 1,048,234 ops/sec ±0.79% (89 runs sampled)
not cached x 13,543 ops/sec ±2.61% (85 runs sampled)
--- DateTimeFormat cache get: Fastest is intl-format-cache ---
fast-memoize x 72,531 ops/sec ±26.27% (79 runs sampled)
intl-format-cache x 88,729 ops/sec ±0.51% (91 runs sampled)
--- IntlMessageFormat cache set: Fastest is intl-format-cache ---
fast-memoize x 665,420 ops/sec ±2.61% (90 runs sampled)
intl-format-cache x 649,186 ops/sec ±2.19% (90 runs sampled)
not cached x 127,110 ops/sec ±0.35% (91 runs sampled)
--- IntlMessageFormat cache get: Fastest is fast-memoize ---
fast-memoize x 1,294,591 ops/sec ±1.10% (94 runs sampled)
intl-format-cache x 1,905,746 ops/sec ±0.71% (91 runs sampled)
not cached x 152,118 ops/sec ±0.47% (94 runs sampled)
--- IntlMessageFormat cache get simple arg: Fastest is intl-format-cache ---
```
License

@@ -56,0 +91,0 @@ -------

@@ -24,3 +24,3 @@ /*

}
var RelativeTimeFormat: {
let RelativeTimeFormat: {
new (

@@ -69,19 +69,18 @@ locales?: string | string[],

const memoizeFormatConstructor: MemoizeFormatConstructorFn = FormatConstructor => {
var cache = {};
return (...args) => {
const cacheId = getCacheId(args);
let format = cacheId && cache[cacheId];
if (!format) {
format = new (FormatConstructor as any)(...args);
if (cacheId) {
cache[cacheId] = format;
}
const memoizeFormatConstructor: MemoizeFormatConstructorFn = (
FormatConstructor,
cache = {}
) => (...args) => {
const cacheId = getCacheId(args);
let format = cacheId && cache[cacheId];
if (!format) {
format = new (FormatConstructor as any)(...args);
if (cacheId) {
cache[cacheId] = format;
}
}
return format;
};
return format;
};
export default memoizeFormatConstructor;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc