You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
89 KiB

2 years ago
{"version":3,"file":"moize.cjs.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 { Options } from './types';\n\n/**\n * @private\n *\n * @constant DEFAULT_OPTIONS\n */\nexport const DEFAULT_OPTIONS: Options = {\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';\nimport {\n Expiration,\n Fn,\n IsEqual,\n IsMatchingKey,\n Key,\n Moizeable,\n Moized,\n Options,\n} from './types';\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<Arg, Result>(\n ...functions: Fn<Arg>[]\n): Fn<Arg, 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[keysIndex], key)\n ) {\n return keysIndex;\n