sculp-js 1.5.0 → 1.6.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.
- package/lib/cjs/array.js +2 -21
- package/lib/cjs/async.js +2 -2
- package/lib/cjs/base64.js +62 -0
- package/lib/cjs/clipboard.js +2 -2
- package/lib/cjs/cookie.js +2 -2
- package/lib/cjs/date.js +2 -3
- package/lib/cjs/dom.js +2 -2
- package/lib/cjs/download.js +4 -4
- package/lib/cjs/easing.js +2 -2
- package/lib/cjs/file.js +2 -2
- package/lib/cjs/func.js +3 -3
- package/lib/cjs/index.js +15 -5
- package/lib/cjs/math.js +88 -0
- package/lib/cjs/number.js +2 -2
- package/lib/cjs/object.js +10 -20
- package/lib/cjs/path.js +2 -2
- package/lib/cjs/qs.js +2 -2
- package/lib/cjs/random.js +2 -2
- package/lib/cjs/string.js +2 -2
- package/lib/cjs/tooltip.js +2 -2
- package/lib/cjs/tree.js +2 -2
- package/lib/cjs/type.js +68 -2
- package/lib/cjs/unique.js +2 -2
- package/lib/cjs/url.js +2 -2
- package/lib/cjs/watermark.js +2 -2
- package/lib/cjs/we-decode.js +2 -2
- package/lib/es/array.js +3 -21
- package/lib/es/async.js +2 -2
- package/lib/es/base64.js +59 -0
- package/lib/es/clipboard.js +2 -2
- package/lib/es/cookie.js +2 -2
- package/lib/es/date.js +2 -3
- package/lib/es/dom.js +2 -2
- package/lib/es/download.js +4 -4
- package/lib/es/easing.js +2 -2
- package/lib/es/file.js +2 -2
- package/lib/es/func.js +3 -3
- package/lib/es/index.js +8 -6
- package/lib/es/math.js +82 -0
- package/lib/es/number.js +2 -2
- package/lib/es/object.js +9 -18
- package/lib/es/path.js +2 -2
- package/lib/es/qs.js +2 -2
- package/lib/es/random.js +2 -2
- package/lib/es/string.js +2 -2
- package/lib/es/tooltip.js +2 -2
- package/lib/es/tree.js +2 -2
- package/lib/es/type.js +66 -3
- package/lib/es/unique.js +2 -2
- package/lib/es/url.js +2 -2
- package/lib/es/watermark.js +2 -2
- package/lib/es/we-decode.js +2 -2
- package/lib/index.d.ts +93 -16
- package/lib/umd/index.js +320 -151
- package/package.json +2 -2
package/lib/cjs/array.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var object = require('./object.js');
|
|
10
|
-
var type = require('./type.js');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 判断一个对象是否为类数组
|
|
14
|
-
*
|
|
15
|
-
* @param any
|
|
16
|
-
* @returns {boolean}
|
|
17
|
-
*/
|
|
18
|
-
function arrayLike(any) {
|
|
19
|
-
if (type.isArray(any))
|
|
20
|
-
return true;
|
|
21
|
-
if (type.isString(any))
|
|
22
|
-
return true;
|
|
23
|
-
if (!type.isObject(any))
|
|
24
|
-
return false;
|
|
25
|
-
return object.objectHas(any, 'length');
|
|
26
|
-
}
|
|
27
9
|
/**
|
|
28
10
|
* 遍历数组,返回 false 中断遍历(支持continue和break操作)
|
|
29
11
|
*
|
|
@@ -113,5 +95,4 @@ function arrayRemove(array, expect) {
|
|
|
113
95
|
exports.arrayEach = arrayEach;
|
|
114
96
|
exports.arrayEachAsync = arrayEachAsync;
|
|
115
97
|
exports.arrayInsertBefore = arrayInsertBefore;
|
|
116
|
-
exports.arrayLike = arrayLike;
|
|
117
98
|
exports.arrayRemove = arrayRemove;
|
package/lib/cjs/async.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var func = require('./func.js');
|
|
10
|
+
var type = require('./type.js');
|
|
11
|
+
var weDecode = require('./we-decode.js');
|
|
12
|
+
|
|
13
|
+
function stringToUint8Array(str) {
|
|
14
|
+
const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
|
|
15
|
+
const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
|
|
16
|
+
for (let i = 0; i < utf8.length; i++) {
|
|
17
|
+
uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
|
|
18
|
+
}
|
|
19
|
+
return uint8Array;
|
|
20
|
+
}
|
|
21
|
+
function uint8ArrayToString(uint8Array) {
|
|
22
|
+
const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
|
|
23
|
+
return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
|
|
27
|
+
* @param base64 base64编码的字符串
|
|
28
|
+
* @returns 原始字符串,包括中文内容
|
|
29
|
+
*/
|
|
30
|
+
function decodeFromBase64(base64) {
|
|
31
|
+
const binaryString = !type.isNullOrUnDef(func.getGlobal('atob')) ? func.getGlobal('atob')(base64) : weDecode.weAtob(base64);
|
|
32
|
+
const len = binaryString.length;
|
|
33
|
+
const bytes = new Uint8Array(len);
|
|
34
|
+
for (let i = 0; i < len; i++) {
|
|
35
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
36
|
+
}
|
|
37
|
+
// 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
|
|
38
|
+
return !type.isNullOrUnDef(func.getGlobal('TextDecoder'))
|
|
39
|
+
? new (func.getGlobal('TextDecoder'))('utf-8').decode(bytes)
|
|
40
|
+
: uint8ArrayToString(bytes);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
|
|
44
|
+
* @param rawStr 原始字符串,包括中文内容
|
|
45
|
+
* @returns base64编码的字符串
|
|
46
|
+
*/
|
|
47
|
+
function encodeToBase64(rawStr) {
|
|
48
|
+
const utf8Array = !type.isNullOrUnDef(func.getGlobal('TextEncoder'))
|
|
49
|
+
? new (func.getGlobal('TextEncoder'))().encode(rawStr)
|
|
50
|
+
: stringToUint8Array(rawStr);
|
|
51
|
+
// 将 Uint8Array 转换为二进制字符串
|
|
52
|
+
let binaryString = '';
|
|
53
|
+
const len = utf8Array.length;
|
|
54
|
+
for (let i = 0; i < len; i++) {
|
|
55
|
+
binaryString += String.fromCharCode(utf8Array[i]);
|
|
56
|
+
}
|
|
57
|
+
// 将二进制字符串转换为base64编码的字符串
|
|
58
|
+
return !type.isNullOrUnDef(func.getGlobal('btoa')) ? func.getGlobal('btoa')(binaryString) : weDecode.weBtoa(binaryString);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.decodeFromBase64 = decodeFromBase64;
|
|
62
|
+
exports.encodeToBase64 = encodeToBase64;
|
package/lib/cjs/clipboard.js
CHANGED
package/lib/cjs/cookie.js
CHANGED
package/lib/cjs/date.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -129,7 +129,6 @@ function dateToEnd(value) {
|
|
|
129
129
|
* - DD:日
|
|
130
130
|
* - dd: 日
|
|
131
131
|
* - HH:时(24 小时制)
|
|
132
|
-
* - hh:时(12 小时制)
|
|
133
132
|
* - mm:分
|
|
134
133
|
* - ss:秒
|
|
135
134
|
* - SSS:毫秒
|
package/lib/cjs/dom.js
CHANGED
package/lib/cjs/download.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -59,7 +59,7 @@ function downloadBlob(blob, filename, callback) {
|
|
|
59
59
|
* @param {string} filename
|
|
60
60
|
* @param {Function} callback
|
|
61
61
|
*/
|
|
62
|
-
function
|
|
62
|
+
function crossOriginDownload(url, filename, callback) {
|
|
63
63
|
const xhr = new XMLHttpRequest();
|
|
64
64
|
xhr.open('GET', url, true);
|
|
65
65
|
xhr.responseType = 'blob';
|
|
@@ -105,7 +105,7 @@ function downloadData(data, fileType, filename, headers) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
exports.
|
|
108
|
+
exports.crossOriginDownload = crossOriginDownload;
|
|
109
109
|
exports.downloadBlob = downloadBlob;
|
|
110
110
|
exports.downloadData = downloadData;
|
|
111
111
|
exports.downloadHref = downloadHref;
|
package/lib/cjs/easing.js
CHANGED
package/lib/cjs/file.js
CHANGED
package/lib/cjs/func.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -126,7 +126,7 @@ function setGlobal(key, val) {
|
|
|
126
126
|
throw new SyntaxError('当前环境下无法设置全局属性');
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
129
|
+
* 获取全局变量
|
|
130
130
|
* @param {string | number | symbol} key
|
|
131
131
|
* @param val
|
|
132
132
|
*/
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -27,14 +27,15 @@ var number = require('./number.js');
|
|
|
27
27
|
var unique = require('./unique.js');
|
|
28
28
|
var tooltip = require('./tooltip.js');
|
|
29
29
|
var tree = require('./tree.js');
|
|
30
|
+
var math = require('./math.js');
|
|
30
31
|
var weDecode = require('./we-decode.js');
|
|
32
|
+
var base64 = require('./base64.js');
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
exports.arrayEach = array.arrayEach;
|
|
35
37
|
exports.arrayEachAsync = array.arrayEachAsync;
|
|
36
38
|
exports.arrayInsertBefore = array.arrayInsertBefore;
|
|
37
|
-
exports.arrayLike = array.arrayLike;
|
|
38
39
|
exports.arrayRemove = array.arrayRemove;
|
|
39
40
|
exports.copyText = clipboard.copyText;
|
|
40
41
|
exports.cookieDel = cookie.cookieDel;
|
|
@@ -57,7 +58,7 @@ exports.onDomReady = dom.onDomReady;
|
|
|
57
58
|
exports.removeClass = dom.removeClass;
|
|
58
59
|
exports.setStyle = dom.setStyle;
|
|
59
60
|
exports.smoothScroll = dom.smoothScroll;
|
|
60
|
-
exports.
|
|
61
|
+
exports.crossOriginDownload = download.crossOriginDownload;
|
|
61
62
|
exports.downloadBlob = download.downloadBlob;
|
|
62
63
|
exports.downloadData = download.downloadData;
|
|
63
64
|
exports.downloadHref = download.downloadHref;
|
|
@@ -69,7 +70,6 @@ exports.objectEach = object.objectEach;
|
|
|
69
70
|
exports.objectEachAsync = object.objectEachAsync;
|
|
70
71
|
exports.objectFill = object.objectFill;
|
|
71
72
|
exports.objectGet = object.objectGet;
|
|
72
|
-
exports.objectHas = object.objectHas;
|
|
73
73
|
exports.objectMap = object.objectMap;
|
|
74
74
|
exports.objectMerge = object.objectAssign;
|
|
75
75
|
exports.objectOmit = object.objectOmit;
|
|
@@ -88,10 +88,12 @@ exports.stringEscapeHtml = string.stringEscapeHtml;
|
|
|
88
88
|
exports.stringFill = string.stringFill;
|
|
89
89
|
exports.stringFormat = string.stringFormat;
|
|
90
90
|
exports.stringKebabCase = string.stringKebabCase;
|
|
91
|
+
exports.arrayLike = type.arrayLike;
|
|
91
92
|
exports.isArray = type.isArray;
|
|
92
93
|
exports.isBigInt = type.isBigInt;
|
|
93
94
|
exports.isBoolean = type.isBoolean;
|
|
94
95
|
exports.isDate = type.isDate;
|
|
96
|
+
exports.isEmpty = type.isEmpty;
|
|
95
97
|
exports.isError = type.isError;
|
|
96
98
|
exports.isFunction = type.isFunction;
|
|
97
99
|
exports.isJsonString = type.isJsonString;
|
|
@@ -105,6 +107,7 @@ exports.isRegExp = type.isRegExp;
|
|
|
105
107
|
exports.isString = type.isString;
|
|
106
108
|
exports.isSymbol = type.isSymbol;
|
|
107
109
|
exports.isUndefined = type.isUndefined;
|
|
110
|
+
exports.objectHas = type.objectHas;
|
|
108
111
|
exports.typeIs = type.typeIs;
|
|
109
112
|
exports.urlDelParams = url.urlDelParams;
|
|
110
113
|
exports.urlParse = url.urlParse;
|
|
@@ -140,5 +143,12 @@ exports.forEachMap = tree.forEachMap;
|
|
|
140
143
|
exports.formatTree = tree.formatTree;
|
|
141
144
|
exports.fuzzySearchTree = tree.fuzzySearchTree;
|
|
142
145
|
exports.searchTreeById = tree.searchTreeById;
|
|
146
|
+
exports.add = math.add;
|
|
147
|
+
exports.divide = math.divide;
|
|
148
|
+
exports.multiply = math.multiply;
|
|
149
|
+
exports.strip = math.strip;
|
|
150
|
+
exports.subtract = math.subtract;
|
|
143
151
|
exports.weAtob = weDecode.weAtob;
|
|
144
152
|
exports.weBtoa = weDecode.weBtoa;
|
|
153
|
+
exports.decodeFromBase64 = base64.decodeFromBase64;
|
|
154
|
+
exports.encodeToBase64 = base64.encodeToBase64;
|
package/lib/cjs/math.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 数值安全乘法
|
|
11
|
+
* @param arg1 数值1
|
|
12
|
+
* @param arg2 数值2
|
|
13
|
+
*/
|
|
14
|
+
const multiply = (arg1, arg2) => {
|
|
15
|
+
let m = 0;
|
|
16
|
+
const s1 = arg1.toString();
|
|
17
|
+
const s2 = arg2.toString();
|
|
18
|
+
if (s1.split('.')[1] !== undefined)
|
|
19
|
+
m += s1.split('.')[1].length;
|
|
20
|
+
if (s2.split('.')[1] !== undefined)
|
|
21
|
+
m += s2.split('.')[1].length;
|
|
22
|
+
return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 数值安全加法
|
|
26
|
+
* @param arg1 数值1
|
|
27
|
+
* @param arg2 数值2
|
|
28
|
+
*/
|
|
29
|
+
const add = (arg1, arg2) => {
|
|
30
|
+
let r1 = 0;
|
|
31
|
+
let r2 = 0;
|
|
32
|
+
let m = 0;
|
|
33
|
+
try {
|
|
34
|
+
r1 = arg1.toString().split('.')[1].length;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
r1 = 0;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
r2 = arg2.toString().split('.')[1].length;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
r2 = 0;
|
|
44
|
+
}
|
|
45
|
+
m = 10 ** Math.max(r1, r2);
|
|
46
|
+
return (multiply(arg1, m) + multiply(arg2, m)) / m;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 数值安全减法
|
|
50
|
+
* @param arg1 数值1
|
|
51
|
+
* @param arg2 数值2
|
|
52
|
+
*/
|
|
53
|
+
const subtract = (arg1, arg2) => add(arg1, -arg2);
|
|
54
|
+
/**
|
|
55
|
+
* 数值安全除法
|
|
56
|
+
* @param arg1 数值1
|
|
57
|
+
* @param arg2 数值2
|
|
58
|
+
*/
|
|
59
|
+
const divide = (arg1, arg2) => {
|
|
60
|
+
let t1 = 0;
|
|
61
|
+
let t2 = 0;
|
|
62
|
+
let r1 = 0;
|
|
63
|
+
let r2 = 0;
|
|
64
|
+
if (arg1.toString().split('.')[1] !== undefined)
|
|
65
|
+
t1 = arg1.toString().split('.')[1].length;
|
|
66
|
+
if (arg2.toString().split('.')[1] !== undefined)
|
|
67
|
+
t2 = arg2.toString().split('.')[1].length;
|
|
68
|
+
r1 = Number(arg1.toString().replace('.', ''));
|
|
69
|
+
r2 = Number(arg2.toString().replace('.', ''));
|
|
70
|
+
return (r1 / r2) * Math.pow(10, t2 - t1);
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Correct the given number to specifying significant digits.
|
|
74
|
+
*
|
|
75
|
+
* @param num The input number
|
|
76
|
+
* @param precision An integer specifying the number of significant digits
|
|
77
|
+
*
|
|
78
|
+
* @example strip(0.09999999999999998) === 0.1 // true
|
|
79
|
+
*/
|
|
80
|
+
function strip(num, precision = 15) {
|
|
81
|
+
return +parseFloat(Number(num).toPrecision(precision));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
exports.add = add;
|
|
85
|
+
exports.divide = divide;
|
|
86
|
+
exports.multiply = multiply;
|
|
87
|
+
exports.strip = strip;
|
|
88
|
+
exports.subtract = subtract;
|
package/lib/cjs/number.js
CHANGED
package/lib/cjs/object.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -23,15 +23,6 @@ const isPlainObject = (obj) => {
|
|
|
23
23
|
// 是否对象直接实例
|
|
24
24
|
return proto === Object.prototype;
|
|
25
25
|
};
|
|
26
|
-
/**
|
|
27
|
-
* 判断对象内是否有该静态属性
|
|
28
|
-
* @param {object} obj
|
|
29
|
-
* @param {string} key
|
|
30
|
-
* @returns {boolean}
|
|
31
|
-
*/
|
|
32
|
-
function objectHas(obj, key) {
|
|
33
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
34
|
-
}
|
|
35
26
|
/**
|
|
36
27
|
* 遍历对象,返回 false 中断遍历
|
|
37
28
|
* @param {O} obj
|
|
@@ -39,7 +30,7 @@ function objectHas(obj, key) {
|
|
|
39
30
|
*/
|
|
40
31
|
function objectEach(obj, iterator) {
|
|
41
32
|
for (const key in obj) {
|
|
42
|
-
if (!objectHas(obj, key))
|
|
33
|
+
if (!type.objectHas(obj, key))
|
|
43
34
|
continue;
|
|
44
35
|
if (iterator(obj[key], key) === false)
|
|
45
36
|
break;
|
|
@@ -52,7 +43,7 @@ function objectEach(obj, iterator) {
|
|
|
52
43
|
*/
|
|
53
44
|
async function objectEachAsync(obj, iterator) {
|
|
54
45
|
for (const key in obj) {
|
|
55
|
-
if (!objectHas(obj, key))
|
|
46
|
+
if (!type.objectHas(obj, key))
|
|
56
47
|
continue;
|
|
57
48
|
if ((await iterator(obj[key], key)) === false)
|
|
58
49
|
break;
|
|
@@ -67,7 +58,7 @@ async function objectEachAsync(obj, iterator) {
|
|
|
67
58
|
function objectMap(obj, iterator) {
|
|
68
59
|
const obj2 = {};
|
|
69
60
|
for (const key in obj) {
|
|
70
|
-
if (!objectHas(obj, key))
|
|
61
|
+
if (!type.objectHas(obj, key))
|
|
71
62
|
continue;
|
|
72
63
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
73
64
|
obj2[key] = iterator(obj[key], key);
|
|
@@ -185,23 +176,23 @@ function objectGet(obj, path, strict = false) {
|
|
|
185
176
|
let i = 0;
|
|
186
177
|
for (let len = keyArr.length; i < len - 1; ++i) {
|
|
187
178
|
const key = keyArr[i];
|
|
188
|
-
if (key
|
|
189
|
-
|
|
179
|
+
if (type.isNumber(Number(key)) && Array.isArray(tempObj)) {
|
|
180
|
+
tempObj = tempObj[key];
|
|
181
|
+
}
|
|
182
|
+
else if (type.isObject(tempObj) && type.objectHas(tempObj, key)) {
|
|
190
183
|
tempObj = tempObj[key];
|
|
191
184
|
}
|
|
192
185
|
else {
|
|
193
186
|
tempObj = undefined;
|
|
194
187
|
if (strict) {
|
|
195
|
-
throw new Error('[
|
|
188
|
+
throw new Error('[Object] objectGet path 路径不正确');
|
|
196
189
|
}
|
|
197
190
|
break;
|
|
198
191
|
}
|
|
199
192
|
}
|
|
200
193
|
return {
|
|
201
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
202
194
|
p: tempObj,
|
|
203
195
|
k: tempObj ? keyArr[i] : undefined,
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
205
196
|
v: tempObj ? tempObj[keyArr[i]] : undefined
|
|
206
197
|
};
|
|
207
198
|
}
|
|
@@ -236,7 +227,6 @@ exports.objectEach = objectEach;
|
|
|
236
227
|
exports.objectEachAsync = objectEachAsync;
|
|
237
228
|
exports.objectFill = objectFill;
|
|
238
229
|
exports.objectGet = objectGet;
|
|
239
|
-
exports.objectHas = objectHas;
|
|
240
230
|
exports.objectMap = objectMap;
|
|
241
231
|
exports.objectMerge = objectAssign;
|
|
242
232
|
exports.objectOmit = objectOmit;
|
package/lib/cjs/path.js
CHANGED
package/lib/cjs/qs.js
CHANGED
package/lib/cjs/random.js
CHANGED
package/lib/cjs/string.js
CHANGED
package/lib/cjs/tooltip.js
CHANGED
package/lib/cjs/tree.js
CHANGED
package/lib/cjs/type.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.6.1
|
|
3
|
+
* (c) 2023-2025 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -8,6 +8,31 @@
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
10
10
|
|
|
11
|
+
// 常用类型定义
|
|
12
|
+
/**
|
|
13
|
+
* 判断对象内是否有该静态属性
|
|
14
|
+
* @param {object} obj
|
|
15
|
+
* @param {string} key
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
function objectHas(obj, key) {
|
|
19
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 判断一个对象是否为类数组
|
|
23
|
+
*
|
|
24
|
+
* @param any
|
|
25
|
+
* @returns {boolean}
|
|
26
|
+
*/
|
|
27
|
+
function arrayLike(any) {
|
|
28
|
+
if (isArray(any))
|
|
29
|
+
return true;
|
|
30
|
+
if (isString(any))
|
|
31
|
+
return true;
|
|
32
|
+
if (!isObject(any))
|
|
33
|
+
return false;
|
|
34
|
+
return objectHas(any, 'length');
|
|
35
|
+
}
|
|
11
36
|
/**
|
|
12
37
|
* 判断任意值的数据类型
|
|
13
38
|
* @param {unknown} any
|
|
@@ -54,12 +79,52 @@ function isJsonString(str) {
|
|
|
54
79
|
return false;
|
|
55
80
|
}
|
|
56
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks if `value` is an empty object, collection, map, or set.
|
|
84
|
+
*
|
|
85
|
+
* Objects are considered empty if they have no own enumerable string keyed
|
|
86
|
+
* properties.
|
|
87
|
+
*
|
|
88
|
+
* Array-like values such as `arguments` objects, arrays, buffers, strings, or
|
|
89
|
+
* jQuery-like collections are considered empty if they have a `length` of `0`.
|
|
90
|
+
* Similarly, maps and sets are considered empty if they have a `size` of `0`.
|
|
91
|
+
*
|
|
92
|
+
* @param {*} value The value to check.
|
|
93
|
+
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
|
94
|
+
* @example
|
|
95
|
+
*
|
|
96
|
+
* _.isEmpty(null);
|
|
97
|
+
* // => true
|
|
98
|
+
*
|
|
99
|
+
* _.isEmpty(true);
|
|
100
|
+
* // => true
|
|
101
|
+
*
|
|
102
|
+
* _.isEmpty(1);
|
|
103
|
+
* // => true
|
|
104
|
+
*
|
|
105
|
+
* _.isEmpty([1, 2, 3]);
|
|
106
|
+
* // => false
|
|
107
|
+
*
|
|
108
|
+
* _.isEmpty({ 'a': 1 });
|
|
109
|
+
* // => false
|
|
110
|
+
*/
|
|
111
|
+
function isEmpty(value) {
|
|
112
|
+
if (isNullOrUnDef(value) || Number.isNaN(value)) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (arrayLike(value) && (isArray(value) || isString(value) || isFunction(value.splice))) {
|
|
116
|
+
return !value.length;
|
|
117
|
+
}
|
|
118
|
+
return !Object.keys(value).length;
|
|
119
|
+
}
|
|
57
120
|
|
|
121
|
+
exports.arrayLike = arrayLike;
|
|
58
122
|
exports.default = typeIs;
|
|
59
123
|
exports.isArray = isArray;
|
|
60
124
|
exports.isBigInt = isBigInt;
|
|
61
125
|
exports.isBoolean = isBoolean;
|
|
62
126
|
exports.isDate = isDate;
|
|
127
|
+
exports.isEmpty = isEmpty;
|
|
63
128
|
exports.isError = isError;
|
|
64
129
|
exports.isFunction = isFunction;
|
|
65
130
|
exports.isJsonString = isJsonString;
|
|
@@ -73,4 +138,5 @@ exports.isRegExp = isRegExp;
|
|
|
73
138
|
exports.isString = isString;
|
|
74
139
|
exports.isSymbol = isSymbol;
|
|
75
140
|
exports.isUndefined = isUndefined;
|
|
141
|
+
exports.objectHas = objectHas;
|
|
76
142
|
exports.typeIs = typeIs;
|
package/lib/cjs/unique.js
CHANGED
package/lib/cjs/url.js
CHANGED
package/lib/cjs/watermark.js
CHANGED
package/lib/cjs/we-decode.js
CHANGED