{"xo":[{"rules":{"@typescript-eslint/no-redundant-type-constituents":"off"}},{"files":["test.ts","test-d/**"],"rules":{"@typescript-eslint/no-unsafe-call":"off","@typescript-eslint/no-unsafe-return":"off","@typescript-eslint/no-unsafe-assignment":"off","@typescript-eslint/no-unsafe-member-access":"off"}},{"files":["package.json"]}],"_id":"p-memoize@9.0.0","bugs":{"url":"https://github.com/sindresorhus/p-memoize/issues"},"dist":{"shasum":"4c039cf7a7081504460ca662c6e7b87e5de4178c","tarball":"http://registry-npm.ywwl.com/p-memoize/download/p-memoize-9.0.0.tgz","fileCount":5,"integrity":"sha512-CrDWMfDzkLVDM9qmPibiClRWbWbbLnQ7gfrvpY0F83az9zpZxtegV4SZvkYj0EeutirIK61YXLsIldlkGHORwA==","signatures":[{"sig":"MEQCIDocZwItHqzhb08GdVwG/jKN6NQeZOuddbALHy+Lh4X6AiAezQncNwL3HIllTN/Kuzw2Jq/ZqKh3gfQxYcUg/65bGA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEpvEUuAbc/OdVuZ6Bsuz0bAkNwAHvA8RBqTipTl9A0/AiAC8J76J+bsOOS3J1/a+1gjkk6Qz8eOrq70Or+wCKFk/A=="}],"unpackedSize":35069,"size":9780,"noattachment":false,"key":"/p-memoize/-/p-memoize-9.0.0.tgz"},"name":"p-memoize","type":"module","author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"engines":{"node":">=22"},"exports":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"funding":"https://github.com/sindresorhus/p-memoize?sponsor=1","gitHead":"49be452fa90183f04d7225b0f46ddd25a915febf","license":"MIT","scripts":{"test":"xo && node --import=tsimp/import --test test.ts && npm run build && nz","build":"del-cli dist && tsc","prepack":"npm run build"},"version":"9.0.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"homepage":"https://github.com/sindresorhus/p-memoize#readme","keywords":["promise","memoize","mem","memoization","function","cache","caching","optimize","performance","ttl","expire","async","await","promises","time","out","cancel","bluebird"],"repository":{"url":"git+https://github.com/sindresorhus/p-memoize.git","type":"git"},"_npmVersion":"12.2.0","description":"Memoize promise-returning & async functions","directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"},{"name":"fregante","email":"opensource@bfred.it"}],"sideEffects":false,"_nodeVersion":"26.11.1","dependencies":{"mimic-function":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"nz":"^0.1.0","xo":"^5.0.1","tsimp":"^2.0.12","del-cli":"^7.0.0","p-defer":"^4.0.1","p-state":"^3.0.0","@typescript/native":"npm:typescript@^7.0.2","serialize-javascript":"^7.1.2","@sindresorhus/tsconfig":"^8.1.0","@types/serialize-javascript":"^5.0.4"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/p-memoize_9.0.0_1792068086189_0.9236097184508565"},"readme":"# p-memoize\n\n> [Memoize](https://en.wikipedia.org/wiki/Memoization) promise-returning & async functions\n\nUseful for speeding up consecutive function calls by caching the result of calls with identical input.\n\n<!-- Please keep this section in sync with https://github.com/sindresorhus/memoize/blob/main/readme.md -->\n\nBy default, **only the memoized function's first argument is considered** via strict equality comparison. If you need to cache multiple arguments or cache `object`s *by value*, have a look at alternative [caching strategies](#caching-strategy) below.\n\nThis package is similar to [memoize](https://github.com/sindresorhus/memoize) but with async-specific enhancements; in particular, it allows for asynchronous caches and does not cache rejected promises.\n\n## Install\n\n```sh\nnpm install p-memoize\n```\n\n## Usage\n\n```js\nimport pMemoize from 'p-memoize';\nimport got from 'got';\n\nconst memoizedGot = pMemoize(got);\n\nawait memoizedGot('https://sindresorhus.com');\n\n// This call is cached\nawait memoizedGot('https://sindresorhus.com');\n```\n\n### Caching strategy\n\nSimilar to the [caching strategy for `memoize`](https://github.com/sindresorhus/memoize#options) with the following exceptions:\n\n- Promises returned from a memoized function are locally cached until resolving, when their value is added to `cache`. Special properties assigned to a returned promise will not be kept after resolution and every promise may need to resolve with a serializable object if caching results in a database.\n- Whatever the function resolves to is cached as it is, so a one-shot value (an async generator, a `Readable`) is handed to every later caller already consumed.\n- Concurrent calls with the same key share one execution, so neither the function nor its `shouldCache` predicate may await a nested call for that same key. The nested call joins the one already running, which is waiting on it, and neither ever settles.\n- `.get()`, `.has()` and `.set()` methods on `cache` can run asynchronously by returning a promise.\n- Instead of `.set()` being provided an object with the properties `value` and `maxAge`, it will only be provided `value` as the first argument. If you want to implement time-based expiry, consider [doing so in `cache`](#time-based-cache-expiration).\n\n## API\n\n### pMemoize(fn, options?)\n\nReturns a memoized version of the given function.\n\nFor an overloaded function, the option types come from one of its overloads, because `ReturnType` resolves a type with several call signatures to a single one. Pass both type arguments to `pMemoize` when that matters.\n\n#### fn\n\nType: `Function`\n\nPromise-returning or async function to be memoized.\n\n#### options\n\nType: `object`\n\n##### cacheKey\n\nType: `Function`\\\nDefault: `arguments_ => arguments_[0]`\\\nExample: `arguments_ => JSON.stringify(arguments_)`\n\nDetermines the cache key for storing the result based on the function arguments. By default, **only the first argument is considered** and it is compared by strict equality, so two objects only share an entry when they are the same one.\n\nA `cacheKey` function can return any type supported by `Map` (or whatever structure you use in the `cache` option).\n\n- A call with no arguments has an undefined first argument, so it shares an entry with a call passing `undefined` explicitly. Pass a `cacheKey` that also looks at the argument count to tell them apart.\n- A `cacheKey` that returns a promise is rejected by the type: a promise is a fresh object on every call, so every key would be unique and nothing would ever be memoized.\n- The receiver (`this`) is not part of the key, and `cacheKey` cannot see it. See [the receiver is not part of the cache key](#the-receiver-is-not-part-of-the-cache-key).\n\nSee the [caching strategy](#caching-strategy) section for more information.\n\n##### cache\n\nType: `object | false`\\\nDefault: `new Map()`\n\nUse a different cache storage. Must implement the following methods: `.has(key)`, `.get(key)`, and `.set(key, value)`, and optionally `.clear()`. You could for example use a `WeakMap` instead or [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache. To disable caching so that only concurrent executions resolve with the same value, pass `false`.\n\n- `.has()` decides whether there is a hit, and `.get()` is only called on a hit, to supply the value. If the two disagree, for example because the entry is evicted in between, the call resolves to `undefined` without running the function.\n- Its key type must be the one `cacheKey` produces, which by default is the first argument's type. TypeScript cannot always check this, so a cache keyed by something else may only fail at runtime, depending on the cache.\n- A cache with no `.clear()` cannot be emptied by [`pMemoizeClear()`](#pmemoizeclearmemoized), and a `WeakMap` has none.\n\nSee the [caching strategy](https://github.com/sindresorhus/mem#caching-strategy) section in the `mem` package for more information.\n\n##### shouldCache\n\nType: `(value, {key, argumentsList}) => boolean | Promise<boolean>`\n\nControls whether a fulfilled value should be written to the cache.\n\nIt runs after the function fulfills and before `cache.set`.\n\n- Omit to keep current behavior (always write).\n- Return `false` to skip writing to the cache (in-flight de-duplication is still cleared).\n- Throw or reject to propagate the error and skip caching. The predicate does not run at all when caching is disabled with `cache: false`.\n\n```js\nimport pMemoize from 'p-memoize';\n\n// Only cache defined values\nconst getMaybe = pMemoize(async key => db.get(key), {\n\tshouldCache: value => value !== undefined,\n});\n\n// Only cache non-empty arrays\nconst search = pMemoize(async query => fetchResults(query), {\n\tshouldCache: value => Array.isArray(value) && value.length > 0,\n});\n```\n\nNote: Affects only writes; reads from the cache are unchanged.\n\n#### The receiver is not part of the cache key\n\n> [!WARNING]\n> A method memoized on a prototype shares one cache between every instance, so it returns whichever instance's result was cached first.\n\nThe cache key is derived from the arguments only. The receiver (`this`) never reaches `cacheKey`, so there is no way to include it:\n\n```js\nclass Repository {\n\tname = '';\n\tasync lookup(key) {\n\t\treturn `${this.name}:${key}`;\n\t}\n}\n\n// `beta.lookup('k')` returns the value cached by `alpha.lookup('k')`.\nRepository.prototype.lookup = pMemoize(Repository.prototype.lookup);\n```\n\nThe same applies to `pMemoizeDecorator()` when you pass a `cache` of your own, since the same cache instance is handed to every instance. A method that depends on the instance needs a per-instance cache, which is what `pMemoizeDecorator()` gives you when you do not pass one:\n\n```js\nclass Repository {\n\tname = '';\n\n\t// Each instance gets its own cache.\n\t@pMemoizeDecorator()\n\tasync lookup(key) {\n\t\treturn `${this.name}:${key}`;\n\t}\n}\n```\n\n### pMemoizeDecorator(options)\n\nReturns a decorator to memoize class methods (instance and static).\n\nNotes:\n\n- Only class methods are supported; regular functions are not part of the decorators proposals.\n- Requires the new ECMAScript decorators (TypeScript 5.0+). Legacy `experimentalDecorators` are not supported.\n- Babel’s legacy decorators are not supported as they implement a different proposal variant.\n- Private methods are not supported.\n- Put `@pMemoizeDecorator()` first (topmost) when you combine it with other method decorators. Decorators are applied from the bottom up, so a decorator listed above it replaces the method after it, and the memoized copy is then skipped so that it does not hide that replacement. This happens silently.\n- A subclass that overrides the method is not memoized for it, and a `super.method()` call from the override reaches the original, unmemoized method.\n\n#### options\n\nType: `object`\n\nSame as options for `pMemoize()`.\n\n```ts\nimport {pMemoizeDecorator} from 'p-memoize';\n\nclass Example {\n\tindex = 0\n\n\t@pMemoizeDecorator()\n\tasync counter() {\n\t\treturn ++this.index;\n\t}\n}\n\nclass ExampleWithOptions {\n\tindex = 0\n\n\t// Only cache positive results.\n\t@pMemoizeDecorator({shouldCache: value => value > 0})\n\tasync counter() {\n\t\treturn ++this.index;\n\t}\n}\n```\n\nThe decorator memoizes per-instance for an instance method, and per-class for a static one. With no `cache` of your own, you can clear an instance method's cache using `pMemoizeClear(instance.method)`. With one, the cache is shared, so that call empties it for every instance of the class.\n\n### pMemoizeClear(memoized)\n\nClear all cached data of a memoized function.\n\nWhat the clear reaches depends on what it is clearing:\n\n- The cache is emptied for every memoized function sharing it, and a call still running on any of them will not write its result back into it.\n- Only the in-flight calls of the function you called it on are dropped, so a later call on it starts fresh rather than joining one that began before the clear. Another memoized function over the same cache keeps sharing its own in-flight calls until they settle.\n\nA `cache.set()` that has already started when you clear is not undone, so that value can still land in the cleared cache.\n\nThis function is synchronous: a `clear()` that returns a promise finishes after it returns, and a rejection from it is dropped rather than reported, since there is nothing to return it through. A `clear()` that throws synchronously still propagates to the caller.\n\nIt throws when given something that was not memoized, when the memoized function has caching disabled, or when its cache cannot be cleared.\n\n## Tips\n\n### Time-based cache expiration\n\n```js\nimport pMemoize from 'p-memoize';\nimport ExpiryMap from 'expiry-map';\nimport got from 'got';\n\nconst cache = new ExpiryMap(10000); // Cached values expire after 10 seconds\n\nconst memoizedGot = pMemoize(got, {cache});\n```\n\n### Caching promise rejections\n\n```js\nimport pMemoize from 'p-memoize';\nimport pReflect from 'p-reflect';\n\nconst memoizedGot = pMemoize(async (url, options) => pReflect(got(url, options)));\n\nawait memoizedGot('https://example.com');\n// {isFulfilled: true, isRejected: false, value: '...'}\n```\n\n## Related\n\n- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions\n- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions\n- [More…](https://github.com/sindresorhus/promise-fun)\n","publish_time":1792068086282,"_cnpm_publish_time":1792068086282,"dist-tags":{"latest":"9.0.0","version4":"4.0.4"}}