diff --git a/.github/funding.yml b/.github/funding.yml index 5919969..b5f4cea 100644 --- a/.github/funding.yml +++ b/.github/funding.yml @@ -1,2 +1 @@ github: [sindresorhus, fregante] -tidelift: npm/mem diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ed4040b..d9ff47b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,10 +12,9 @@ jobs: node-version: #- 20 - 18 - - 16 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.ts b/index.ts index 6062813..b945855 100644 --- a/index.ts +++ b/index.ts @@ -1,7 +1,7 @@ -import mimicFn from 'mimic-fn'; +import mimicFunction from 'mimic-function'; import mapAgeCleaner from 'map-age-cleaner'; -type AnyFunction = (...arguments_: any) => any; +type AnyFunction = (...arguments_: readonly any[]) => any; const cacheStore = new WeakMap>(); @@ -68,7 +68,7 @@ export type Options< /** [Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input. -@param fn - Function to be memoized. +@param fn - The function to be memoized. @example ``` @@ -113,7 +113,7 @@ export default function mem< const cacheItem = cache.get(key); if (cacheItem) { - return cacheItem.data; // eslint-disable-line @typescript-eslint/no-unsafe-return + return cacheItem.data; } const result = fn.apply(this, arguments_) as ReturnType; @@ -123,10 +123,10 @@ export default function mem< maxAge: maxAge ? Date.now() + maxAge : Number.POSITIVE_INFINITY, }); - return result; // eslint-disable-line @typescript-eslint/no-unsafe-return + return result; } as FunctionToMemoize; - mimicFn(memoized, fn, { + mimicFunction(memoized, fn, { ignoreNonConfigurable: true, }); diff --git a/package.json b/package.json index 5b70288..5c694f7 100644 --- a/package.json +++ b/package.json @@ -11,16 +11,19 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./dist/index.js", + "exports": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "sideEffects": false, "engines": { - "node": ">=16" + "node": ">=18" }, "scripts": { - "test": "xo && ava && npm run build && tsd", + "test": "xo && ava && npm run build && tsd --typings dist/index.d.ts", "build": "del-cli dist && tsc", "prepack": "npm run build" }, - "types": "dist/index.d.ts", "files": [ "dist" ], @@ -39,19 +42,18 @@ ], "dependencies": { "map-age-cleaner": "^0.2.0", - "mimic-fn": "^4.0.0" + "mimic-function": "^5.0.0" }, "devDependencies": { - "@sindresorhus/tsconfig": "^3.0.1", - "@types/serialize-javascript": "^5.0.2", - "ava": "^5.2.0", - "del-cli": "^5.0.0", - "delay": "^5.0.0", + "@sindresorhus/tsconfig": "^5.0.0", + "@types/serialize-javascript": "^5.0.4", + "ava": "^5.3.1", + "del-cli": "^5.1.0", + "delay": "^6.0.0", "serialize-javascript": "^6.0.1", "ts-node": "^10.9.1", - "tsd": "^0.28.1", - "typescript": "^5.0.4", - "xo": "^0.54.2" + "tsd": "^0.29.0", + "xo": "^0.56.0" }, "ava": { "timeout": "1m", @@ -64,9 +66,7 @@ }, "xo": { "rules": { - "@typescript-eslint/member-ordering": "off", - "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/no-empty-function": "off" + "@typescript-eslint/no-unsafe-return": "off" } } } diff --git a/readme.md b/readme.md index ca0d771..b4ffe68 100644 --- a/readme.md +++ b/readme.md @@ -12,8 +12,8 @@ If you want to memoize Promise-returning functions (like `async` functions), you ## Install -``` -$ npm install mem +```sh +npm install mem ``` ## Usage @@ -164,7 +164,7 @@ Better yet, if your function’s arguments are compatible with `WeakMap`, you sh Type: `Function` -Function to be memoized. +The function to be memoized. #### options @@ -273,15 +273,3 @@ console.log(cache.stats); ## Related - [p-memoize](https://github.com/sindresorhus/p-memoize) - Memoize promise-returning & async functions - ---- - -
- - Get professional support for this package with a Tidelift subscription - -
- - Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. -
-
diff --git a/test.ts b/test.ts index 41bf19a..41aa6c0 100644 --- a/test.ts +++ b/test.ts @@ -162,7 +162,7 @@ test('promise support', async t => { }); test('preserves the original function name', t => { - t.is(mem(function foo() {}).name, 'foo'); // eslint-disable-line func-names + t.is(mem(function foo() {}).name, 'foo'); // eslint-disable-line func-names, @typescript-eslint/no-empty-function }); test('.clear()', t => { @@ -220,7 +220,7 @@ test('.decorator()', t => { test('memClear() throws when called with a plain function', t => { t.throws(() => { - memClear(() => {}); + memClear(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function }, { message: 'Can\'t clear a function that was not memoized!', instanceOf: TypeError,