zaraz 0.0.2 → 2.0.0

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/Readme.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![NPM version][npm-image]][npm-url]
2
- [![Build Status][travis-image]][travis-url]
2
+ [![Build Status][build-image]][build-url]
3
3
  [![Dependency Status][deps-image]][deps-url]
4
- [![Dev Dependency Status][deps-dev-image]][deps-dev-url]
5
4
 
6
5
  # zaraz
7
6
 
@@ -50,14 +49,12 @@ zaraz(sum, 10, 10); // will displey 20 after it displays 13
50
49
 
51
50
  MIT © [Damian Krzeminski](https://pirxpilot.me)
52
51
 
53
- [npm-image]: https://img.shields.io/npm/v/zaraz.svg
52
+ [npm-image]: https://img.shields.io/npm/v/zaraz
54
53
  [npm-url]: https://npmjs.org/package/zaraz
55
54
 
56
- [travis-url]: https://travis-ci.com/pirxpilot/zaraz
57
- [travis-image]: https://img.shields.io/travis/com/pirxpilot/zaraz.svg
55
+ [build-url]: https://github.com/pirxpilot/zaraz/actions/workflows/check.yaml
56
+ [build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/zaraz/check.yaml?branch=main
58
57
 
59
- [deps-image]: https://img.shields.io/david/pirxpilot/zaraz.svg
60
- [deps-url]: https://david-dm.org/pirxpilot/zaraz
58
+ [deps-image]: https://img.shields.io/librariesio/release/npm/zaraz
59
+ [deps-url]: https://libraries.io/npm/zaraz
61
60
 
62
- [deps-dev-image]: https://img.shields.io/david/dev/pirxpilot/zaraz.svg
63
- [deps-dev-url]: https://david-dm.org/pirxpilot/zaraz?type=dev
package/lib/zaraz.js CHANGED
@@ -1,6 +1,6 @@
1
- const debug = require('debug')('zaraz');
1
+ import Debug from 'debug';
2
2
 
3
- module.exports = zaraz;
3
+ const debug = Debug('zaraz');
4
4
 
5
5
  const queues = {
6
6
  timer: undefined,
@@ -9,29 +9,30 @@ const queues = {
9
9
  later: []
10
10
  };
11
11
 
12
- const Item = {
13
- init(fn, params) {
14
- this._fn = fn;
15
- this._params = params;
16
- return this;
17
- },
12
+ class Item {
13
+ #fn;
14
+ #params;
15
+ constructor(fn, params) {
16
+ this.#fn = fn;
17
+ this.#params = params;
18
+ }
18
19
 
19
20
  run() {
20
21
  // bail if nothing to run
21
- if (!this._fn) { return; }
22
+ if (!this.#fn) return;
22
23
 
23
- const fn = this._fn;
24
+ const fn = this.#fn;
24
25
  this.clear();
25
- fn(...this._params);
26
- },
26
+ fn(...this.#params);
27
+ }
27
28
 
28
29
  clear() {
29
- this._fn = undefined;
30
+ this.#fn = undefined;
30
31
  }
31
- };
32
+ }
32
33
 
33
- function zaraz(fn, ...params) {
34
- const item = Object.create(Item).init(fn, params);
34
+ export default function zaraz(fn, ...params) {
35
+ const item = new Item(fn, params);
35
36
  const q = queues.index > 0 ? queues.later : queues.current;
36
37
  q.push(item);
37
38
 
@@ -39,9 +40,9 @@ function zaraz(fn, ...params) {
39
40
  return item;
40
41
  }
41
42
 
42
- zaraz.DELAY = 10; // default delay
43
- zaraz.ACTIVE = 100; // how long before we yield after processing items
44
- zaraz.MAX_ITEMS = 1000; // how many items we can process in a single step
43
+ zaraz.DELAY = 10; // default delay
44
+ zaraz.ACTIVE = 100; // how long before we yield after processing items
45
+ zaraz.MAX_ITEMS = 1000; // how many items we can process in a single step
45
46
 
46
47
  function execute() {
47
48
  const start = Date.now();
@@ -49,7 +50,7 @@ function execute() {
49
50
 
50
51
  debug('queues before', queues.current.length - queues.index, queues.later.length);
51
52
 
52
- while(queues.index < max) {
53
+ while (queues.index < max) {
53
54
  queues.current[queues.index++].run();
54
55
  if (Date.now() - start > zaraz.ACTIVE) {
55
56
  debug('breaking...');
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "zaraz",
3
- "version": "0.0.2",
3
+ "version": "2.0.0",
4
4
  "description": "Cheap way to introduce short async delay.",
5
+ "type": "module",
6
+ "exports": "./index.js",
5
7
  "author": {
6
8
  "name": "Damian Krzeminski",
7
9
  "email": "pirxpilot@furkot.com",
8
10
  "url": "https://pirxpilot.me"
9
11
  },
10
- "repository": "pirxpilot/zaraz",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/pirxpilot/zaraz.git"
15
+ },
11
16
  "license": "MIT",
12
17
  "keywords": [
13
18
  "zaraz",
@@ -19,9 +24,7 @@
19
24
  "debug": "*"
20
25
  },
21
26
  "devDependencies": {
22
- "jshint": "~2",
23
- "tap-dot": "~2",
24
- "tape": "~4"
27
+ "@biomejs/biome": "^1.9.4"
25
28
  },
26
29
  "scripts": {
27
30
  "test": "make check"
@@ -30,4 +33,4 @@
30
33
  "index.js",
31
34
  "lib"
32
35
  ]
33
- }
36
+ }
package/History.md DELETED
@@ -1,16 +0,0 @@
1
-
2
- 0.0.2 / 2019-04-01
3
- ==================
4
-
5
- * add basic docs to README
6
- * use spread operator to extract optional parameters
7
- * use setInterval instead of setTimeout
8
- * optimize queue merging
9
- * replace mocha with tape
10
- * rewrite in ES6
11
-
12
- 0.0.1 / 2017-11-12
13
- ==================
14
-
15
- * implement MAX_ITEMS and ACTIVE restriction
16
- * initial implementation
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./lib/zaraz');