ph-utils 0.20.0 → 1.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/lib/browser.d.ts +416 -0
- package/lib/browser.js +858 -0
- package/lib/color-CUZrwrjD.js +206 -0
- package/lib/index.d.ts +615 -61
- package/lib/index.js +1539 -235
- package/lib/node.d.ts +115 -0
- package/lib/node.js +213 -0
- package/package.json +10 -64
- package/lib/array.d.ts +0 -79
- package/lib/array.js +0 -212
- package/lib/color.d.ts +0 -55
- package/lib/color.js +0 -294
- package/lib/config.d.ts +0 -33
- package/lib/config.js +0 -99
- package/lib/copy.d.ts +0 -11
- package/lib/copy.js +0 -101
- package/lib/crypto.d.ts +0 -74
- package/lib/crypto.js +0 -261
- package/lib/crypto_node.d.ts +0 -61
- package/lib/crypto_node.js +0 -133
- package/lib/date.d.ts +0 -66
- package/lib/date.js +0 -202
- package/lib/dom.d.ts +0 -265
- package/lib/dom.js +0 -635
- package/lib/file.d.ts +0 -29
- package/lib/file.js +0 -54
- package/lib/id.d.ts +0 -68
- package/lib/id.js +0 -170
- package/lib/logger.d.ts +0 -62
- package/lib/logger.js +0 -122
- package/lib/server.d.ts +0 -33
- package/lib/server.js +0 -65
- package/lib/storage.d.ts +0 -51
- package/lib/storage.js +0 -73
- package/lib/theme.d.ts +0 -44
- package/lib/theme.js +0 -156
- package/lib/validator.d.ts +0 -71
- package/lib/validator.js +0 -248
- package/lib/web.d.ts +0 -30
- package/lib/web.js +0 -100
package/lib/web.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* web(浏览器) 端工具类
|
|
3
|
-
*/
|
|
4
|
-
import { isBlank } from "./index.js";
|
|
5
|
-
/**
|
|
6
|
-
* 解析 Form 表单中的 input 元素的数据为 JSON 格式,key: input-name;value: input-value
|
|
7
|
-
* @param form {object} Form 节点对象
|
|
8
|
-
*/
|
|
9
|
-
export const formJson = function (form) {
|
|
10
|
-
let elems = form.elements;
|
|
11
|
-
let value = {};
|
|
12
|
-
for (let i = 0, len = elems.length; i < len; i++) {
|
|
13
|
-
let item = elems[i];
|
|
14
|
-
if (!isBlank(item.name)) {
|
|
15
|
-
if ((item.tagName === "INPUT" || item.tagName === "TEXTAREA") &&
|
|
16
|
-
!isBlank(item.value)) {
|
|
17
|
-
let dataType = item.getAttribute("data-type");
|
|
18
|
-
if (dataType === "number") {
|
|
19
|
-
value[item.name] = Number(item.value);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
value[item.name] = item.value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else if (item.tagName === "SELECT") {
|
|
26
|
-
value[item.name] = item.options[item.selectedIndex].value;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return value;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* 获取 url query 参数 (get 请求的参数)
|
|
34
|
-
* @param search 如果是 React 应用就需要传递 useLocation().search
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
export function query(search) {
|
|
38
|
-
if (isBlank(search)) {
|
|
39
|
-
search = location.search;
|
|
40
|
-
}
|
|
41
|
-
const searchParams = new URLSearchParams(search);
|
|
42
|
-
let query = {};
|
|
43
|
-
for (const [key, value] of searchParams) {
|
|
44
|
-
let oldValue = query[key];
|
|
45
|
-
let newValue = value;
|
|
46
|
-
if (oldValue != null) {
|
|
47
|
-
if (oldValue instanceof Array) {
|
|
48
|
-
oldValue.push(value);
|
|
49
|
-
newValue = oldValue;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
newValue = [value, oldValue];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
query[key] = newValue;
|
|
56
|
-
}
|
|
57
|
-
return query;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 函数节流 - 每隔单位时间,只执行一次
|
|
61
|
-
* @param cb 待节流的函数
|
|
62
|
-
* @param wait 间隔时间
|
|
63
|
-
* @returns
|
|
64
|
-
*/
|
|
65
|
-
export function throttle(fn, wait = 500) {
|
|
66
|
-
// 上一次的请求时间
|
|
67
|
-
let last = 0;
|
|
68
|
-
return (...args) => {
|
|
69
|
-
// 当前时间戳
|
|
70
|
-
const now = Date.now();
|
|
71
|
-
if (now - last > wait) {
|
|
72
|
-
fn(...args);
|
|
73
|
-
last = now;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 函数防抖 - 当重复触发某一个行为(事件时),只执行最后一次触发
|
|
79
|
-
* @param fn 防抖函数
|
|
80
|
-
* @param interval 间隔时间段
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
export function debounce(fn, interval = 500) {
|
|
84
|
-
let _t;
|
|
85
|
-
const handle = (...args) => {
|
|
86
|
-
if (_t)
|
|
87
|
-
clearTimeout(_t);
|
|
88
|
-
_t = setTimeout(() => {
|
|
89
|
-
//@ts-ignore
|
|
90
|
-
fn.apply(this, args);
|
|
91
|
-
}, interval);
|
|
92
|
-
};
|
|
93
|
-
handle.cancel = function () {
|
|
94
|
-
if (_t) {
|
|
95
|
-
clearTimeout(_t);
|
|
96
|
-
_t = null;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
return handle;
|
|
100
|
-
}
|