thaw 2.0.2 → 2.1.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.
Files changed (3) hide show
  1. package/README.md +8 -5
  2. package/dist/index.js +25 -49
  3. package/package.json +12 -14
package/README.md CHANGED
@@ -1,16 +1,19 @@
1
1
  The narrow belt for AOP 🎀
2
- ----
3
- This package provides narrow methods for aspect-oriented programming (AOP).
2
+ ---
3
+ This package provides **narrow-trench** methods for aspect-oriented programming (AOP).
4
4
 
5
5
  ## Prerequisites
6
+
6
7
  * Node.js `>= 14.x`
7
8
 
8
9
  ## Installation
9
- ```shell
10
+
11
+ ```bash
10
12
  npm install thaw --save
11
13
  ```
12
14
 
13
15
  ### Usage
16
+
14
17
  ```javascript
15
18
  import * as thaw from 'thaw';
16
19
 
@@ -33,7 +36,7 @@ setTimeout(debounce, 250); // will fire
33
36
  setTimeout(debounce, 300);
34
37
  setTimeout(debounce, 350); // will fire
35
38
  setTimeout(debounce, 400);
36
- setTimeout(() => console.assert(bip === 2, 'debounce'), 1000);
39
+ setTimeout(() => console.assert(bip === 2, 'debounce'), 1e3);
37
40
 
38
41
  let pib = 0;
39
42
  const throttle = thaw.throttle(() => pib++, 100);
@@ -44,5 +47,5 @@ setTimeout(throttle, 250); // will fire
44
47
  setTimeout(throttle, 300);
45
48
  setTimeout(throttle, 350); // will fire
46
49
  setTimeout(throttle, 400);
47
- setTimeout(() => console.assert(pib === 3, 'throttle'), 1000);
50
+ setTimeout(() => console.assert(pib === 3, 'throttle'), 1e3);
48
51
  ```
package/dist/index.js CHANGED
@@ -1,46 +1,38 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.throttle = exports.debounce = exports.compose = exports.before = exports.after = exports.around = void 0;
4
+ exports.throttle = exports.debounce = exports.compose = exports.before = exports.around = exports.after = void 0;
5
5
 
6
- var around = function around(fn, cb) {
7
- return function () {
8
- return cb(fn(cb.apply(void 0, arguments)));
6
+ const around = (fn, cb) => {
7
+ return (...args) => {
8
+ return cb(fn(cb(...args)));
9
9
  };
10
10
  };
11
11
 
12
12
  exports.around = around;
13
13
 
14
- var after = function after(fn, cb) {
15
- return function () {
16
- return cb(fn.apply(void 0, arguments));
14
+ const after = (fn, cb) => {
15
+ return (...args) => {
16
+ return cb(fn(...args));
17
17
  };
18
18
  };
19
19
 
20
20
  exports.after = after;
21
21
 
22
- var before = function before(fn, cb) {
23
- return function () {
24
- return fn(cb.apply(void 0, arguments));
22
+ const before = (fn, cb) => {
23
+ return (...args) => {
24
+ return fn(cb(...args));
25
25
  };
26
26
  };
27
27
 
28
28
  exports.before = before;
29
29
 
30
- var compose = function compose() {
31
- for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
32
- fns[_key] = arguments[_key];
33
- }
30
+ const compose = (...fns) => {
31
+ return (...args) => {
32
+ let result = null;
34
33
 
35
- return function () {
36
- var result = null;
37
-
38
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
39
- args[_key2] = arguments[_key2];
40
- }
41
-
42
- for (var i = 0; i < fns.length; i++) {
43
- result = fns[i].apply(fns, i ? [result] : args);
34
+ for (let i = 0; i < fns.length; i++) {
35
+ result = fns[i](...(i ? [result] : args));
44
36
  }
45
37
 
46
38
  return result;
@@ -49,40 +41,24 @@ var compose = function compose() {
49
41
 
50
42
  exports.compose = compose;
51
43
 
52
- var debounce = function debounce(fn, wait) {
53
- if (wait === void 0) {
54
- wait = 0;
55
- }
56
-
57
- var tick;
58
- return function () {
59
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
60
- args[_key3] = arguments[_key3];
61
- }
62
-
44
+ const debounce = (fn, wait = 0) => {
45
+ let tick;
46
+ return (...args) => {
63
47
  clearTimeout(tick);
64
- tick = setTimeout(function () {
65
- fn.apply(void 0, args);
48
+ tick = setTimeout(() => {
49
+ fn(...args);
66
50
  }, wait);
67
51
  };
68
52
  };
69
53
 
70
54
  exports.debounce = debounce;
71
55
 
72
- var throttle = function throttle(fn, wait) {
73
- if (wait === void 0) {
74
- wait = 0;
75
- }
76
-
77
- var tick;
78
- return function () {
79
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
80
- args[_key4] = arguments[_key4];
81
- }
82
-
83
- tick = !tick && setTimeout(function () {
56
+ const throttle = (fn, wait = 0) => {
57
+ let tick;
58
+ return (...args) => {
59
+ tick = !tick && setTimeout(() => {
84
60
  tick = clearTimeout(tick);
85
- fn.apply(void 0, args);
61
+ fn(...args);
86
62
  }, wait);
87
63
  };
88
64
  };
package/package.json CHANGED
@@ -2,22 +2,20 @@
2
2
  "author": {
3
3
  "name": "Yehor Sergeenko",
4
4
  "email": "yehor.sergeenko@gmail.com",
5
- "url": "http://github.com/bricss"
5
+ "url": "https://github.com/bricss"
6
6
  },
7
7
  "bugs": {
8
8
  "url": "https://github.com/bricss/thaw/issues"
9
9
  },
10
10
  "devDependencies": {
11
- "@babel/cli": "^7.12.1",
12
- "@babel/core": "^7.12.3",
13
- "@babel/eslint-parser": "^7.12.1",
14
- "@babel/plugin-syntax-top-level-await": "^7.12.1",
15
- "@babel/plugin-transform-runtime": "^7.12.1",
16
- "@babel/preset-env": "^7.12.1",
17
- "c8": "^7.3.5",
18
- "eslint": "^7.12.1",
19
- "eslint-config-ultra-refined": "^1.0.28",
20
- "mocha": "^8.2.0"
11
+ "@babel/cli": "^7.16.8",
12
+ "@babel/core": "^7.16.12",
13
+ "@babel/eslint-parser": "^7.16.5",
14
+ "@babel/preset-env": "^7.16.11",
15
+ "c8": "^7.11.0",
16
+ "eslint": "^8.7.0",
17
+ "eslint-config-ultra-refined": "^2.3.0",
18
+ "mocha": "^9.2.0"
21
19
  },
22
20
  "description": "The narrow belt for AOP 🎀",
23
21
  "engines": {
@@ -46,11 +44,11 @@
46
44
  },
47
45
  "scripts": {
48
46
  "build": "rm -rf dist && npx babel src -d dist",
49
- "lint": "eslint src test --ext .cjs,.js,.mjs",
47
+ "lint": "eslint . --ext .cjs,.js,.mjs",
50
48
  "prepack": "npm run build",
51
49
  "pretest": "rm -rf coverage",
52
- "test": "mocha --exit",
50
+ "test": "mocha --exit --recursive",
53
51
  "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
54
52
  },
55
- "version": "2.0.2"
53
+ "version": "2.1.1"
56
54
  }