{"_id":"@blumintinc/typescript-memoize","_rev":"5-e04fe92ba15dc604605fd726684df03b","name":"@blumintinc/typescript-memoize","dist-tags":{"latest":"1.4.0"},"versions":{"1.2.0":{"name":"@blumintinc/typescript-memoize","version":"1.2.0","keywords":["typescript","memoize","functional","decorator"],"author":{"name":"Joseph O'Connor"},"license":"MIT","_id":"@blumintinc/typescript-memoize@1.2.0","maintainers":[{"name":"oconnorjoseph","email":"oconnor.joseph@columbia.edu"},{"name":"brodie-m","email":"brodiedmcguire@gmail.com"}],"homepage":"https://github.com/BluMintInc/typescript-memoize#readme","bugs":{"url":"https://github.com/BluMintInc/typescript-memoize/issues"},"dist":{"shasum":"f8ec5283d4af0aa739cc70881e950bd34b4abe5e","tarball":"https://registry.npmjs.org/@blumintinc/typescript-memoize/-/typescript-memoize-1.2.0.tgz","fileCount":9,"integrity":"sha512-o+OMbVvxGvuvmrXT5aP4shtbxAWknsGym8I6MwrDwAiSnC3k637N/a24yFxb66r1p8W13gFHsE2uzSEN/KENjA==","signatures":[{"sig":"MEQCIC68Osn2I5Ou5mEx6HrjIV9MJ8wqcGbVe7TBB6dXxc4pAiAkIxxtVR3AbyT5nbAmntN9ACAYIQOkh/qXWnqg+GF9+g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":51961},"main":"./dist/memoize-decorator.js","module":"./dist/es2015/memoize-decorator.js","gitHead":"7cbfafde9089fa09681fda4b38d81cdf29310218","private":false,"scripts":{"test":"karma start test/karma.config.js --single-run","build":"tsc","clean":"rm -rf ./dist","eslint":"npm run tslint","tslint":"tslint --project .","prepublish":"npm run build && npm run build:es2015","build:es2015":"tsc --module es2015 --target es2015 --outDir dist/es2015"},"typings":"./dist/memoize-decorator.d.ts","_npmUser":{"name":"oconnorjoseph","email":"oconnor.joseph@columbia.edu"},"repository":{"url":"git+https://github.com/BluMintInc/typescript-memoize.git","type":"git"},"_npmVersion":"10.9.2","description":"Memoize decorator for Typescript with deep equality","directories":{},"_nodeVersion":"22.13.0","dependencies":{"fast-deep-equal":"^3.1.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"karma":"6.3.16","tslib":"2.0.3","tslint":"6.1.3","es6-shim":"0.35.6","typescript":"4.1.2","@types/node":"14.14.9","jasmine-core":"3.6.0","karma-jasmine":"4.0.1","@types/jasmine":"3.6.2","karma-es6-shim":"1.0.0","karma-typescript":"5.2.0","source-map-loader":"1.1.2","karma-spec-reporter":"0.0.32","karma-junit-reporter":"2.0.1","karma-chrome-launcher":"3.1.0","karma-sourcemap-loader":"0.3.8","karma-threshold-reporter":"0.1.15","awesome-typescript-loader":"5.2.1","karma-jasmine-html-reporter":"1.5.4"},"_npmOperationalInternal":{"tmp":"tmp/typescript-memoize_1.2.0_1744850693816_0.7351540919054642","host":"s3://npm-registry-packages-npm-production"}},"1.3.0":{"name":"@blumintinc/typescript-memoize","version":"1.3.0","keywords":["typescript","memoize","functional","decorator"],"author":{"name":"Joseph O'Connor"},"license":"MIT","_id":"@blumintinc/typescript-memoize@1.3.0","maintainers":[{"name":"oconnorjoseph","email":"oconnor.joseph@columbia.edu"}],"homepage":"https://github.com/BluMintInc/typescript-memoize#readme","bugs":{"url":"https://github.com/BluMintInc/typescript-memoize/issues"},"dist":{"shasum":"69fdb3d7cf1925282ff5e9c911f9effb360f0cbf","tarball":"https://registry.npmjs.org/@blumintinc/typescript-memoize/-/typescript-memoize-1.3.0.tgz","fileCount":9,"integrity":"sha512-DFcTQo+1gqnySKKIJG+21yw5KYxL8STKGCQAzr4IwqHPFN6DB2jacjBj6BAleu1ly+hBptItNy2J4tO6n9ifqg==","signatures":[{"sig":"MEUCIQDBoOtsPkBZZX/1odqM06MY0pprqgWX77qBP0fiEtxv+wIgEWPSjVq+bGTORNvh37trihSGzMXOlrNOyGM856nP134=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50987},"main":"./dist/memoize-decorator.js","module":"./dist/es2015/memoize-decorator.js","gitHead":"e1bd81de74da046ec4f1eacff753a6a6d59c0f94","private":false,"scripts":{"test":"karma start test/karma.config.js --single-run","build":"tsc","clean":"rm -rf ./dist","eslint":"npm run tslint","tslint":"tslint --project .","prepublish":"npm run build && npm run build:es2015","build:es2015":"tsc --module es2015 --target es2015 --outDir dist/es2015"},"typings":"./dist/memoize-decorator.d.ts","_npmUser":{"name":"oconnorjoseph","email":"oconnor.joseph@columbia.edu"},"repository":{"url":"git+https://github.com/BluMintInc/typescript-memoize.git","type":"git"},"_npmVersion":"10.9.4","description":"Memoize decorator for Typescript with deep equality","directories":{},"_nodeVersion":"22.21.1","dependencies":{"@blumintinc/fast-deep-equal":"^4.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"karma":"6.3.16","tslib":"2.0.3","tslint":"6.1.3","es6-shim":"0.35.6","typescript":"4.1.2","@types/node":"14.14.9","jasmine-core":"3.6.0","karma-jasmine":"4.0.1","@types/jasmine":"3.6.2","karma-es6-shim":"1.0.0","karma-typescript":"5.5.4","source-map-loader":"1.1.2","karma-spec-reporter":"0.0.32","karma-junit-reporter":"2.0.1","karma-chrome-launcher":"3.1.0","karma-sourcemap-loader":"0.3.8","karma-threshold-reporter":"0.1.15","karma-jasmine-html-reporter":"1.5.4","karma-typescript-es6-transform":"^5.5.4"},"_npmOperationalInternal":{"tmp":"tmp/typescript-memoize_1.3.0_1767828569621_0.5364724649569697","host":"s3://npm-registry-packages-npm-production"}},"1.4.0":{"name":"@blumintinc/typescript-memoize","version":"1.4.0","keywords":["typescript","memoize","functional","decorator"],"author":{"name":"Joseph O'Connor"},"license":"MIT","_id":"@blumintinc/typescript-memoize@1.4.0","maintainers":[{"name":"oconnorjoseph","email":"oconnor.joseph@columbia.edu"}],"homepage":"https://github.com/BluMintInc/typescript-memoize#readme","bugs":{"url":"https://github.com/BluMintInc/typescript-memoize/issues"},"dist":{"shasum":"d9c4d56051c87da6bf2df9b7713695db15b36999","tarball":"https://registry.npmjs.org/@blumintinc/typescript-memoize/-/typescript-memoize-1.4.0.tgz","fileCount":9,"integrity":"sha512-FbZ7SLeEMGqSRkGRpBsij8mByehhvWsnxDO2gTKJHjFOJ7nK1OWUrdu+vFukBqR8VRwZDrNJRUjZ2hJy2rt8vQ==","signatures":[{"sig":"MEUCIQD8GJ6RCYoboaCs5du2OawASO3re3TyU2l0qNpPh0OzaQIgUVyNbUWzxNCHOzjTzhYQ2WQBs9DR95OlCPeHFhtG6Vs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":60147},"main":"./dist/memoize-decorator.js","module":"./dist/es2015/memoize-decorator.js","gitHead":"844c474e224376e8616d526f3571cb241b23688e","private":false,"scripts":{"test":"karma start test/karma.config.js --single-run","build":"tsc","clean":"rm -rf ./dist","eslint":"npm run tslint","tslint":"tslint --project .","prepublish":"npm run build && npm run build:es2015","build:es2015":"tsc --module es2015 --target es2015 --outDir dist/es2015"},"typings":"./dist/memoize-decorator.d.ts","_npmUser":{"name":"oconnorjoseph","email":"oconnor.joseph@columbia.edu"},"repository":{"url":"git+https://github.com/BluMintInc/typescript-memoize.git","type":"git"},"_npmVersion":"10.9.4","description":"Memoize decorator for Typescript with deep equality","directories":{},"_nodeVersion":"22.21.1","dependencies":{"@blumintinc/fast-deep-equal":"^4.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"karma":"6.3.16","tslib":"2.0.3","tslint":"6.1.3","es6-shim":"0.35.6","typescript":"4.1.2","@types/node":"14.14.9","jasmine-core":"3.6.0","karma-jasmine":"4.0.1","@types/jasmine":"3.6.2","karma-es6-shim":"1.0.0","karma-typescript":"5.5.4","source-map-loader":"1.1.2","karma-spec-reporter":"0.0.32","karma-junit-reporter":"2.0.1","karma-chrome-launcher":"3.1.0","karma-sourcemap-loader":"0.3.8","karma-threshold-reporter":"0.1.15","karma-jasmine-html-reporter":"1.5.4","karma-typescript-es6-transform":"^5.5.4"},"_npmOperationalInternal":{"tmp":"tmp/typescript-memoize_1.4.0_1771965329077_0.9575113557228805","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-04-17T00:44:53.730Z","modified":"2026-04-29T01:17:39.853Z","1.2.0":"2025-04-17T00:44:54.115Z","1.3.0":"2026-01-07T23:29:29.810Z","1.4.0":"2026-02-24T20:35:29.216Z"},"bugs":{"url":"https://github.com/BluMintInc/typescript-memoize/issues"},"author":{"name":"Joseph O'Connor"},"license":"MIT","homepage":"https://github.com/BluMintInc/typescript-memoize#readme","keywords":["typescript","memoize","functional","decorator"],"repository":{"url":"git+https://github.com/BluMintInc/typescript-memoize.git","type":"git"},"description":"Memoize decorator for Typescript with deep equality","maintainers":[{"email":"oconnor.joseph@columbia.edu","name":"oconnorjoseph"},{"email":"javier@blumint.io","name":"javier.blumint"}],"readme":"# typescript-memoize\n\n[![npm](https://img.shields.io/npm/v/typescript-memoize.svg)](https://www.npmjs.com/package/typescript-memoize)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/darrylhodgins/typescript-memoize/master/LICENSE)\n![Test](https://github.com/darrylhodgins/typescript-memoize/workflows/Test/badge.svg)\n\nA memoize decorator for Typescript.\n\n## Installation\n\n```\nnpm install --save typescript-memoize\n```\n\n## Usage:\n\n```typescript\n@Memoize(hashFunction?: (...args: any[]) => any)\n```\n\nYou can use it in several ways:\n\n* Memoize a `get` accessor,\n* Memoize a method which takes no parameters,\n* Memoize a method which varies based on its first parameter only,\n* Memoize a method which varies based on some combination of parameters\n* Memoize a method using objects with deep equality comparison (default)\n\nYou can call memoized methods *within* the same class, too.  This could be useful if you want to memoize the return value for an entire data set, and also a filtered or mapped version of that same set.\n\n## Memoize a `get` accessor, or a method which takes no parameters\n\nThese both work the same way. Subsequent calls to a memoized method without parameters, or to a `get` accessor, always return the same value.\n\nI generally consider it an anti-pattern for a call to a `get` accessor to trigger an expensive operation.  Simply adding `Memoize()` to a `get` allows for seamless lazy-loading.\n\n```typescript\nimport {Memoize,MemoizeExpiring} from 'typescript-memoize';\n\nclass SimpleFoo {\n\n    // Memoize a method without parameters\n    @Memoize()\n    public getAllTheData() {\n       // do some expensive operation to get data\n       return data;\n    }\n\n    // Memoize a method and expire the value after some time in milliseconds\n    @MemoizeExpiring(5000)\n    public getDataForSomeTime() {\n        // do some expensive operation to get data\n        return data;\n    }\n\n    // Memoize a getter\n    @Memoize()\n    public get someValue() {\n        // do some expensive operation to calculate value\n        return value;\n    }\n\n}\n```\n\nAnd then we call them from somewhere else in our code:\n\n```typescript\nlet simpleFoo = new SimpleFoo();\n\n// Memoizes a calculated value and returns it:\nlet methodVal1 = simpleFoo.getAllTheData();\n\n// Returns memoized value\nlet methodVal2 = simpleFoo.getAllTheData();\n\n// Memoizes (lazy-loads) a calculated value and returns it:\nlet getterVal1 = simpleFoo.someValue;\n\n// Returns memoized value\nlet getterVal2 = simpleFoo.someValue;\n\n```\n\n## Memoize a method which varies based on its first parameter only\n\nSubsequent calls to this style of memoized method will always return the same value.\n\nI'm not really sure why anyone would use this approach to memoize a method with *more* than one parameter, but it's possible.\n\n```typescript\nimport {Memoize} from 'typescript-memoize';\n\nclass ComplicatedFoo {\n\n\t// Memoize a method without parameters (just like the first example)\n\t@Memoize()\n\tpublic getAllTheData() {\n\t\t// do some expensive operation to get data\n\t\treturn data;\n\t}\n\n\t// Memoize a method with one parameter\n\t@Memoize()\n\tpublic getSomeOfTheData(id: number) {\n\t\tlet allTheData = this.getAllTheData(); // if you want to!\n\t\t// do some expensive operation to get data\n\t\treturn data;\n\t}\n\n\t// Memoize a method with multiple parameters\n\t// Only the first parameter will be used for memoization\n\t@Memoize()\n\tpublic getGreeting(name: string, planet: string) {\n\t\treturn 'Hello, ' + name + '! Welcome to ' + planet;\n\t}\n\n}\n```\n\nWe call these methods from somewhere else in our code:\n\n```typescript\nlet complicatedFoo = new ComplicatedFoo();\n\n// Returns calculated value and memoizes it:\nlet oneParam1 = complicatedFoo.getSomeOfTheData();\n\n// Returns memoized value\nlet oneParam2 = complicatedFoo.getSomeOfTheData();\n\n// Memoizes a calculated value and returns it:\n// 'Hello, Darryl! Welcome to Earth'\nlet greeterVal1 = complicatedFoo.getGreeting('Darryl', 'Earth');\n\n// Ignores the second parameter, and returns memoized value\n// 'Hello, Darryl! Welcome to Earth'\nlet greeterVal2 = complicatedFoo.getGreeting('Darryl', 'Mars');\n```\n\n## Memoize a method which varies based on some combination of parameters\n\nPass in a `hashFunction` which takes the same parameters as your target method, to memoize values based on all parameters, or some other custom logic\n\n```typescript\nimport {Memoize} from 'typescript-memoize';\n\nclass MoreComplicatedFoo {\n\n\t// Memoize a method with multiple parameters\n\t// Memoize will remember values based on keys like: 'name;planet'\n\t@Memoize((name: string, planet: string) => {\n\t\treturn name + ';' + planet;\n\t})\n\tpublic getBetterGreeting(name: string, planet: string) {\n\t\treturn 'Hello, ' + name + '! Welcome to ' + planet;\n\t}\n\t\n\t// Memoize based on some other logic\n\t@Memoize(() => {\n\t\treturn new Date();\n\t})\n\tpublic memoryLeak(greeting: string) {\n\t\treturn greeting + '!!!!!';\n\t}\n\n\t// Memoize also accepts parameters via a single object argument\n\t@Memoize({\n\t\texpiring: 10000, // milliseconds\n\t\thashFunction: (name: string, planet: string) => {\n\t\t\treturn name + ';' + planet;\n\t\t}\n\t})\n\tpublic getSameBetterGreeting(name: string, planet: string) {\n\t\treturn 'Hello, ' + name + '! Welcome to ' + planet;\n\t}\n\n}\n```\n\nWe call these methods from somewhere else in our code.  By now you should be getting the idea:\n\n```typescript\nlet moreComplicatedFoo = new MoreComplicatedFoo();\n\n// 'Hello, Darryl! Welcome to Earth'\nlet greeterVal1 = moreComplicatedFoo.getBetterGreeting('Darryl', 'Earth');\n\n// 'Hello, Darryl! Welcome to Mars'\nlet greeterVal2 = moreComplicatedFoo.getBetterGreeting('Darryl', 'Mars');\n\n// Fill up the computer with useless greetings:\nlet greeting = moreComplicatedFoo.memoryLeak('Hello');\n\n```\n\n## Memoize accepts one or more \"tag\" strings that allow the cache to be invalidated on command\n\nPassing an array with one or more \"tag\" strings these will allow you to later clear the cache of results associated with methods or the `get`accessors using the `clear()` function.\n\nThe `clear()` function also requires an array of \"tag\" strings.\n\n```typescript\nimport {Memoize} from 'typescript-memoize';\n\nclass ClearableFoo {\n\n\t// Memoize accepts tags\n\t@Memoize({ tags: [\"foo\", \"bar\"] })\n\tpublic getClearableGreeting(name: string, planet: string) {\n\t\treturn 'Hello, ' + name + '! Welcome to ' + planet;\n\t}\n\n\n\t// Memoize accepts tags\n\t@Memoize({ tags: [\"bar\"] })\n\tpublic getClearableSum(a: number, b: number) {\n\t\treturn a + b;\n\t}\n\n}\n```\n\nWe call these methods from somewhere else in our code.\n\n```typescript\nimport {clear} from 'typescript-memoize';\n\nlet clearableFoo = new ClearableFoo();\n\n// 'Hello, Darryl! Welcome to Earth'\nlet greeterVal1 = clearableFoo.getClearableGreeting('Darryl', 'Earth');\n\n// Ignores the second parameter, and returns memoized value\n// 'Hello, Darryl! Welcome to Earth'\nlet greeterVal2 = clearableFoo.getClearableGreeting('Darryl', 'Mars');\n\n// '3'\nlet sum1 = clearableFoo.getClearableSum(2, 1);\n\n// Ignores the second parameter, and returns memoized value\n// '3'\nlet sum2 = clearableFoo.getClearableSum(2, 2);\n\nclear([\"foo\"]);\n\n// The memoized values are cleared, return a new value\n// 'Hello, Darryl! Welcome to Mars'\nlet greeterVal3 = clearableFoo.getClearableGreeting('Darryl', 'Mars');\n\n\n// The memoized value is not associated with 'foo' tag, returns memoized value\n// '3'\nlet sum3 = clearableFoo.getClearableSum(2, 2);\n\nclear([\"bar\"]);\n\n// The memoized values are cleared, return a new value\n// 'Hello, Darryl! Welcome to Earth'\nlet greeterVal4 = clearableFoo.getClearableGreeting('Darryl', 'Earth');\n\n\n// The memoized values are cleared, return a new value\n// '4'\nlet sum4 = clearableFoo.getClearableSum(2, 2);\n\n```\n\n## Memoize with deep equality comparison\n\nBy default, memoization now uses deep equality when comparing objects, which is useful for objects and arrays with the same structure but different references. If needed, you can disable deep equality with the `useDeepEqual: false` option:\n\n```typescript\nimport {Memoize} from 'typescript-memoize';\n\nclass DeepEqualityFoo {\n    // Uses deep equality comparison by default\n    @Memoize()\n    public processObject(obj: any) {\n        // This will only be called once for objects with the same structure,\n        // even if they are different instances\n        return expensiveOperation(obj);\n    }\n\n    // Disable deep equality if you want reference equality instead\n    @Memoize({\n        useDeepEqual: false\n    })\n    public processObjectWithReferenceEquality(obj: any) {\n        // This will be called for each new object reference,\n        // even if they have the same structure\n        return expensiveOperation(obj);\n    }\n\n    // Combine with other options\n    @Memoize({\n        expiring: 5000, // expire after 5 seconds\n        tags: [\"objects\"]\n    })\n    public processComplexObject(obj: any) {\n        return expensiveOperation(obj);\n    }\n}\n```\n\nWe can call these methods and get memoized results based on deep equality:\n\n```typescript\nlet deepFoo = new DeepEqualityFoo();\n\n// First call with an object\nconst result1 = deepFoo.processObject({ id: 123, name: \"Test\" });\n\n// Second call with different object instance but same structure\n// Will return the memoized result without calling the original method again\nconst result2 = deepFoo.processObject({ id: 123, name: \"Test\" });\n\n// Call with different object structure\n// Will call the original method again\nconst result3 = deepFoo.processObject({ id: 456, name: \"Different\" });\n\n// Deep equality works with complex nested objects too\nconst result4 = deepFoo.processComplexObject({ \n    user: { \n        id: 123, \n        details: { \n            age: 30, \n            preferences: [\"red\", \"blue\"] \n        } \n    }\n});\n\n// Using reference equality will call the method for each new object\nconst refObj = { id: 123, name: \"Test\" };\nconst result5 = deepFoo.processObjectWithReferenceEquality(refObj);\n// This will be memoized since it's the same reference\nconst result6 = deepFoo.processObjectWithReferenceEquality(refObj);\n// This will call the method again since it's a new reference\nconst result7 = deepFoo.processObjectWithReferenceEquality({ id: 123, name: \"Test\" });\n```\n\nThe deep equality comparison uses the [fast-deep-equal](https://www.npmjs.com/package/fast-deep-equal) package for efficient deep equality comparisons.\n","readmeFilename":"README.md"}