chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
@@ -0,0 +1,21 @@
# @react-native/normalize-colors
[![Version][version-badge]][package]
## Installation
```
yarn add --dev @react-native/normalize-colors
```
*Note: We're using `yarn` to install deps. Feel free to change commands to use `npm` 3+ and `npx` if you like*
[version-badge]: https://img.shields.io/npm/v/@react-native/normalize-colors?style=flat-square
[package]: https://www.npmjs.com/package/@react-native/normalize-colors
## Testing
To run the tests in this package, run the following commands from the React Native root folder:
1. `yarn` to install the dependencies. You just need to run this once
2. `yarn jest packages/normalize-color`.
@@ -0,0 +1,461 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @noflow
*/
/* eslint no-bitwise: 0 */
'use strict';
function normalizeColor(color) {
if (typeof color === 'number') {
if (color >>> 0 === color && color >= 0 && color <= 0xffffffff) {
return color;
}
return null;
}
if (typeof color !== 'string') {
return null;
}
const matchers = getMatchers();
let match;
// Ordered based on occurrences on Facebook codebase
if ((match = matchers.hex6.exec(color))) {
return parseInt(match[1] + 'ff', 16) >>> 0;
}
const colorFromKeyword = normalizeKeyword(color);
if (colorFromKeyword != null) {
return colorFromKeyword;
}
if ((match = matchers.rgb.exec(color))) {
return (
((parse255(match[1]) << 24) | // r
(parse255(match[2]) << 16) | // g
(parse255(match[3]) << 8) | // b
0x000000ff) >>> // a
0
);
}
if ((match = matchers.rgba.exec(color))) {
// rgba(R G B / A) notation
if (match[6] !== undefined) {
return (
((parse255(match[6]) << 24) | // r
(parse255(match[7]) << 16) | // g
(parse255(match[8]) << 8) | // b
parse1(match[9])) >>> // a
0
);
}
// rgba(R, G, B, A) notation
return (
((parse255(match[2]) << 24) | // r
(parse255(match[3]) << 16) | // g
(parse255(match[4]) << 8) | // b
parse1(match[5])) >>> // a
0
);
}
if ((match = matchers.hex3.exec(color))) {
return (
parseInt(
match[1] +
match[1] + // r
match[2] +
match[2] + // g
match[3] +
match[3] + // b
'ff', // a
16,
) >>> 0
);
}
// https://drafts.csswg.org/css-color-4/#hex-notation
if ((match = matchers.hex8.exec(color))) {
return parseInt(match[1], 16) >>> 0;
}
if ((match = matchers.hex4.exec(color))) {
return (
parseInt(
match[1] +
match[1] + // r
match[2] +
match[2] + // g
match[3] +
match[3] + // b
match[4] +
match[4], // a
16,
) >>> 0
);
}
if ((match = matchers.hsl.exec(color))) {
return (
(hslToRgb(
parse360(match[1]), // h
parsePercentage(match[2]), // s
parsePercentage(match[3]), // l
) |
0x000000ff) >>> // a
0
);
}
if ((match = matchers.hsla.exec(color))) {
// hsla(H S L / A) notation
if (match[6] !== undefined) {
return (
(hslToRgb(
parse360(match[6]), // h
parsePercentage(match[7]), // s
parsePercentage(match[8]), // l
) |
parse1(match[9])) >>> // a
0
);
}
// hsla(H, S, L, A) notation
return (
(hslToRgb(
parse360(match[2]), // h
parsePercentage(match[3]), // s
parsePercentage(match[4]), // l
) |
parse1(match[5])) >>> // a
0
);
}
if ((match = matchers.hwb.exec(color))) {
return (
(hwbToRgb(
parse360(match[1]), // h
parsePercentage(match[2]), // w
parsePercentage(match[3]), // b
) |
0x000000ff) >>> // a
0
);
}
return null;
}
function hue2rgb(p, q, t) {
if (t < 0) {
t += 1;
}
if (t > 1) {
t -= 1;
}
if (t < 1 / 6) {
return p + (q - p) * 6 * t;
}
if (t < 1 / 2) {
return q;
}
if (t < 2 / 3) {
return p + (q - p) * (2 / 3 - t) * 6;
}
return p;
}
function hslToRgb(h, s, l) {
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
const r = hue2rgb(p, q, h + 1 / 3);
const g = hue2rgb(p, q, h);
const b = hue2rgb(p, q, h - 1 / 3);
return (
(Math.round(r * 255) << 24) |
(Math.round(g * 255) << 16) |
(Math.round(b * 255) << 8)
);
}
function hwbToRgb(h, w, b) {
if (w + b >= 1) {
const gray = Math.round((w * 255) / (w + b));
return (gray << 24) | (gray << 16) | (gray << 8);
}
const red = hue2rgb(0, 1, h + 1 / 3) * (1 - w - b) + w;
const green = hue2rgb(0, 1, h) * (1 - w - b) + w;
const blue = hue2rgb(0, 1, h - 1 / 3) * (1 - w - b) + w;
return (
(Math.round(red * 255) << 24) |
(Math.round(green * 255) << 16) |
(Math.round(blue * 255) << 8)
);
}
const NUMBER = '[-+]?\\d*\\.?\\d+';
const PERCENTAGE = NUMBER + '%';
function call(...args) {
return '\\(\\s*(' + args.join(')\\s*,?\\s*(') + ')\\s*\\)';
}
function callWithSlashSeparator(...args) {
return (
'\\(\\s*(' +
args.slice(0, args.length - 1).join(')\\s*,?\\s*(') +
')\\s*/\\s*(' +
args[args.length - 1] +
')\\s*\\)'
);
}
function commaSeparatedCall(...args) {
return '\\(\\s*(' + args.join(')\\s*,\\s*(') + ')\\s*\\)';
}
let cachedMatchers;
function getMatchers() {
if (cachedMatchers === undefined) {
cachedMatchers = {
rgb: new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER)),
rgba: new RegExp(
'rgba(' +
commaSeparatedCall(NUMBER, NUMBER, NUMBER, NUMBER) +
'|' +
callWithSlashSeparator(NUMBER, NUMBER, NUMBER, NUMBER) +
')',
),
hsl: new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE)),
hsla: new RegExp(
'hsla(' +
commaSeparatedCall(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER) +
'|' +
callWithSlashSeparator(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER) +
')',
),
hwb: new RegExp('hwb' + call(NUMBER, PERCENTAGE, PERCENTAGE)),
hex3: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
hex4: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
hex6: /^#([0-9a-fA-F]{6})$/,
hex8: /^#([0-9a-fA-F]{8})$/,
};
}
return cachedMatchers;
}
function parse255(str) {
const int = parseInt(str, 10);
if (int < 0) {
return 0;
}
if (int > 255) {
return 255;
}
return int;
}
function parse360(str) {
const int = parseFloat(str);
return (((int % 360) + 360) % 360) / 360;
}
function parse1(str) {
const num = parseFloat(str);
if (num < 0) {
return 0;
}
if (num > 1) {
return 255;
}
return Math.round(num * 255);
}
function parsePercentage(str) {
// parseFloat conveniently ignores the final %
const int = parseFloat(str);
if (int < 0) {
return 0;
}
if (int > 100) {
return 1;
}
return int / 100;
}
function normalizeKeyword(name) {
// prettier-ignore
switch (name) {
case 'transparent': return 0x00000000;
// http://www.w3.org/TR/css3-color/#svg-color
case 'aliceblue': return 0xf0f8ffff;
case 'antiquewhite': return 0xfaebd7ff;
case 'aqua': return 0x00ffffff;
case 'aquamarine': return 0x7fffd4ff;
case 'azure': return 0xf0ffffff;
case 'beige': return 0xf5f5dcff;
case 'bisque': return 0xffe4c4ff;
case 'black': return 0x000000ff;
case 'blanchedalmond': return 0xffebcdff;
case 'blue': return 0x0000ffff;
case 'blueviolet': return 0x8a2be2ff;
case 'brown': return 0xa52a2aff;
case 'burlywood': return 0xdeb887ff;
case 'burntsienna': return 0xea7e5dff;
case 'cadetblue': return 0x5f9ea0ff;
case 'chartreuse': return 0x7fff00ff;
case 'chocolate': return 0xd2691eff;
case 'coral': return 0xff7f50ff;
case 'cornflowerblue': return 0x6495edff;
case 'cornsilk': return 0xfff8dcff;
case 'crimson': return 0xdc143cff;
case 'cyan': return 0x00ffffff;
case 'darkblue': return 0x00008bff;
case 'darkcyan': return 0x008b8bff;
case 'darkgoldenrod': return 0xb8860bff;
case 'darkgray': return 0xa9a9a9ff;
case 'darkgreen': return 0x006400ff;
case 'darkgrey': return 0xa9a9a9ff;
case 'darkkhaki': return 0xbdb76bff;
case 'darkmagenta': return 0x8b008bff;
case 'darkolivegreen': return 0x556b2fff;
case 'darkorange': return 0xff8c00ff;
case 'darkorchid': return 0x9932ccff;
case 'darkred': return 0x8b0000ff;
case 'darksalmon': return 0xe9967aff;
case 'darkseagreen': return 0x8fbc8fff;
case 'darkslateblue': return 0x483d8bff;
case 'darkslategray': return 0x2f4f4fff;
case 'darkslategrey': return 0x2f4f4fff;
case 'darkturquoise': return 0x00ced1ff;
case 'darkviolet': return 0x9400d3ff;
case 'deeppink': return 0xff1493ff;
case 'deepskyblue': return 0x00bfffff;
case 'dimgray': return 0x696969ff;
case 'dimgrey': return 0x696969ff;
case 'dodgerblue': return 0x1e90ffff;
case 'firebrick': return 0xb22222ff;
case 'floralwhite': return 0xfffaf0ff;
case 'forestgreen': return 0x228b22ff;
case 'fuchsia': return 0xff00ffff;
case 'gainsboro': return 0xdcdcdcff;
case 'ghostwhite': return 0xf8f8ffff;
case 'gold': return 0xffd700ff;
case 'goldenrod': return 0xdaa520ff;
case 'gray': return 0x808080ff;
case 'green': return 0x008000ff;
case 'greenyellow': return 0xadff2fff;
case 'grey': return 0x808080ff;
case 'honeydew': return 0xf0fff0ff;
case 'hotpink': return 0xff69b4ff;
case 'indianred': return 0xcd5c5cff;
case 'indigo': return 0x4b0082ff;
case 'ivory': return 0xfffff0ff;
case 'khaki': return 0xf0e68cff;
case 'lavender': return 0xe6e6faff;
case 'lavenderblush': return 0xfff0f5ff;
case 'lawngreen': return 0x7cfc00ff;
case 'lemonchiffon': return 0xfffacdff;
case 'lightblue': return 0xadd8e6ff;
case 'lightcoral': return 0xf08080ff;
case 'lightcyan': return 0xe0ffffff;
case 'lightgoldenrodyellow': return 0xfafad2ff;
case 'lightgray': return 0xd3d3d3ff;
case 'lightgreen': return 0x90ee90ff;
case 'lightgrey': return 0xd3d3d3ff;
case 'lightpink': return 0xffb6c1ff;
case 'lightsalmon': return 0xffa07aff;
case 'lightseagreen': return 0x20b2aaff;
case 'lightskyblue': return 0x87cefaff;
case 'lightslategray': return 0x778899ff;
case 'lightslategrey': return 0x778899ff;
case 'lightsteelblue': return 0xb0c4deff;
case 'lightyellow': return 0xffffe0ff;
case 'lime': return 0x00ff00ff;
case 'limegreen': return 0x32cd32ff;
case 'linen': return 0xfaf0e6ff;
case 'magenta': return 0xff00ffff;
case 'maroon': return 0x800000ff;
case 'mediumaquamarine': return 0x66cdaaff;
case 'mediumblue': return 0x0000cdff;
case 'mediumorchid': return 0xba55d3ff;
case 'mediumpurple': return 0x9370dbff;
case 'mediumseagreen': return 0x3cb371ff;
case 'mediumslateblue': return 0x7b68eeff;
case 'mediumspringgreen': return 0x00fa9aff;
case 'mediumturquoise': return 0x48d1ccff;
case 'mediumvioletred': return 0xc71585ff;
case 'midnightblue': return 0x191970ff;
case 'mintcream': return 0xf5fffaff;
case 'mistyrose': return 0xffe4e1ff;
case 'moccasin': return 0xffe4b5ff;
case 'navajowhite': return 0xffdeadff;
case 'navy': return 0x000080ff;
case 'oldlace': return 0xfdf5e6ff;
case 'olive': return 0x808000ff;
case 'olivedrab': return 0x6b8e23ff;
case 'orange': return 0xffa500ff;
case 'orangered': return 0xff4500ff;
case 'orchid': return 0xda70d6ff;
case 'palegoldenrod': return 0xeee8aaff;
case 'palegreen': return 0x98fb98ff;
case 'paleturquoise': return 0xafeeeeff;
case 'palevioletred': return 0xdb7093ff;
case 'papayawhip': return 0xffefd5ff;
case 'peachpuff': return 0xffdab9ff;
case 'peru': return 0xcd853fff;
case 'pink': return 0xffc0cbff;
case 'plum': return 0xdda0ddff;
case 'powderblue': return 0xb0e0e6ff;
case 'purple': return 0x800080ff;
case 'rebeccapurple': return 0x663399ff;
case 'red': return 0xff0000ff;
case 'rosybrown': return 0xbc8f8fff;
case 'royalblue': return 0x4169e1ff;
case 'saddlebrown': return 0x8b4513ff;
case 'salmon': return 0xfa8072ff;
case 'sandybrown': return 0xf4a460ff;
case 'seagreen': return 0x2e8b57ff;
case 'seashell': return 0xfff5eeff;
case 'sienna': return 0xa0522dff;
case 'silver': return 0xc0c0c0ff;
case 'skyblue': return 0x87ceebff;
case 'slateblue': return 0x6a5acdff;
case 'slategray': return 0x708090ff;
case 'slategrey': return 0x708090ff;
case 'snow': return 0xfffafaff;
case 'springgreen': return 0x00ff7fff;
case 'steelblue': return 0x4682b4ff;
case 'tan': return 0xd2b48cff;
case 'teal': return 0x008080ff;
case 'thistle': return 0xd8bfd8ff;
case 'tomato': return 0xff6347ff;
case 'turquoise': return 0x40e0d0ff;
case 'violet': return 0xee82eeff;
case 'wheat': return 0xf5deb3ff;
case 'white': return 0xffffffff;
case 'whitesmoke': return 0xf5f5f5ff;
case 'yellow': return 0xffff00ff;
case 'yellowgreen': return 0x9acd32ff;
}
return null;
}
module.exports = normalizeColor;
@@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
*/
declare module.exports: (color: ?(string | number)) => null | number;
@@ -0,0 +1,19 @@
{
"name": "@react-native/normalize-colors",
"version": "0.74.89",
"description": "Color normalization for React Native.",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/facebook/react-native.git",
"directory": "packages/normalize-color"
},
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/normalize-color#readme",
"keywords": [
"color",
"normalization",
"normalize-colors",
"react-native"
],
"bugs": "https://github.com/facebook/react-native/issues"
}
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Alexander Reardon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,630 @@
# memoize-one
A memoization library that only caches the result of the most recent arguments.
[![npm](https://img.shields.io/npm/v/memoize-one.svg)](https://www.npmjs.com/package/memoize-one)
![types](https://img.shields.io/badge/types-typescript%20%7C%20flow-blueviolet)
[![minzip](https://img.shields.io/bundlephobia/minzip/memoize-one.svg)](https://www.npmjs.com/package/memoize-one)
[![Downloads per month](https://img.shields.io/npm/dm/memoize-one.svg)](https://www.npmjs.com/package/memoize-one)
## Rationale
Unlike other memoization libraries, `memoize-one` only remembers the latest arguments and result. No need to worry about cache busting mechanisms such as `maxAge`, `maxSize`, `exclusions` and so on, which can be prone to memory leaks. A function memoized with `memoize-one` simply remembers the last arguments, and if the memoized function is next called with the same arguments then it returns the previous result.
> For working with promises, [@Kikobeats](https://github.com/Kikobeats) has built [async-memoize-one](https://github.com/microlinkhq/async-memoize-one).
## Usage
```js
// memoize-one uses the default import
import memoizeOne from 'memoize-one';
function add(a, b) {
return a + b;
}
const memoizedAdd = memoizeOne(add);
memoizedAdd(1, 2);
// add function: is called
// [new value returned: 3]
memoizedAdd(1, 2);
// add function: not called
// [cached result is returned: 3]
memoizedAdd(2, 3);
// add function: is called
// [new value returned: 5]
memoizedAdd(2, 3);
// add function: not called
// [cached result is returned: 5]
memoizedAdd(1, 2);
// add function: is called
// [new value returned: 3]
// 👇
// While the result of `add(1, 2)` was previously cached
// `(1, 2)` was not the *latest* arguments (the last call was `(2, 3)`)
// so the previous cached result of `(1, 3)` was lost
```
## Installation
```bash
# yarn
yarn add memoize-one
# npm
npm install memoize-one --save
```
## Function argument equality
By default, we apply our own _fast_ and _relatively naive_ equality function to determine whether the arguments provided to your function are equal. You can see the full code here: [are-inputs-equal.ts](https://github.com/alexreardon/memoize-one/blob/master/src/are-inputs-equal.ts).
(By default) function arguments are considered equal if:
1. there is same amount of arguments
2. each new argument has strict equality (`===`) with the previous argument
3. **[special case]** if two arguments are not `===` and they are both `NaN` then the two arguments are treated as equal
What this looks like in practice:
```js
import memoizeOne from 'memoize-one';
// add all numbers provided to the function
const add = (...args = []) =>
args.reduce((current, value) => {
return current + value;
}, 0);
const memoizedAdd = memoizeOne(add);
```
> 1. there is same amount of arguments
```js
memoizedAdd(1, 2);
// the amount of arguments has changed, so underlying add function is called
memoizedAdd(1, 2, 3);
```
> 2. new arguments have strict equality (`===`) with the previous argument
```js
memoizedAdd(1, 2);
// each argument is `===` to the last argument, so cache is used
memoizedAdd(1, 2);
// second argument has changed, so add function is called again
memoizedAdd(1, 3);
// the first value is not `===` to the previous first value (1 !== 3)
// so add function is called again
memoizedAdd(3, 1);
```
> 3. **[special case]** if the arguments are not `===` and they are both `NaN` then the argument is treated as equal
```js
memoizedAdd(NaN);
// Even though NaN !== NaN these arguments are
// treated as equal as they are both `NaN`
memoizedAdd(NaN);
```
## Custom equality function
You can also pass in a custom function for checking the equality of two sets of arguments
```js
const memoized = memoizeOne(fn, isEqual);
```
An equality function should return `true` if the arguments are equal. If `true` is returned then the wrapped function will not be called.
**Tip**: A custom equality function needs to compare `Arrays`. The `newArgs` array will be a new reference every time so a simple `newArgs === lastArgs` will always return `false`.
Equality functions are not called if the `this` context of the function has changed (see below).
Here is an example that uses a [lodash.isEqual](https://lodash.com/docs/4.17.15#isEqual) deep equal equality check
> `lodash.isequal` correctly handles deep comparing two arrays
```js
import memoizeOne from 'memoize-one';
import isDeepEqual from 'lodash.isequal';
const identity = (x) => x;
const shallowMemoized = memoizeOne(identity);
const deepMemoized = memoizeOne(identity, isDeepEqual);
const result1 = shallowMemoized({ foo: 'bar' });
const result2 = shallowMemoized({ foo: 'bar' });
result1 === result2; // false - different object reference
const result3 = deepMemoized({ foo: 'bar' });
const result4 = deepMemoized({ foo: 'bar' });
result3 === result4; // true - arguments are deep equal
```
The equality function needs to conform to the `EqualityFn` `type`:
```ts
// TFunc is the function being memoized
type EqualityFn<TFunc extends (...args: any[]) => any> = (
newArgs: Parameters<TFunc>,
lastArgs: Parameters<TFunc>,
) => boolean;
// You can import this type
import type { EqualityFn } from 'memoize-one';
```
The `EqualityFn` type allows you to create equality functions that are extremely typesafe. You are welcome to provide your own less type safe equality functions.
Here are some examples of equality functions which are ordered by most type safe, to least type safe:
<details>
<summary>Example equality function types</summary>
<p>
```ts
// the function we are going to memoize
function add(first: number, second: number): number {
return first + second;
}
// Some options for our equality function
// ↑ stronger types
// ↓ weaker types
// ✅ exact parameters of `add`
{
const isEqual = function (first: Parameters<typeof add>, second: Parameters<typeof add>) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ tuple of the correct types
{
const isEqual = function (first: [number, number], second: [number, number]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ❌ tuple of incorrect types
{
const isEqual = function (first: [number, string], second: [number, number]) {
return true;
};
expectTypeOf<typeof isEqual>().not.toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ array of the correct types
{
const isEqual = function (first: number[], second: number[]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ❌ array of incorrect types
{
const isEqual = function (first: string[], second: number[]) {
return true;
};
expectTypeOf<typeof isEqual>().not.toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ tuple of 'unknown'
{
const isEqual = function (first: [unknown, unknown], second: [unknown, unknown]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ❌ tuple of 'unknown' of incorrect length
{
const isEqual = function (first: [unknown, unknown, unknown], second: [unknown, unknown]) {
return true;
};
expectTypeOf<typeof isEqual>().not.toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ array of 'unknown'
{
const isEqual = function (first: unknown[], second: unknown[]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ spread of 'unknown'
{
const isEqual = function (...first: unknown[]) {
return !!first;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ tuple of 'any'
{
const isEqual = function (first: [any, any], second: [any, any]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ❌ tuple of 'any' or incorrect size
{
const isEqual = function (first: [any, any, any], second: [any, any]) {
return true;
};
expectTypeOf<typeof isEqual>().not.toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ array of 'any'
{
const isEqual = function (first: any[], second: any[]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ two arguments of type any
{
const isEqual = function (first: any, second: any) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ a single argument of type any
{
const isEqual = function (first: any) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
// ✅ spread of any type
{
const isEqual = function (...first: any[]) {
return true;
};
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
}
```
</p>
</details>
## `this`
### `memoize-one` correctly respects `this` control
This library takes special care to maintain, and allow control over the the `this` context for **both** the original function being memoized as well as the returned memoized function. Both the original function and the memoized function's `this` context respect [all the `this` controlling techniques](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch2.md):
- new bindings (`new`)
- explicit binding (`call`, `apply`, `bind`);
- implicit binding (call site: `obj.foo()`);
- default binding (`window` or `undefined` in `strict mode`);
- fat arrow binding (binding to lexical `this`)
- ignored this (pass `null` as `this` to explicit binding)
### Changes to `this` is considered an argument change
Changes to the running context (`this`) of a function can result in the function returning a different value even though its arguments have stayed the same:
```js
function getA() {
return this.a;
}
const temp1 = {
a: 20,
};
const temp2 = {
a: 30,
};
getA.call(temp1); // 20
getA.call(temp2); // 30
```
Therefore, in order to prevent against unexpected results, `memoize-one` takes into account the current execution context (`this`) of the memoized function. If `this` is different to the previous invocation then it is considered a change in argument. [further discussion](https://github.com/alexreardon/memoize-one/issues/3).
Generally this will be of no impact if you are not explicity controlling the `this` context of functions you want to memoize with [explicit binding](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch2.md#explicit-binding) or [implicit binding](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch2.md#implicit-binding). `memoize-One` will detect when you are manipulating `this` and will then consider the `this` context as an argument. If `this` changes, it will re-execute the original function even if the arguments have not changed.
## Clearing the memoization cache
A `.clear()` property is added to memoized functions to allow you to clear it's memoization cache.
This is helpful if you want to:
- Release memory
- Allow the underlying function to be called again without having to change arguments
```ts
import memoizeOne from 'memoize-one';
function add(a: number, b: number): number {
return a + b;
}
const memoizedAdd = memoizeOne(add);
// first call - not memoized
const first = memoizedAdd(1, 2);
// second call - cache hit (underlying function not called)
const second = memoizedAdd(1, 2);
// 👋 clearing memoization cache
memoizedAdd.clear();
// third call - not memoized (cache was cleared)
const third = memoizedAdd(1, 2);
```
## When your result function `throw`s
> There is no caching when your result function throws
If your result function `throw`s then the memoized function will also throw. The throw will not break the memoized functions existing argument cache. It means the memoized function will pretend like it was never called with arguments that made it `throw`.
```js
const canThrow = (name: string) => {
console.log('called');
if (name === 'throw') {
throw new Error(name);
}
return { name };
};
const memoized = memoizeOne(canThrow);
const value1 = memoized('Alex');
// console.log => 'called'
const value2 = memoized('Alex');
// result function not called
console.log(value1 === value2);
// console.log => true
try {
memoized('throw');
// console.log => 'called'
} catch (e) {
firstError = e;
}
try {
memoized('throw');
// console.log => 'called'
// the result function was called again even though it was called twice
// with the 'throw' string
} catch (e) {
secondError = e;
}
console.log(firstError !== secondError);
const value3 = memoized('Alex');
// result function not called as the original memoization cache has not been busted
console.log(value1 === value3);
// console.log => true
```
## Function properties
Functions memoized with `memoize-one` do not preserve any properties on the function object.
> This behaviour correctly reflected in the TypeScript types
```ts
import memoizeOne from 'memoize-one';
function add(a, b) {
return a + b;
}
add.hello = 'hi';
console.log(typeof add.hello); // string
const memoized = memoizeOne(add);
// hello property on the `add` was not preserved
console.log(typeof memoized.hello); // undefined
```
If you feel strongly that `memoize-one` _should_ preserve function properties, please raise an issue. This decision was made in order to keep `memoize-one` as light as possible.
For _now_, the `.length` property of a function is not preserved on the memoized function
```ts
import memoizeOne from 'memoize-one';
function add(a, b) {
return a + b;
}
console.log(add.length); // 2
const memoized = memoizeOne(add);
console.log(memoized.length); // 0
```
There is no (great) way to correctly set the `.length` property of the memoized function while also supporting ie11. Once we [remove ie11 support](https://github.com/alexreardon/memoize-one/issues/125) then we will set the `.length` property of the memoized function to match the original function
[→ discussion](https://github.com/alexreardon/memoize-one/pull/124).
## Memoized function `type`
The resulting function you get back from `memoize-one` has *almost* the same `type` as the function that you are memoizing
```ts
declare type MemoizedFn<TFunc extends (this: any, ...args: any[]) => any> = {
clear: () => void;
(this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>): ReturnType<TFunc>;
};
```
- the same call signature as the function being memoized
- a `.clear()` function property added
- other function object properties on `TFunc` as not carried over
You are welcome to use the `MemoizedFn` generic directly from `memoize-one` if you like:
```ts
import memoize, { MemoizedFn } from 'memoize-one';
import isDeepEqual from 'lodash.isequal';
import { expectTypeOf } from 'expect-type';
// Takes any function: TFunc, and returns a Memoized<TFunc>
function withDeepEqual<TFunc extends (...args: any[]) => any>(fn: TFunc): MemoizedFn<TFunc> {
return memoize(fn, isDeepEqual);
}
function add(first: number, second: number): number {
return first + second;
}
const memoized = withDeepEqual(add);
expectTypeOf<typeof memoized>().toEqualTypeOf<MemoizedFn<typeof add>>();
```
In this specific example, this type would have been correctly inferred too
```ts
import memoize, { MemoizedFn } from 'memoize-one';
import isDeepEqual from 'lodash.isequal';
import { expectTypeOf } from 'expect-type';
// return type of MemoizedFn<TFunc> is inferred
function withDeepEqual<TFunc extends (...args: any[]) => any>(fn: TFunc) {
return memoize(fn, isDeepEqual);
}
function add(first: number, second: number): number {
return first + second;
}
const memoized = withDeepEqual(add);
// type test still passes
expectTypeOf<typeof memoized>().toEqualTypeOf<MemoizedFn<typeof add>>();
```
## Performance 🚀
### Tiny
`memoize-one` is super lightweight at [![min](https://img.shields.io/bundlephobia/min/memoize-one.svg?label=)](https://www.npmjs.com/package/memoize-one) minified and [![minzip](https://img.shields.io/bundlephobia/minzip/memoize-one.svg?label=)](https://www.npmjs.com/package/memoize-one) gzipped. (`1KB` = `1,024 Bytes`)
### Extremely fast
`memoize-one` performs better or on par with than other popular memoization libraries for the purpose of remembering the latest invocation.
The comparisons are not exhaustive and are primarily to show that `memoize-one` accomplishes remembering the latest invocation really fast. There is variability between runs. The benchmarks do not take into account the differences in feature sets, library sizes, parse time, and so on.
<details>
<summary>Expand for results</summary>
<p>
node version `16.11.1`
You can run this test in the repo by:
1. Add `"type": "module"` to the `package.json` (why is things so hard)
2. Run `yarn perf:library-comparison`
**no arguments**
| Position | Library | Operations per second |
| -------- | -------------------------------------------- | --------------------- |
| 1 | memoize-one | 80,112,981 |
| 2 | moize | 72,885,631 |
| 3 | memoizee | 35,550,009 |
| 4 | mem (JSON.stringify strategy) | 4,610,532 |
| 5 | lodash.memoize (JSON.stringify key resolver) | 3,708,945 |
| 6 | no memoization | 505 |
| 7 | fast-memoize | 504 |
**single primitive argument**
| Position | Library | Operations per second |
| -------- | -------------------------------------------- | --------------------- |
| 1 | fast-memoize | 45,482,711 |
| 2 | moize | 34,810,659 |
| 3 | memoize-one | 29,030,828 |
| 4 | memoizee | 23,467,065 |
| 5 | mem (JSON.stringify strategy) | 3,985,223 |
| 6 | lodash.memoize (JSON.stringify key resolver) | 3,369,297 |
| 7 | no memoization | 507 |
**single complex argument**
| Position | Library | Operations per second |
| -------- | -------------------------------------------- | --------------------- |
| 1 | moize | 27,660,856 |
| 2 | memoize-one | 22,407,916 |
| 3 | memoizee | 19,546,835 |
| 4 | mem (JSON.stringify strategy) | 2,068,038 |
| 5 | lodash.memoize (JSON.stringify key resolver) | 1,911,335 |
| 6 | fast-memoize | 1,633,855 |
| 7 | no memoization | 504 |
**multiple primitive arguments**
| Position | Library | Operations per second |
| -------- | -------------------------------------------- | --------------------- |
| 1 | moize | 22,366,497 |
| 2 | memoize-one | 17,241,995 |
| 3 | memoizee | 9,789,442 |
| 4 | mem (JSON.stringify strategy) | 3,065,328 |
| 5 | lodash.memoize (JSON.stringify key resolver) | 2,663,599 |
| 6 | fast-memoize | 1,219,548 |
| 7 | no memoization | 504 |
**multiple complex arguments**
| Position | Library | Operations per second |
| -------- | -------------------------------------------- | --------------------- |
| 1 | moize | 21,788,081 |
| 2 | memoize-one | 17,321,248 |
| 3 | memoizee | 9,595,420 |
| 4 | lodash.memoize (JSON.stringify key resolver) | 873,283 |
| 5 | mem (JSON.stringify strategy) | 850,779 |
| 6 | fast-memoize | 687,863 |
| 7 | no memoization | 504 |
**multiple complex arguments (spreading arguments)**
| Position | Library | Operations per second |
| -------- | -------------------------------------------- | --------------------- |
| 1 | moize | 21,701,537 |
| 2 | memoizee | 19,463,942 |
| 3 | memoize-one | 17,027,544 |
| 4 | lodash.memoize (JSON.stringify key resolver) | 887,816 |
| 5 | mem (JSON.stringify strategy) | 849,244 |
| 6 | fast-memoize | 691,512 |
| 7 | no memoization | 504 |
</p>
</details>
## Code health 👍
- Tested with all built in [JavaScript types](https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/types%20%26%20grammar/ch1.md)
- Written in `Typescript`
- Correct typing for `Typescript` and `flow` type systems
- No dependencies
@@ -0,0 +1 @@
export default function areInputsEqual(newInputs: readonly unknown[], lastInputs: readonly unknown[]): boolean;
@@ -0,0 +1,53 @@
'use strict';
var safeIsNaN = Number.isNaN ||
function ponyfill(value) {
return typeof value === 'number' && value !== value;
};
function isEqual(first, second) {
if (first === second) {
return true;
}
if (safeIsNaN(first) && safeIsNaN(second)) {
return true;
}
return false;
}
function areInputsEqual(newInputs, lastInputs) {
if (newInputs.length !== lastInputs.length) {
return false;
}
for (var i = 0; i < newInputs.length; i++) {
if (!isEqual(newInputs[i], lastInputs[i])) {
return false;
}
}
return true;
}
function memoizeOne(resultFn, isEqual) {
if (isEqual === void 0) { isEqual = areInputsEqual; }
var cache = null;
function memoized() {
var newArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
newArgs[_i] = arguments[_i];
}
if (cache && cache.lastThis === this && isEqual(newArgs, cache.lastArgs)) {
return cache.lastResult;
}
var lastResult = resultFn.apply(this, newArgs);
cache = {
lastResult: lastResult,
lastArgs: newArgs,
lastThis: this,
};
return lastResult;
}
memoized.clear = function clear() {
cache = null;
};
return memoized;
}
module.exports = memoizeOne;
@@ -0,0 +1,11 @@
// @flow
// These types are not as powerful as the TypeScript types, but they get the job done
export type EqualityFn = (newArgs: mixed[], lastArgs: mixed[]) => boolean;
// default export
declare export default function memoizeOne<ResultFn: (...any[]) => mixed>(
fn: ResultFn,
isEqual?: EqualityFn,
): ResultFn & { clear: () => void };
@@ -0,0 +1,7 @@
export declare type EqualityFn<TFunc extends (...args: any[]) => any> = (newArgs: Parameters<TFunc>, lastArgs: Parameters<TFunc>) => boolean;
export declare type MemoizedFn<TFunc extends (this: any, ...args: any[]) => any> = {
clear: () => void;
(this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>): ReturnType<TFunc>;
};
declare function memoizeOne<TFunc extends (this: any, ...newArgs: any[]) => any>(resultFn: TFunc, isEqual?: EqualityFn<TFunc>): MemoizedFn<TFunc>;
export default memoizeOne;
@@ -0,0 +1,51 @@
var safeIsNaN = Number.isNaN ||
function ponyfill(value) {
return typeof value === 'number' && value !== value;
};
function isEqual(first, second) {
if (first === second) {
return true;
}
if (safeIsNaN(first) && safeIsNaN(second)) {
return true;
}
return false;
}
function areInputsEqual(newInputs, lastInputs) {
if (newInputs.length !== lastInputs.length) {
return false;
}
for (var i = 0; i < newInputs.length; i++) {
if (!isEqual(newInputs[i], lastInputs[i])) {
return false;
}
}
return true;
}
function memoizeOne(resultFn, isEqual) {
if (isEqual === void 0) { isEqual = areInputsEqual; }
var cache = null;
function memoized() {
var newArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
newArgs[_i] = arguments[_i];
}
if (cache && cache.lastThis === this && isEqual(newArgs, cache.lastArgs)) {
return cache.lastResult;
}
var lastResult = resultFn.apply(this, newArgs);
cache = {
lastResult: lastResult,
lastArgs: newArgs,
lastThis: this,
};
return lastResult;
}
memoized.clear = function clear() {
cache = null;
};
return memoized;
}
export { memoizeOne as default };
@@ -0,0 +1,59 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.memoizeOne = factory());
})(this, (function () { 'use strict';
var safeIsNaN = Number.isNaN ||
function ponyfill(value) {
return typeof value === 'number' && value !== value;
};
function isEqual(first, second) {
if (first === second) {
return true;
}
if (safeIsNaN(first) && safeIsNaN(second)) {
return true;
}
return false;
}
function areInputsEqual(newInputs, lastInputs) {
if (newInputs.length !== lastInputs.length) {
return false;
}
for (var i = 0; i < newInputs.length; i++) {
if (!isEqual(newInputs[i], lastInputs[i])) {
return false;
}
}
return true;
}
function memoizeOne(resultFn, isEqual) {
if (isEqual === void 0) { isEqual = areInputsEqual; }
var cache = null;
function memoized() {
var newArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
newArgs[_i] = arguments[_i];
}
if (cache && cache.lastThis === this && isEqual(newArgs, cache.lastArgs)) {
return cache.lastResult;
}
var lastResult = resultFn.apply(this, newArgs);
cache = {
lastResult: lastResult,
lastArgs: newArgs,
lastThis: this,
};
return lastResult;
}
memoized.clear = function clear() {
cache = null;
};
return memoized;
}
return memoizeOne;
}));
@@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).memoizeOne=t()}(this,(function(){"use strict";var e=Number.isNaN||function(e){return"number"==typeof e&&e!=e};function t(t,n){if(t.length!==n.length)return!1;for(var r=0;r<t.length;r++)if(i=t[r],u=n[r],!(i===u||e(i)&&e(u)))return!1;var i,u;return!0}return function(e,n){void 0===n&&(n=t);var r=null;function i(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];if(r&&r.lastThis===this&&n(t,r.lastArgs))return r.lastResult;var u=e.apply(this,t);return r={lastResult:u,lastArgs:t,lastThis:this},u}return i.clear=function(){r=null},i}}));
@@ -0,0 +1,102 @@
{
"name": "memoize-one",
"version": "6.0.0",
"description": "A memoization library which only remembers the latest invocation",
"main": "dist/memoize-one.cjs.js",
"types": "dist/memoize-one.d.ts",
"module": "dist/memoize-one.esm.js",
"sideEffects": false,
"author": "Alex Reardon <alexreardon@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/alexreardon/memoize-one.git"
},
"files": [
"/dist",
"/src"
],
"size-limit": [
{
"path": "dist/memoize-one.min.js",
"limit": "234B"
},
{
"path": "dist/memoize-one.js",
"limit": "234B"
},
{
"path": "dist/memoize-one.cjs.js",
"limit": "230B"
},
{
"path": "dist/memoize-one.esm.js",
"limit": "246B"
}
],
"keywords": [
"memoize",
"memoization",
"cache",
"performance"
],
"dependencies": {},
"devDependencies": {
"@size-limit/preset-small-lib": "^5.0.4",
"@types/benchmark": "^2.1.1",
"@types/jest": "^27.0.2",
"@types/lodash.isequal": "^4.5.5",
"@types/lodash.memoize": "^4.1.6",
"@types/node": "^16.10.1",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"benchmark": "^2.1.4",
"cross-env": "^7.0.3",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.4.2",
"eslint-plugin-prettier": "^4.0.0",
"expect-type": "^0.12.0",
"fast-memoize": "^2.5.2",
"jest": "^27.2.2",
"lodash.isequal": "^4.5.0",
"lodash.memoize": "^4.1.2",
"markdown-table": "^3.0.1",
"mem": "^9.0.1",
"memoizee": "^0.4.15",
"moize": "^6.1.0",
"nanocolors": "^0.2.9",
"ora": "^6.0.1",
"prettier": "2.4.1",
"rimraf": "3.0.2",
"rollup": "^2.57.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript": "^1.0.1",
"size-limit": "^5.0.4",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
},
"config": {
"prettier_target": "src/**/*.{ts,js,jsx,md,json} test/**/*.{ts,js,jsx,md,json}"
},
"scripts": {
"validate": "yarn prettier:check && yarn eslint:check && yarn typescript:check",
"test": "yarn jest",
"test:size": "yarn build && yarn size-limit",
"typescript:check": "yarn tsc --noEmit",
"prettier:check": "yarn prettier --debug-check $npm_package_config_prettier_target",
"prettier:write": "yarn prettier --write $npm_package_config_prettier_target",
"eslint:check": "eslint $npm_package_config_prettier_target",
"build": "yarn build:clean && yarn build:dist && yarn build:typescript && yarn build:flow",
"build:clean": "yarn rimraf dist",
"build:dist": "yarn rollup -c",
"build:typescript": "yarn tsc ./src/memoize-one.ts --emitDeclarationOnly --declaration --outDir ./dist",
"build:flow": "cp src/memoize-one.js.flow dist/memoize-one.cjs.js.flow",
"perf": "yarn ts-node ./benchmarks/shallow-equal.ts",
"perf:library-comparison": "yarn build && node ./benchmarks/library-comparison.js",
"prepublishOnly": "yarn build"
}
}
@@ -0,0 +1,41 @@
// Number.isNaN as it is not supported in IE11 so conditionally using ponyfill
// Using Number.isNaN where possible as it is ~10% faster
const safeIsNaN =
Number.isNaN ||
function ponyfill(value: unknown): boolean {
// // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#polyfill
// NaN is the only value in JavaScript which is not equal to itself.
return typeof value === 'number' && value !== value;
};
function isEqual(first: unknown, second: unknown): boolean {
if (first === second) {
return true;
}
// Special case for NaN (NaN !== NaN)
if (safeIsNaN(first) && safeIsNaN(second)) {
return true;
}
return false;
}
export default function areInputsEqual(
newInputs: readonly unknown[],
lastInputs: readonly unknown[],
): boolean {
// no checks needed if the inputs length has changed
if (newInputs.length !== lastInputs.length) {
return false;
}
// Using for loop for speed. It generally performs better than array.every
// https://github.com/alexreardon/memoize-one/pull/59
for (let i = 0; i < newInputs.length; i++) {
if (!isEqual(newInputs[i], lastInputs[i])) {
return false;
}
}
return true;
}
@@ -0,0 +1,11 @@
// @flow
// These types are not as powerful as the TypeScript types, but they get the job done
export type EqualityFn = (newArgs: mixed[], lastArgs: mixed[]) => boolean;
// default export
declare export default function memoizeOne<ResultFn: (...any[]) => mixed>(
fn: ResultFn,
isEqual?: EqualityFn,
): ResultFn & { clear: () => void };
@@ -0,0 +1,56 @@
import areInputsEqual from './are-inputs-equal';
export type EqualityFn<TFunc extends (...args: any[]) => any> = (
newArgs: Parameters<TFunc>,
lastArgs: Parameters<TFunc>,
) => boolean;
export type MemoizedFn<TFunc extends (this: any, ...args: any[]) => any> = {
clear: () => void;
(this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>): ReturnType<TFunc>;
};
// internal type
type Cache<TFunc extends (this: any, ...args: any[]) => any> = {
lastThis: ThisParameterType<TFunc>;
lastArgs: Parameters<TFunc>;
lastResult: ReturnType<TFunc>;
};
function memoizeOne<TFunc extends (this: any, ...newArgs: any[]) => any>(
resultFn: TFunc,
isEqual: EqualityFn<TFunc> = areInputsEqual,
): MemoizedFn<TFunc> {
let cache: Cache<TFunc> | null = null;
// breaking cache when context (this) or arguments change
function memoized(
this: ThisParameterType<TFunc>,
...newArgs: Parameters<TFunc>
): ReturnType<TFunc> {
if (cache && cache.lastThis === this && isEqual(newArgs, cache.lastArgs)) {
return cache.lastResult;
}
// Throwing during an assignment aborts the assignment: https://codepen.io/alexreardon/pen/RYKoaz
// Doing the lastResult assignment first so that if it throws
// the cache will not be overwritten
const lastResult = resultFn.apply(this, newArgs);
cache = {
lastResult,
lastArgs: newArgs,
lastThis: this,
};
return lastResult;
}
// Adding the ability to clear the cache of a memoized function
memoized.clear = function clear() {
cache = null;
};
return memoized;
}
export default memoizeOne;