@daysnap/utils 0.0.78 → 0.0.80
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 +254 -111
- package/es/formartDateToZN.js +0 -1
- package/es/throttle.d.ts +11 -1
- package/es/throttle.js +25 -3
- package/es/trap.d.ts +5 -0
- package/es/trap.js +13 -0
- package/lib/formartDateToZN.js +0 -1
- package/lib/throttle.d.ts +11 -1
- package/lib/throttle.js +28 -4
- package/lib/trap.d.ts +5 -0
- package/lib/trap.js +15 -1
- package/package.json +1 -1
package/es/formartDateToZN.js
CHANGED
|
@@ -9,7 +9,6 @@ export function formatDateToZN(v) {
|
|
|
9
9
|
const hours = Math.floor(minutes / 60);
|
|
10
10
|
const days = Math.floor(hours / 24);
|
|
11
11
|
const weeks = Math.floor(days / 7);
|
|
12
|
-
console.log(diff, seconds, minutes, hours, days, weeks);
|
|
13
12
|
// 判断时间间隔,并返回相应的表示方式
|
|
14
13
|
if (weeks >= 4) {
|
|
15
14
|
return formatDate(timestamp, 'yyyy-MM-dd hh:mm');
|
package/es/throttle.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 节流函数,时间戳模式
|
|
3
|
+
* 减少事件执行次数,有规律的执行,事件触发后立即执行
|
|
4
|
+
*/
|
|
5
|
+
export declare function throttleLeading<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
|
|
6
|
+
/**
|
|
7
|
+
* 节流函数,定时器模式
|
|
8
|
+
* 减少事件执行次数,有规律的执行,事件触发后延迟执行
|
|
9
|
+
*/
|
|
10
|
+
export declare function throttleTrailing<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
|
|
1
11
|
/**
|
|
2
12
|
* 节流函数
|
|
3
13
|
* 减少事件执行次数,有规律的执行
|
|
4
14
|
*/
|
|
5
|
-
export declare function throttle<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
|
|
15
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, ms: number, mode?: 'leading' | 'trailing'): (this: unknown, ...args: Parameters<T>) => void;
|
package/es/throttle.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 节流函数,时间戳模式
|
|
3
|
+
* 减少事件执行次数,有规律的执行,事件触发后立即执行
|
|
4
4
|
*/
|
|
5
|
-
export function
|
|
5
|
+
export function throttleLeading(fn, ms) {
|
|
6
|
+
let pre = Date.now();
|
|
7
|
+
// eslint-disable-next-line func-names
|
|
8
|
+
return function (...args) {
|
|
9
|
+
const now = Date.now();
|
|
10
|
+
if (now - pre >= ms) {
|
|
11
|
+
fn.apply(this, args);
|
|
12
|
+
pre = now;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 节流函数,定时器模式
|
|
18
|
+
* 减少事件执行次数,有规律的执行,事件触发后延迟执行
|
|
19
|
+
*/
|
|
20
|
+
export function throttleTrailing(fn, ms) {
|
|
6
21
|
let timer = null;
|
|
7
22
|
// eslint-disable-next-line func-names
|
|
8
23
|
return function (...args) {
|
|
@@ -15,3 +30,10 @@ export function throttle(fn, ms) {
|
|
|
15
30
|
}, ms);
|
|
16
31
|
};
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 节流函数
|
|
35
|
+
* 减少事件执行次数,有规律的执行
|
|
36
|
+
*/
|
|
37
|
+
export function throttle(fn, ms, mode = 'trailing') {
|
|
38
|
+
return mode === 'leading' ? throttleLeading(fn, ms) : throttleTrailing(fn, ms);
|
|
39
|
+
}
|
package/es/trap.d.ts
CHANGED
package/es/trap.js
CHANGED
|
@@ -28,3 +28,16 @@ export const trap = {
|
|
|
28
28
|
this.list = {};
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
|
+
export function createTrapInstance(id) {
|
|
32
|
+
return {
|
|
33
|
+
trigger(data) {
|
|
34
|
+
return trap.trigger(id, data);
|
|
35
|
+
},
|
|
36
|
+
create(cb) {
|
|
37
|
+
return trap.create(id, cb);
|
|
38
|
+
},
|
|
39
|
+
delete() {
|
|
40
|
+
return trap.delete(id);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/lib/formartDateToZN.js
CHANGED
|
@@ -12,7 +12,6 @@ function formatDateToZN(v) {
|
|
|
12
12
|
const hours = Math.floor(minutes / 60);
|
|
13
13
|
const days = Math.floor(hours / 24);
|
|
14
14
|
const weeks = Math.floor(days / 7);
|
|
15
|
-
console.log(diff, seconds, minutes, hours, days, weeks);
|
|
16
15
|
// 判断时间间隔,并返回相应的表示方式
|
|
17
16
|
if (weeks >= 4) {
|
|
18
17
|
return (0, index_1.formatDate)(timestamp, 'yyyy-MM-dd hh:mm');
|
package/lib/throttle.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 节流函数,时间戳模式
|
|
3
|
+
* 减少事件执行次数,有规律的执行,事件触发后立即执行
|
|
4
|
+
*/
|
|
5
|
+
export declare function throttleLeading<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
|
|
6
|
+
/**
|
|
7
|
+
* 节流函数,定时器模式
|
|
8
|
+
* 减少事件执行次数,有规律的执行,事件触发后延迟执行
|
|
9
|
+
*/
|
|
10
|
+
export declare function throttleTrailing<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
|
|
1
11
|
/**
|
|
2
12
|
* 节流函数
|
|
3
13
|
* 减少事件执行次数,有规律的执行
|
|
4
14
|
*/
|
|
5
|
-
export declare function throttle<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
|
|
15
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, ms: number, mode?: 'leading' | 'trailing'): (this: unknown, ...args: Parameters<T>) => void;
|
package/lib/throttle.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throttle = void 0;
|
|
3
|
+
exports.throttle = exports.throttleTrailing = exports.throttleLeading = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* 节流函数,时间戳模式
|
|
6
|
+
* 减少事件执行次数,有规律的执行,事件触发后立即执行
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
8
|
+
function throttleLeading(fn, ms) {
|
|
9
|
+
let pre = Date.now();
|
|
10
|
+
// eslint-disable-next-line func-names
|
|
11
|
+
return function (...args) {
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
if (now - pre >= ms) {
|
|
14
|
+
fn.apply(this, args);
|
|
15
|
+
pre = now;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.throttleLeading = throttleLeading;
|
|
20
|
+
/**
|
|
21
|
+
* 节流函数,定时器模式
|
|
22
|
+
* 减少事件执行次数,有规律的执行,事件触发后延迟执行
|
|
23
|
+
*/
|
|
24
|
+
function throttleTrailing(fn, ms) {
|
|
9
25
|
let timer = null;
|
|
10
26
|
// eslint-disable-next-line func-names
|
|
11
27
|
return function (...args) {
|
|
@@ -18,4 +34,12 @@ function throttle(fn, ms) {
|
|
|
18
34
|
}, ms);
|
|
19
35
|
};
|
|
20
36
|
}
|
|
37
|
+
exports.throttleTrailing = throttleTrailing;
|
|
38
|
+
/**
|
|
39
|
+
* 节流函数
|
|
40
|
+
* 减少事件执行次数,有规律的执行
|
|
41
|
+
*/
|
|
42
|
+
function throttle(fn, ms, mode = 'trailing') {
|
|
43
|
+
return mode === 'leading' ? throttleLeading(fn, ms) : throttleTrailing(fn, ms);
|
|
44
|
+
}
|
|
21
45
|
exports.throttle = throttle;
|
package/lib/trap.d.ts
CHANGED
package/lib/trap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.trap = void 0;
|
|
3
|
+
exports.createTrapInstance = exports.trap = void 0;
|
|
4
4
|
const isUndefined_1 = require("./isUndefined");
|
|
5
5
|
exports.trap = {
|
|
6
6
|
list: {},
|
|
@@ -31,3 +31,17 @@ exports.trap = {
|
|
|
31
31
|
this.list = {};
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
|
+
function createTrapInstance(id) {
|
|
35
|
+
return {
|
|
36
|
+
trigger(data) {
|
|
37
|
+
return exports.trap.trigger(id, data);
|
|
38
|
+
},
|
|
39
|
+
create(cb) {
|
|
40
|
+
return exports.trap.create(id, cb);
|
|
41
|
+
},
|
|
42
|
+
delete() {
|
|
43
|
+
return exports.trap.delete(id);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.createTrapInstance = createTrapInstance;
|