Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 14, 2023
1 parent 22c4b5e commit 3afdfaf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 43 deletions.
1 change: 0 additions & 1 deletion .github/funding.yml
@@ -1,2 +1 @@
github: [sindresorhus, fregante]
tidelift: npm/mem
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions 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<AnyFunction, CacheStorage<any, any>>();

Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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<FunctionToMemoize>;
Expand All @@ -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,
});

Expand Down
32 changes: 16 additions & 16 deletions package.json
Expand Up @@ -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"
],
Expand All @@ -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",
Expand All @@ -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"
}
}
}
18 changes: 3 additions & 15 deletions readme.md
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -273,15 +273,3 @@ console.log(cache.stats);
## Related

- [p-memoize](https://github.com/sindresorhus/p-memoize) - Memoize promise-returning & async functions

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-mem?utm_source=npm-mem&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
4 changes: 2 additions & 2 deletions test.ts
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3afdfaf

Please sign in to comment.