@daysnap/utils 0.0.80 → 0.0.82
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/docs/interfaces/StorageManager.md +4 -4
- package/docs/interfaces/Trap.md +5 -5
- package/docs/modules.md +183 -114
- package/es/createLinearFunction.d.ts +9 -0
- package/es/createLinearFunction.js +20 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/throttle.js +1 -1
- package/es/withPreventConsecutiveClicks.d.ts +4 -0
- package/es/withPreventConsecutiveClicks.js +38 -0
- package/lib/createLinearFunction.d.ts +9 -0
- package/lib/createLinearFunction.js +24 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/throttle.js +1 -1
- package/lib/withPreventConsecutiveClicks.d.ts +4 -0
- package/lib/withPreventConsecutiveClicks.js +42 -0
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建一个线性函数
|
|
3
|
+
* 主要用于动画值计算
|
|
4
|
+
* @param x1 坐标轴 x1
|
|
5
|
+
* @param x2 坐标轴 x2
|
|
6
|
+
* @param y1 坐标轴 y1
|
|
7
|
+
* @param y2 坐标轴 y2
|
|
8
|
+
*/
|
|
9
|
+
export function createLinearFunction(x1, x2, y1, y2) {
|
|
10
|
+
return (x) => {
|
|
11
|
+
if (x <= x1) {
|
|
12
|
+
return y1;
|
|
13
|
+
}
|
|
14
|
+
if (x >= x2) {
|
|
15
|
+
return y2;
|
|
16
|
+
}
|
|
17
|
+
const r = (y2 - y1) / (x2 - x1);
|
|
18
|
+
return r * (x - x1) + y1;
|
|
19
|
+
};
|
|
20
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './cloneSimple';
|
|
|
11
11
|
export * from './compareVersion';
|
|
12
12
|
export * from './compressImage';
|
|
13
13
|
export * from './createHexColorByHash';
|
|
14
|
+
export * from './createLinearFunction';
|
|
14
15
|
export * from './createWithLoading';
|
|
15
16
|
export * from './debounce';
|
|
16
17
|
export * from './downloadFile';
|
|
@@ -102,3 +103,4 @@ export * from './toCDB';
|
|
|
102
103
|
export * from './toDBC';
|
|
103
104
|
export * from './trap';
|
|
104
105
|
export * from './typeOf';
|
|
106
|
+
export * from './withPreventConsecutiveClicks';
|
package/es/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from './cloneSimple';
|
|
|
12
12
|
export * from './compareVersion';
|
|
13
13
|
export * from './compressImage';
|
|
14
14
|
export * from './createHexColorByHash';
|
|
15
|
+
export * from './createLinearFunction';
|
|
15
16
|
export * from './createWithLoading';
|
|
16
17
|
export * from './debounce';
|
|
17
18
|
export * from './downloadFile';
|
|
@@ -103,3 +104,4 @@ export * from './toCDB';
|
|
|
103
104
|
export * from './toDBC';
|
|
104
105
|
export * from './trap';
|
|
105
106
|
export * from './typeOf';
|
|
107
|
+
export * from './withPreventConsecutiveClicks';
|
package/es/throttle.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 防止连续点击
|
|
12
|
+
*/
|
|
13
|
+
export function withPreventConsecutiveClicks(fn, ms) {
|
|
14
|
+
let flag = false;
|
|
15
|
+
return function (...args) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (flag) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
flag = true;
|
|
21
|
+
try {
|
|
22
|
+
return yield fn.apply(this, args);
|
|
23
|
+
// eslint-disable-next-line no-useless-catch
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
if (ms) {
|
|
30
|
+
setTimeout(() => (flag = false), ms);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
flag = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLinearFunction = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 创建一个线性函数
|
|
6
|
+
* 主要用于动画值计算
|
|
7
|
+
* @param x1 坐标轴 x1
|
|
8
|
+
* @param x2 坐标轴 x2
|
|
9
|
+
* @param y1 坐标轴 y1
|
|
10
|
+
* @param y2 坐标轴 y2
|
|
11
|
+
*/
|
|
12
|
+
function createLinearFunction(x1, x2, y1, y2) {
|
|
13
|
+
return (x) => {
|
|
14
|
+
if (x <= x1) {
|
|
15
|
+
return y1;
|
|
16
|
+
}
|
|
17
|
+
if (x >= x2) {
|
|
18
|
+
return y2;
|
|
19
|
+
}
|
|
20
|
+
const r = (y2 - y1) / (x2 - x1);
|
|
21
|
+
return r * (x - x1) + y1;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.createLinearFunction = createLinearFunction;
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './cloneSimple';
|
|
|
11
11
|
export * from './compareVersion';
|
|
12
12
|
export * from './compressImage';
|
|
13
13
|
export * from './createHexColorByHash';
|
|
14
|
+
export * from './createLinearFunction';
|
|
14
15
|
export * from './createWithLoading';
|
|
15
16
|
export * from './debounce';
|
|
16
17
|
export * from './downloadFile';
|
|
@@ -102,3 +103,4 @@ export * from './toCDB';
|
|
|
102
103
|
export * from './toDBC';
|
|
103
104
|
export * from './trap';
|
|
104
105
|
export * from './typeOf';
|
|
106
|
+
export * from './withPreventConsecutiveClicks';
|
package/lib/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __exportStar(require("./cloneSimple"), exports);
|
|
|
28
28
|
__exportStar(require("./compareVersion"), exports);
|
|
29
29
|
__exportStar(require("./compressImage"), exports);
|
|
30
30
|
__exportStar(require("./createHexColorByHash"), exports);
|
|
31
|
+
__exportStar(require("./createLinearFunction"), exports);
|
|
31
32
|
__exportStar(require("./createWithLoading"), exports);
|
|
32
33
|
__exportStar(require("./debounce"), exports);
|
|
33
34
|
__exportStar(require("./downloadFile"), exports);
|
|
@@ -119,3 +120,4 @@ __exportStar(require("./toCDB"), exports);
|
|
|
119
120
|
__exportStar(require("./toDBC"), exports);
|
|
120
121
|
__exportStar(require("./trap"), exports);
|
|
121
122
|
__exportStar(require("./typeOf"), exports);
|
|
123
|
+
__exportStar(require("./withPreventConsecutiveClicks"), exports);
|
package/lib/throttle.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.throttle = exports.throttleTrailing = exports.throttleLeading = void 0;
|
|
|
6
6
|
* 减少事件执行次数,有规律的执行,事件触发后立即执行
|
|
7
7
|
*/
|
|
8
8
|
function throttleLeading(fn, ms) {
|
|
9
|
-
let pre =
|
|
9
|
+
let pre = 0;
|
|
10
10
|
// eslint-disable-next-line func-names
|
|
11
11
|
return function (...args) {
|
|
12
12
|
const now = Date.now();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.withPreventConsecutiveClicks = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* 防止连续点击
|
|
15
|
+
*/
|
|
16
|
+
function withPreventConsecutiveClicks(fn, ms) {
|
|
17
|
+
let flag = false;
|
|
18
|
+
return function (...args) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (flag) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
flag = true;
|
|
24
|
+
try {
|
|
25
|
+
return yield fn.apply(this, args);
|
|
26
|
+
// eslint-disable-next-line no-useless-catch
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (ms) {
|
|
33
|
+
setTimeout(() => (flag = false), ms);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
flag = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.withPreventConsecutiveClicks = withPreventConsecutiveClicks;
|