memoize-fs
Advanced tools
Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "memoize-fs", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"private": false, | ||
@@ -30,3 +30,3 @@ "type": "module", | ||
"lint": "eslint .", | ||
"test": "npm run lint && npm run coverage", | ||
"test": "npm run lint && tsc --noEmit && npm run coverage", | ||
"open-coverage": "open coverage/lcov-report/index.ts.html", | ||
@@ -53,21 +53,21 @@ "publish-coverage": "npm run coverage && coveralls < coverage/lcov.info", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.2", | ||
"@rollup/plugin-typescript": "^10.0.1", | ||
"@types/node": "^18.11.11", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"@types/node": "^20.1.0", | ||
"@types/serialize-javascript": "^5.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.45.1", | ||
"@typescript-eslint/parser": "^5.45.1", | ||
"@vitest/coverage-c8": "^0.28.4", | ||
"@typescript-eslint/eslint-plugin": "^7.0.1", | ||
"@typescript-eslint/parser": "^7.0.1", | ||
"@vitest/coverage-v8": "^1.0.4", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.29.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"open-cli": "^7.1.0", | ||
"prettier": "^2.8.1", | ||
"rollup": "^3.17.1", | ||
"open-cli": "^8.0.0", | ||
"prettier": "^3.0.0", | ||
"rollup": "^4.0.2", | ||
"serialize-javascript": "^6.0.0", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.5.0", | ||
"typescript": "^4.9.5", | ||
"vitest": "^0.28.4" | ||
"typescript": "^5.0.4", | ||
"vitest": "^1.0.4" | ||
}, | ||
@@ -74,0 +74,0 @@ "license": "MIT", |
@@ -7,3 +7,2 @@ # memoize-fs | ||
[![npm version](https://badge.fury.io/js/memoize-fs.svg)](http://badge.fury.io/js/memoize-fs) | ||
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
@@ -13,3 +12,3 @@ ## Motivation | ||
Memoization is the best technique to save on memory or CPU cycles when we deal with repeated operations. For detailed insight see: | ||
Memoization is a technique which can help save on memory or CPU cycles when dealing with repeated operations. For detailed insight see: | ||
http://en.wikipedia.org/wiki/Memoization | ||
@@ -35,17 +34,10 @@ | ||
```js | ||
const assert = require('assert') | ||
const memoizeFs = require('memoize-fs') | ||
import memoizeFs from 'memoize-fs' | ||
import assert from 'node:assert' | ||
const memoizer = memoizeFs({ cachePath: './some-cache' }) | ||
console.log(memoizer) | ||
// => { | ||
// fn: [AsyncFunction: fn], | ||
// getCacheFilePath: [Function: t], | ||
// invalidate: [AsyncFunction: e] | ||
// } | ||
async function main () { | ||
;(async () => { | ||
let idx = 0 | ||
const func = function foo (a, b) { | ||
const func = function foo(a, b) { | ||
idx += a + b | ||
@@ -64,9 +56,8 @@ return idx | ||
assert.strictEqual(idx, 3) | ||
} | ||
main().catch(console.error) | ||
})() | ||
``` | ||
_**NOTE:** that memoized function is always an async function and | ||
the result of it is a Promise (if not `await`-ed as seen in above example)!_ | ||
> **Note** | ||
> A memoized function is always an async function and | ||
the result of it is a Promise (which you can `await`, as seen in the example above)! | ||
@@ -172,3 +163,3 @@ - [Learn more about Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) | ||
opt?: Partial<MemoizerOptions> | ||
) => Promise<(...args: Parameters<FN>) => Promise<ReturnType<FN>>> | ||
) => Promise<(...args: Parameters<FN>) => EnsurePromise<ReturnType<FN>>> | ||
getCacheFilePath: ( | ||
@@ -181,2 +172,4 @@ fn: (...args: never) => unknown, | ||
} | ||
type EnsurePromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>; | ||
``` | ||
@@ -269,3 +262,3 @@ | ||
In the following example we are using [Yahoo's `serialize-javascript`](https://ghub.now.sh/serialize-javascript) | ||
In the following example we are using [Yahoo's `serialize-javascript`](https://github.com/yahoo/serialize-javascript) | ||
to be able to cache properly the return result of memoized function containing a `function`. | ||
@@ -272,0 +265,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
25939
349