Skip to content

Commit a69513a

Browse files
committed
Meta tweaks
1 parent 5cb0a4e commit a69513a

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ declare namespace pThrottle {
2121
/**
2222
Maximum number of calls within an `interval`.
2323
*/
24-
limit: number
24+
limit: number;
2525

2626
/**
2727
Timespan for `limit` in milliseconds.
2828
*/
29-
interval: number
29+
interval: number;
3030
}
3131

3232
type AbortError = AbortErrorClass;
3333

3434
/**
3535
@param fn - Promise-returning/async function or a normal function.
3636
*/
37-
type Throttle<FunctionType extends (...args: any) => any> = (fn: (...arguments: Parameters<FunctionType>) => ReturnType<FunctionType>) => pThrottle.ThrottledFunction<FunctionType>;
37+
type Throttle<FunctionType extends (...args: any) => any> = (fn: (...arguments: Parameters<FunctionType>) => ReturnType<FunctionType>) => ThrottledFunction<FunctionType>;
3838
}
3939

4040
declare const pThrottle: {
41+
AbortError: typeof AbortErrorClass;
42+
4143
/**
4244
[Throttle](https://css-tricks.com/debouncing-throttling-explained-examples/) promise-returning/async/normal functions.
4345
@@ -66,8 +68,6 @@ declare const pThrottle: {
6668
<FunctionType extends (...args: any) => any>(
6769
options: pThrottle.Options
6870
): pThrottle.Throttle<FunctionType>;
69-
70-
AbortError: typeof AbortErrorClass;
7171
};
7272

7373
export = pThrottle;

index.test-d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {expectType} from 'tsd';
2-
import pThrottle = require('.');
3-
import {AbortError, ThrottledFunction} from '.';
1+
import {expectType, expectAssignable} from 'tsd';
2+
import pThrottle = require('./index.js');
3+
import {AbortError, ThrottledFunction} from './index.js';
44

55
const throttledUnicorn = pThrottle({
66
limit: 1,
@@ -14,8 +14,8 @@ const throttledLazyUnicorn = pThrottle({
1414

1515
expectType<AbortError>(new AbortError());
1616

17-
expectType<ThrottledFunction<(index: string) => string>>(throttledUnicorn);
18-
expectType<ThrottledFunction<(index: string) => string>>(throttledLazyUnicorn);
17+
expectAssignable<ThrottledFunction<(index: string) => string>>(throttledUnicorn);
18+
expectAssignable<ThrottledFunction<(index: string) => string>>(throttledLazyUnicorn);
1919

2020
throttledUnicorn.abort();
2121
throttledLazyUnicorn.abort();

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"description": "Throttle promise-returning & async functions",
55
"license": "MIT",
66
"repository": "sindresorhus/p-throttle",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
1213
"engines": {
1314
"node": ">=10"
@@ -40,11 +41,11 @@
4041
"bluebird"
4142
],
4243
"devDependencies": {
43-
"ava": "^1.4.1",
44-
"delay": "^4.1.0",
45-
"in-range": "^1.0.0",
46-
"time-span": "^2.0.0",
47-
"tsd": "^0.7.2",
48-
"xo": "^0.24.0"
44+
"ava": "^2.4.0",
45+
"delay": "^4.4.0",
46+
"in-range": "^2.0.0",
47+
"time-span": "^4.0.0",
48+
"tsd": "^0.14.0",
49+
"xo": "^0.37.1"
4950
}
5051
}

test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import inRange from 'in-range';
33
import timeSpan from 'time-span';
4-
import pThrottle from '.';
4+
import pThrottle from './index.js';
55

66
const fixture = Symbol('fixture');
77

@@ -12,10 +12,13 @@ test('main', async t => {
1212
const end = timeSpan();
1313
const throttled = pThrottle({limit, interval})(async () => {});
1414

15-
await Promise.all(new Array(totalRuns).fill(0).map(throttled));
15+
await Promise.all(new Array(totalRuns).fill(0).map(x => throttled(x)));
1616

1717
const totalTime = (totalRuns * interval) / limit;
18-
t.true(inRange(end(), totalTime - 200, totalTime + 200));
18+
t.true(inRange(end(), {
19+
start: totalTime - 200,
20+
end: totalTime + 200
21+
}));
1922
});
2023

2124
test('passes arguments through', async t => {
@@ -35,8 +38,8 @@ test('can be aborted', async t => {
3538
let error;
3639
try {
3740
await promise;
38-
} catch (error2) {
39-
error = error2;
41+
} catch (error_) {
42+
error = error_;
4043
}
4144

4245
t.true(error instanceof pThrottle.AbortError);

0 commit comments

Comments
 (0)