hexo/node_modules/moize/dist/moize.esm.js.map

1 line
88 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
{"version":3,"file":"moize.esm.js","sources":["../src/constants.ts","../src/utils.ts","../src/maxAge.ts","../src/stats.ts","../src/instance.ts","../src/component.ts","../src/maxArgs.ts","../src/serialize.ts","../src/options.ts","../src/updateCacheForKey.ts","../src/index.ts"],"sourcesContent":["import type { AnyFn, Options } from '../index.d';\n\n/**\n * @private\n *\n * @constant DEFAULT_OPTIONS\n */\nexport const DEFAULT_OPTIONS: Options<AnyFn> = {\n isDeepEqual: false,\n isPromise: false,\n isReact: false,\n isSerialized: false,\n isShallowEqual: false,\n matchesArg: undefined,\n matchesKey: undefined,\n maxAge: undefined,\n maxArgs: undefined,\n maxSize: 1,\n onExpire: undefined,\n profileName: undefined,\n serializer: undefined,\n updateCacheForKey: undefined,\n transformArgs: undefined,\n updateExpire: false,\n};\n","import { DEFAULT_OPTIONS } from './constants';\n\nimport type {\n AnyFn,\n Expiration,\n IsEqual,\n IsMatchingKey,\n Key,\n Moizeable,\n Moized,\n Options,\n} from '../index.d';\n\n/**\n * @private\n *\n * @description\n * method to combine functions and return a single function that fires them all\n *\n * @param functions the functions to compose\n * @returns the composed function\n */\nexport function combine<Args extends any[], Result>(\n ...functions: Array<(...args: Args) => any>\n): ((...args: Args) => Result) | undefined {\n return functions.reduce(function (f: any, g: any) {\n if (typeof f === 'function') {\n return typeof g === 'function'\n ? function (this: any) {\n f.apply(this, arguments);\n g.apply(this, arguments);\n }\n : f;\n }\n\n if (typeof g === 'function') {\n return g;\n }\n });\n}\n\n/**\n * @private\n *\n * @description\n * method to compose functions and return a single function\n *\n * @param functions the functions to compose\n * @returns the composed function\n */\nexport function compose<Method>(...functions: Method[]): Method {\n return functions.reduce(function (f: any, g: any) {\n if (typeof f === 'function') {\n return typeof g === 'function'\n ? function (this: any) {\n return f(g.apply(this, arguments));\n }\n : f;\n }\n\n if (typeof g === 'function') {\n return g;\n }\n });\n}\n\n/**\n * @private\n *\n * @description\n * find the index of the expiration based on the key\n *\n * @param expirations the list of expirations\n * @param key the key to match\n * @returns the index of the expiration\n */\nexport function findExpirationIndex(expirations: Expiration[], key: Key) {\n for (let index = 0; index < expirations.length; index++) {\n if (expirations[index].key === key) {\n return index;\n }\n }\n\n return -1;\n}\n\n/**\n * @private\n *\n * @description\n * create function that finds the index of the key in the list of cache keys\n *\n * @param isEqual the function to test individual argument equality\n * @param isMatchingKey the function to test full key equality\n * @returns the function that finds the index of the key\n */\nexport function createFindKeyIndex(\n isEqual: IsEqual,\n isMatchingKey: IsMatchingKey | undefined\n) {\n const areKeysEqual: IsMatchingKey =\n typeof isMatchingKey === 'function'\n ? isMatchingKey\n : function (cacheKey: Key, key: Key) {\n for (let index = 0; index < key.length; index++) {\n if (!isEqual(cacheKey[index], key[index])) {\n return false;\n }\n }\n\n return true;\n };\n\n return function (keys: Key[], key: Key) {\n for (let keysIndex = 0; keysIndex < keys.length; keysIndex++) {\n if (\n keys[keysIndex].length === key.length &&\n areKeysEqual(keys