node-intl-format-cache-4.3.1/0000775000175000017500000000000015256370073014767 5ustar emfoxemfoxnode-intl-format-cache-4.3.1/index.d.ts0000555000175000017500000000067703560116604016672 0ustar emfoxemfoxexport declare type CacheValue = Intl.NumberFormat | Intl.DateTimeFormat | Intl.PluralRules | any; export interface MemoizeFormatConstructorFn { (constructor: T, cache?: Record): (...args: ConstructorParameters) => any; } declare const memoizeFormatConstructor: MemoizeFormatConstructorFn; export default memoizeFormatConstructor; //# sourceMappingURL=index.d.ts.mapnode-intl-format-cache-4.3.1/_validate_dist-esm_options.optionsvalid.d.ts0000555000175000017500000000067603560116604025604 0ustar emfoxemfox // /home/longlho/.cache/bazel/_bazel_longlho/576c18efaac10246ec115c72af79fca6/sandbox/linux-sandbox/209/execroot/formatjs/node_modules/@bazel/typescript/internal/ts_project_options_validator.js checked attributes for //packages/intl-format-cache:dist-esm // composite: false // declaration: true // declaration_map: true // incremental: false // source_map: false // emit_declaration_only: false node-intl-format-cache-4.3.1/_validate_dist_options.optionsvalid.d.ts0000555000175000017500000000067103560116604025015 0ustar emfoxemfox // /home/longlho/.cache/bazel/_bazel_longlho/576c18efaac10246ec115c72af79fca6/sandbox/linux-sandbox/20/execroot/formatjs/node_modules/@bazel/typescript/internal/ts_project_options_validator.js checked attributes for //packages/intl-format-cache:dist // composite: false // declaration: true // declaration_map: true // incremental: false // source_map: false // emit_declaration_only: false node-intl-format-cache-4.3.1/README.md0000555000175000017500000001042603560116604016241 0ustar emfoxemfox# Intl Format Cache A memoizer factory for Intl format constructors. [![npm Version][npm-badge]][npm] ![size](https://badgen.net/bundlephobia/minzip/intl-format-cache) ## Overview This is a helper package used within [FormatJS suite][formatjs]. It provides a factory for creating memoizers of [`Intl`][intl] format constructors: [`Intl.NumberFormat`][intl-nf], [`Intl.DateTimeFormat`][intl-dtf], [`IntlMessageFormat`][intl-mf], and [`IntlRelativeFormat`][intl-rf]. Creating instances of these `Intl` formats is an expensive operation, and the APIs are designed such that developers should re-use format instances instead of always creating new ones. This package is simply to make it easier to create a cache of format instances of a particular type to aid in their reuse. 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. ## Usage This package works as an ES6 or Node.js module, in either case it has a single default export function; e.g.: ```js // In an ES6 module. import memoizeFormatConstructor from 'intl-format-cache'; ``` ```js // In Node. var memoizeFormatConstructor = require('intl-format-cache'); ``` This default export is a factory function which can be passed an `Intl` format constructor and it will return a memoizer that will create or reuse an `Intl` format instance and return it. ```js var getNumberFormat = memoizeFormatConstructor(Intl.NumberFormat); var nf1 = getNumberFormat('en'); var nf2 = getNumberFormat('en'); var nf3 = getNumberFormat('fr'); console.log(nf1 === nf2); // => true console.log(nf1 === nf3); // => false console.log(nf1.format(1000)); // => "1,000" console.log(nf3.format(1000)); // => "1 000" ``` # 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 --- number x 536,024 ops/sec ±0.99% (86 runs sampled) datetime x 397,275 ops/sec ±0.92% (90 runs sampled) messageformat x 1,278,072 ops/sec ±1.31% (89 runs sampled) --- all formats: Fastest is messageformat --- number x 532,863 ops/sec ±0.79% (93 runs sampled) datetime x 377,391 ops/sec ±1.11% (89 runs sampled) messageformat x 709,020 ops/sec ±3.19% (81 runs sampled) --- all formats random input: Fastest is messageformat --- ``` [npm]: https://www.npmjs.org/package/intl-format-cache [npm-badge]: https://img.shields.io/npm/v/intl-format-cache.svg?style=flat-square [intl]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl [intl-nf]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat [intl-dtf]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat [intl-mf]: https://github.com/formatjs/formatjs [intl-rf]: https://github.com/formatjs/formatjs [formatjs]: http://formatjs.io/ node-intl-format-cache-4.3.1/LICENSE.md0000555000175000017500000000303003560116604016357 0ustar emfoxemfoxCopyright (c) 2019, Oath Inc. Licensed under the terms of the New BSD license. See below for terms. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of Oath Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Oath Inc. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. node-intl-format-cache-4.3.1/index.d.ts.map0000555000175000017500000000102503560116604017432 0ustar emfoxemfox{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/intl-format-cache/index.ts"],"names":[],"mappings":"AAsBA,oBAAY,UAAU,GAClB,IAAI,CAAC,YAAY,GACjB,IAAI,CAAC,cAAc,GACnB,IAAI,CAAC,WAAW,GAChB,GAAG,CAAC;AAER,MAAM,WAAW,0BAA0B;IACzC,CAAC,CAAC,SAAS;QAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;KAAC,EACpC,WAAW,EAAE,CAAC,EACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GACjC,CAAC,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;CAC/C;AAED,QAAA,MAAM,wBAAwB,EAAE,0BAc/B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}node-intl-format-cache-4.3.1/package.json0000555000175000017500000000120503560116604017243 0ustar emfoxemfox{ "name": "intl-format-cache", "version": "4.3.1", "description": "A memoizer factory for Intl format constructors.", "main": "index.js", "module": "lib/index.js", "types": "intl-format-cache.d.ts", "repository": { "type": "git", "url": "https://github.com/formatjs/formatjs.git" }, "keywords": [ "intl", "i18n" ], "sideEffects": false, "author": "Eric Ferraiuolo ", "license": "BSD-3-Clause", "bugs": { "url": "https://github.com/formatjs/formatjs/issues" }, "homepage": "https://github.com/formatjs/formatjs", "gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c" } node-intl-format-cache-4.3.1/lib/0000775000175000017500000000000015256370073015535 5ustar emfoxemfoxnode-intl-format-cache-4.3.1/lib/index.d.ts0000555000175000017500000000067703560116604017440 0ustar emfoxemfoxexport declare type CacheValue = Intl.NumberFormat | Intl.DateTimeFormat | Intl.PluralRules | any; export interface MemoizeFormatConstructorFn { (constructor: T, cache?: Record): (...args: ConstructorParameters) => any; } declare const memoizeFormatConstructor: MemoizeFormatConstructorFn; export default memoizeFormatConstructor; //# sourceMappingURL=index.d.ts.mapnode-intl-format-cache-4.3.1/lib/index.d.ts.map0000555000175000017500000000103003560116604020174 0ustar emfoxemfox{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-format-cache/index.ts"],"names":[],"mappings":"AAsBA,oBAAY,UAAU,GAClB,IAAI,CAAC,YAAY,GACjB,IAAI,CAAC,cAAc,GACnB,IAAI,CAAC,WAAW,GAChB,GAAG,CAAC;AAER,MAAM,WAAW,0BAA0B;IACzC,CAAC,CAAC,SAAS;QAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;KAAC,EACpC,WAAW,EAAE,CAAC,EACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GACjC,CAAC,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;CAC/C;AAED,QAAA,MAAM,wBAAwB,EAAE,0BAc/B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}node-intl-format-cache-4.3.1/lib/index.js0000555000175000017500000000304103560116604017170 0ustar emfoxemfox/* Copyright (c) 2014, Yahoo! Inc. All rights reserved. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; // -- Utilities ---------------------------------------------------------------- function getCacheId(inputs) { return JSON.stringify(inputs.map(function (input) { return input && typeof input === 'object' ? orderedProps(input) : input; })); } function orderedProps(obj) { return Object.keys(obj) .sort() .map(function (k) { var _a; return (_a = {}, _a[k] = obj[k], _a); }); } var memoizeFormatConstructor = function (FormatConstructor, cache) { if (cache === void 0) { cache = {}; } return function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var cacheId = getCacheId(args); var format = cacheId && cache[cacheId]; if (!format) { format = new ((_a = FormatConstructor).bind.apply(_a, __spreadArrays([void 0], args)))(); if (cacheId) { cache[cacheId] = format; } } return format; }; }; export default memoizeFormatConstructor; node-intl-format-cache-4.3.1/index.js0000555000175000017500000000316103560116604016425 0ustar emfoxemfox"use strict"; /* Copyright (c) 2014, Yahoo! Inc. All rights reserved. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; Object.defineProperty(exports, "__esModule", { value: true }); // -- Utilities ---------------------------------------------------------------- function getCacheId(inputs) { return JSON.stringify(inputs.map(function (input) { return input && typeof input === 'object' ? orderedProps(input) : input; })); } function orderedProps(obj) { return Object.keys(obj) .sort() .map(function (k) { var _a; return (_a = {}, _a[k] = obj[k], _a); }); } var memoizeFormatConstructor = function (FormatConstructor, cache) { if (cache === void 0) { cache = {}; } return function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var cacheId = getCacheId(args); var format = cacheId && cache[cacheId]; if (!format) { format = new ((_a = FormatConstructor).bind.apply(_a, __spreadArrays([void 0], args)))(); if (cacheId) { cache[cacheId] = format; } } return format; }; }; exports.default = memoizeFormatConstructor;