Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1afa53c

Browse files
authored
Update dependencies and require Node.js 10 (#67)
1 parent807d7c0 commit1afa53c

File tree

7 files changed

+60
-48
lines changed

7 files changed

+60
-48
lines changed

‎.travis.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ language: node_js
22
node_js:
33
-'12'
44
-'10'
5-
-'8'

‎index.d.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
declarenamespacemem{
22
interfaceCacheStorage<KeyType,ValueType>{
3-
has(key:KeyType):boolean;
4-
get(key:KeyType):ValueType|undefined;
5-
set(key:KeyType,value:ValueType):void;
6-
delete(key:KeyType):void;
3+
has:(key:KeyType)=>boolean;
4+
get:(key:KeyType)=>ValueType|undefined;
5+
set:(key:KeyType,value:ValueType)=>void;
6+
delete:(key:KeyType)=>void;
77
clear?:()=>void;
88
}
99

@@ -100,9 +100,9 @@ declare const mem: {
100100
101101
@param fn - Memoized function.
102102
*/
103-
clear<ArgumentsTypeextendsunknown[],ReturnType>(
103+
clear:<ArgumentsTypeextendsunknown[],ReturnType>(
104104
fn:(...arguments:ArgumentsType)=>ReturnType
105-
):void;
105+
)=>void;
106106
};
107107

108108
export=mem;

‎index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const mem = (fn, {
3535
// The below call will throw in some host environments
3636
// See https://github.com/sindresorhus/mimic-fn/issues/10
3737
mimicFn(memoized,fn);
38-
}catch(_){}
38+
}catch{}
3939

4040
cacheStore.set(memoized,cache);
4141

‎index.test-d.ts‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎package.json‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url":"https://sindresorhus.com"
1212
},
1313
"engines": {
14-
"node":">=8"
14+
"node":">=10"
1515
},
1616
"scripts": {
1717
"test":"xo && ava && tsd"
@@ -38,10 +38,16 @@
3838
"mimic-fn":"^3.0.0"
3939
},
4040
"devDependencies": {
41-
"ava":"^2.4.0",
41+
"@types/serialize-javascript":"^4.0.0",
42+
"ava":"^3.13.0",
4243
"delay":"^4.1.0",
43-
"serialize-javascript":"^2.1.0",
44-
"tsd":"^0.11.0",
45-
"xo":"^0.25.3"
44+
"serialize-javascript":"^5.0.1",
45+
"tsd":"^0.13.1",
46+
"xo":"^0.33.1"
47+
},
48+
"xo": {
49+
"rules": {
50+
"@typescript-eslint/member-ordering":"off"
51+
}
4652
}
4753
}

‎test-d/index.test-d.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import{expectType}from'tsd';
2+
importmem= require('..');
3+
4+
constfn=(text:string)=>Boolean(text);
5+
6+
expectType<typeoffn>(mem(fn));
7+
expectType<typeoffn>(mem(fn,{maxAge:1}));
8+
expectType<typeoffn>(mem(fn,{cacheKey:([firstArgument])=>firstArgument}));
9+
expectType<typeoffn>(
10+
mem(fn,{
11+
// The cacheKey returns an array. This isn't deduplicated by a regular Map, but it's valid. The correct solution would be to use ManyKeysMap to deduplicate it correctly
12+
cacheKey:(arguments_:[string])=>arguments_,
13+
cache:newMap<[string],{data:boolean;maxAge:number}>()
14+
})
15+
);
16+
expectType<typeoffn>(
17+
// The `firstArgument` of `fn` is of type `string`, so it's used
18+
mem(fn,{cache:newMap<string,{data:boolean;maxAge:number}>()})
19+
);
20+
21+
/* Overloaded function tests */
22+
functionoverloadedFn(parameter:false):false;
23+
functionoverloadedFn(parameter:true):true;
24+
functionoverloadedFn(parameter:boolean):boolean{
25+
returnparameter;
26+
}
27+
28+
expectType<typeofoverloadedFn>(mem(overloadedFn));
29+
expectType<true>(mem(overloadedFn)(true));
30+
expectType<false>(mem(overloadedFn)(false));
31+
32+
mem.clear(fn);

‎test.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
importtestfrom'ava';
2-
importdelayfrom'delay';
3-
importserializeJavascriptfrom'serialize-javascript';
4-
importmemfrom'.';
1+
consttest=require('ava');
2+
constdelay=require('delay');
3+
constserializeJavascript=require('serialize-javascript');
4+
constmem=require('.');
55

66
test('memoize',t=>{
77
leti=0;
@@ -132,7 +132,9 @@ test('maxAge items are deleted even if function throws', async t => {
132132
awaitdelay(50);
133133
t.is(memoized(1),0);
134134
awaitdelay(200);
135-
t.throws(()=>memoized(1),'failure');
135+
t.throws(()=>memoized(1),{
136+
message:'failure'
137+
});
136138
t.is(cache.size,0);
137139
});
138140

@@ -195,5 +197,7 @@ test('prototype support', t => {
195197
test('mem.clear() throws when called with a plain function',t=>{
196198
t.throws(()=>{
197199
mem.clear(()=>{});
198-
},'Can\'t clear a function that was not memoized!');
200+
},{
201+
message:'Can\'t clear a function that was not memoized!'
202+
});
199203
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp