@ultirequiem/six 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{types/mod.d.ts → lib/index.d.ts} +5 -5
- package/lib/index.d.ts.map +1 -0
- package/{esm/mod.js → lib/index.js} +10 -10
- package/package.json +46 -29
- package/readme.md +50 -0
- package/README.md +0 -97
- package/esm/package.json +0 -3
- package/script/mod.js +0 -37
- package/script/package.json +0 -3
- /package/{LICENSE → license.md} +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
/**
|
|
3
2
|
* Limit the amount of times that setInterval will fire.
|
|
4
3
|
*
|
|
5
4
|
* @example
|
|
6
5
|
* ```javascript
|
|
7
|
-
* import {
|
|
8
|
-
* import { randomNumber } from "
|
|
6
|
+
* import { setIntervalX } from "@ultirequiem/six";
|
|
7
|
+
* import { randomNumber } from "@ultirequiem/random-number";
|
|
9
8
|
*
|
|
10
|
-
* const API_URL = "https://leap
|
|
9
|
+
* const API_URL = "https://example.com/api/leap";
|
|
11
10
|
*
|
|
12
11
|
* async function checkAPIStatus() {
|
|
13
12
|
* const randomYear = randomNumber({ min: 2000, max: 10_000});
|
|
@@ -21,4 +20,5 @@
|
|
|
21
20
|
* setIntervalX(checkAPIStatus, 2000, 15);
|
|
22
21
|
* ```
|
|
23
22
|
*/
|
|
24
|
-
export declare function setIntervalX(
|
|
23
|
+
export declare function setIntervalX(handler: (...args: any[]) => any, timeout: number, repetitions: number, ...args: any[]): NodeJS.Timeout;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAChC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,GAAG,IAAI,EAAE,GAAG,EAAE,kBAaf"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/**
|
|
3
3
|
* Limit the amount of times that setInterval will fire.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```javascript
|
|
7
|
-
* import {
|
|
8
|
-
* import { randomNumber } from "
|
|
7
|
+
* import { setIntervalX } from "@ultirequiem/six";
|
|
8
|
+
* import { randomNumber } from "@ultirequiem/random-number";
|
|
9
9
|
*
|
|
10
|
-
* const API_URL = "https://leap
|
|
10
|
+
* const API_URL = "https://example.com/api/leap";
|
|
11
11
|
*
|
|
12
12
|
* async function checkAPIStatus() {
|
|
13
13
|
* const randomYear = randomNumber({ min: 2000, max: 10_000});
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
* setIntervalX(checkAPIStatus, 2000, 15);
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export function setIntervalX(
|
|
24
|
+
export function setIntervalX(handler, timeout, repetitions, ...args) {
|
|
25
25
|
let x = 0;
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const interval = setInterval(() => {
|
|
27
|
+
handler(...args);
|
|
28
28
|
if (++x === repetitions) {
|
|
29
|
-
clearInterval(
|
|
29
|
+
clearInterval(interval);
|
|
30
30
|
}
|
|
31
|
-
},
|
|
32
|
-
return
|
|
31
|
+
}, timeout);
|
|
32
|
+
return interval;
|
|
33
33
|
}
|
package/package.json
CHANGED
|
@@ -1,39 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
"module": "./esm/mod.js",
|
|
3
|
-
"main": "./script/mod.js",
|
|
4
|
-
"types": "./types/mod.d.ts",
|
|
5
2
|
"name": "@ultirequiem/six",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Limit how many times setInterval fires.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.js"
|
|
12
|
+
}
|
|
12
13
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
14
|
+
"files": [
|
|
15
|
+
"lib/**/*"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
18
19
|
},
|
|
19
20
|
"keywords": [
|
|
20
|
-
"
|
|
21
|
-
"
|
|
21
|
+
"setinterval",
|
|
22
|
+
"timer",
|
|
23
|
+
"repeat",
|
|
24
|
+
"esm",
|
|
25
|
+
"typescript"
|
|
22
26
|
],
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"homepage": "https://ulti.js.org/six",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/UltiRequiem/six.git"
|
|
29
32
|
},
|
|
30
33
|
"scripts": {
|
|
31
|
-
"
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"lint": "eslint 'src/**/*.ts' && prettier --check 'src/**/*.ts'",
|
|
36
|
+
"fmt": "prettier --write 'src/**/*.ts'",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:coverage": "vitest run --coverage"
|
|
32
39
|
},
|
|
33
|
-
"dependencies": {},
|
|
34
40
|
"devDependencies": {
|
|
35
|
-
"@types/node": "
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
"@types/node": "^26.6.5",
|
|
42
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
43
|
+
"eslint": "^10.13.0",
|
|
44
|
+
"eslint-plugin-tsdoc": "^0.5.4",
|
|
45
|
+
"eslint-plugin-unicorn": "^78.0.0",
|
|
46
|
+
"prettier": "^3.9.10",
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
|
+
"typescript-eslint": "^8.72.0",
|
|
49
|
+
"vitest": "^5.0.5"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@ultirequiem/random-number": "^2.0.0",
|
|
53
|
+
"@ultirequiem/six": "^1.0.0"
|
|
54
|
+
},
|
|
55
|
+
"packageManager": "pnpm@12.6.0"
|
|
56
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# six
|
|
2
|
+
|
|
3
|
+
Set Interval X
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@ultirequiem/six)
|
|
6
|
+
[](https://www.npmjs.com/package/@ultirequiem/six)
|
|
7
|
+
[](https://github.com/UltiRequiem/six/actions/workflows/ci.yaml)
|
|
8
|
+
[](https://codecov.io/gh/UltiRequiem/six)
|
|
9
|
+
|
|
10
|
+
Limit the amount of times that `setInterval` will fire.
|
|
11
|
+
|
|
12
|
+
> Made for
|
|
13
|
+
> [this StackOverflow Question](https://stackoverflow.com/questions/2956966) 😆
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @ultirequiem/six
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
ESM only, types included: the same import works in Node.js, Bun and browsers.
|
|
24
|
+
|
|
25
|
+
## Support
|
|
26
|
+
|
|
27
|
+
Open an Issue, I will check it as soon as possible 👀
|
|
28
|
+
|
|
29
|
+
If you want to hurry me up a bit
|
|
30
|
+
[send me a tweet](https://twitter.com/intent/tweet?text=%40UltiRequiem%20) 😆
|
|
31
|
+
|
|
32
|
+
Don't forget to star the repo ⭐
|
|
33
|
+
|
|
34
|
+
## Versioning
|
|
35
|
+
|
|
36
|
+
We use [SemVer](http://semver.org) for versioning. For the versions available,
|
|
37
|
+
see the [tags](https://github.com/UltiRequiem/six/tags).
|
|
38
|
+
|
|
39
|
+
## Authors
|
|
40
|
+
|
|
41
|
+
[Eliaz Bobadilla (a.k.a UltiRequiem)](https://ultirequiem.com) - Creator and
|
|
42
|
+
Maintainer 💪
|
|
43
|
+
|
|
44
|
+
See also the full list of
|
|
45
|
+
[contributors](https://github.com/UltiRequiem/six/contributors) who participated
|
|
46
|
+
in this project.
|
|
47
|
+
|
|
48
|
+
## Licence
|
|
49
|
+
|
|
50
|
+
Released under the MIT Licence.
|
package/README.md
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# six
|
|
2
|
-
|
|
3
|
-
[](https://github.com/UltiRequiem/six/actions/workflows/ci.yaml)
|
|
4
|
-
[](https://codecov.io/gh/ultirequiem/six)
|
|
5
|
-
[](https://doc.deno.land/https/deno.land/x/six/mod.ts)
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-

|
|
9
|
-
[](https://deno.land/x/six)
|
|
10
|
-
|
|
11
|
-
> Set Interval X
|
|
12
|
-
|
|
13
|
-
Limit the amount of times that `setInterval` will fire.
|
|
14
|
-
|
|
15
|
-
> Made for
|
|
16
|
-
> [this StackOverflow Question](https://stackoverflow.com/questions/2956966) 😆
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
### [Deno 🚀](https://deno.land/x/six)
|
|
21
|
-
|
|
22
|
-
```javascript
|
|
23
|
-
import { setInterval } from "https://deno.land/x/six/mod.ts";
|
|
24
|
-
import { randomNumber } from "https://deno.land/x/random_number/mod.ts";
|
|
25
|
-
|
|
26
|
-
const API_URL = "https://leap.deno.dev";
|
|
27
|
-
|
|
28
|
-
async function checkAPIStatus() {
|
|
29
|
-
const startTime = performance.now();
|
|
30
|
-
|
|
31
|
-
const randomYear = randomNumber({ min: 2000, max: 10_000 });
|
|
32
|
-
|
|
33
|
-
const response = await fetch(`${API_URL}/${randomYear}`);
|
|
34
|
-
|
|
35
|
-
const data = await response.json();
|
|
36
|
-
|
|
37
|
-
console.log(`Is ${randomYear} a leap year? ${data.leapYear}.`);
|
|
38
|
-
|
|
39
|
-
const entTime = performance.now();
|
|
40
|
-
|
|
41
|
-
console.log(`Request took ${(entTime - startTime) / 1000} seconds.`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
setIntervalX(checkAPIStatus, 2000, 15);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### [Node.js 🐢](https://www.npmjs.com/package/@ultirequiem/six)
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { setIntervalX } from "@ultirequiem/six";
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### [Browser 🕸](https://developer.mozilla.org/en-US/docs/Glossary/Browser)
|
|
54
|
-
|
|
55
|
-
You can use any [CDN](https://en.wikipedia.org/wiki/Content_delivery_network) 🔥
|
|
56
|
-
|
|
57
|
-
Eg. [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
|
58
|
-
▶ [SkyPack](https://cdn.skypack.dev/@ultirequiem/six) _/_
|
|
59
|
-
[script tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) ▶
|
|
60
|
-
[JSDelivr](https://cdn.jsdelivr.net/npm/@ultirequiem/six).
|
|
61
|
-
|
|
62
|
-
The API is the same on all this platforms.
|
|
63
|
-
|
|
64
|
-
## API
|
|
65
|
-
|
|
66
|
-
[Autogenerated Documentation](https://doc.deno.land/https://deno.land/x/six/mod.ts)
|
|
67
|
-
🚀
|
|
68
|
-
|
|
69
|
-
## Support
|
|
70
|
-
|
|
71
|
-
Open an Issue, I will check it a soon as possible 👀
|
|
72
|
-
|
|
73
|
-
If you want to hurry me up a bit
|
|
74
|
-
[send me a tweet](https://twitter.com/intent/tweet?text=%40UltiRequiem%20) 😆
|
|
75
|
-
|
|
76
|
-
Consider [supporting me on Patreon](https://patreon.com/UltiRequiem) if you like
|
|
77
|
-
my work 🚀
|
|
78
|
-
|
|
79
|
-
Don't forget to start the repo ⭐
|
|
80
|
-
|
|
81
|
-
## Versioning
|
|
82
|
-
|
|
83
|
-
We use [SemVer](http://semver.org) for versioning. For the versions available,
|
|
84
|
-
see the [tags](https://github.com/UltiRequiem/six/tags).
|
|
85
|
-
|
|
86
|
-
## Authors
|
|
87
|
-
|
|
88
|
-
[Eliaz Bobadilla (a.k.a UltiRequiem)](https://ultirequiem.com) - Creator and
|
|
89
|
-
Maintainer 💪
|
|
90
|
-
|
|
91
|
-
See also the full list of
|
|
92
|
-
[contributors](https://github.com/UltiRequiem/six/contributors) who participated
|
|
93
|
-
in this project.
|
|
94
|
-
|
|
95
|
-
## Licence
|
|
96
|
-
|
|
97
|
-
Released under the MIT Licence.
|
package/esm/package.json
DELETED
package/script/mod.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// deno-lint-ignore-file no-explicit-any
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.setIntervalX = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Limit the amount of times that setInterval will fire.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```javascript
|
|
10
|
-
* import { setInterval } from "https://deno.land/x/six/mod.ts";
|
|
11
|
-
* import { randomNumber } from "https://deno.land/x/random_number/mod.ts";
|
|
12
|
-
*
|
|
13
|
-
* const API_URL = "https://leap.deno.dev";
|
|
14
|
-
*
|
|
15
|
-
* async function checkAPIStatus() {
|
|
16
|
-
* const randomYear = randomNumber({ min: 2000, max: 10_000});
|
|
17
|
-
*
|
|
18
|
-
* const response = await fetch(`${API_URL}/${randomYear}`);
|
|
19
|
-
* const data = await response.json();
|
|
20
|
-
*
|
|
21
|
-
* console.log(`Is ${randomYear} a leap year? ${data.leapYear}.`);
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* setIntervalX(checkAPIStatus, 2000, 15);
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
function setIntervalX(callback, delay, repetitions, ...args) {
|
|
28
|
-
let x = 0;
|
|
29
|
-
const intervalID = setInterval(() => {
|
|
30
|
-
callback(...args);
|
|
31
|
-
if (++x === repetitions) {
|
|
32
|
-
clearInterval(intervalID);
|
|
33
|
-
}
|
|
34
|
-
}, delay);
|
|
35
|
-
return intervalID;
|
|
36
|
-
}
|
|
37
|
-
exports.setIntervalX = setIntervalX;
|
package/script/package.json
DELETED
/package/{LICENSE → license.md}
RENAMED
|
File without changes
|