sculp-js 1.5.1 → 1.7.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.
Files changed (61) hide show
  1. package/README.md +10 -1
  2. package/lib/cjs/array.js +2 -21
  3. package/lib/cjs/async.js +2 -2
  4. package/lib/cjs/base64.js +62 -0
  5. package/lib/cjs/clipboard.js +2 -2
  6. package/lib/cjs/cookie.js +2 -2
  7. package/lib/cjs/date.js +2 -3
  8. package/lib/cjs/dom.js +2 -2
  9. package/lib/cjs/download.js +2 -2
  10. package/lib/cjs/easing.js +2 -2
  11. package/lib/cjs/file.js +2 -2
  12. package/lib/cjs/func.js +3 -3
  13. package/lib/cjs/index.js +37 -4
  14. package/lib/cjs/math.js +88 -0
  15. package/lib/cjs/number.js +2 -2
  16. package/lib/cjs/object.js +10 -20
  17. package/lib/cjs/path.js +2 -2
  18. package/lib/cjs/qs.js +2 -2
  19. package/lib/cjs/random.js +2 -2
  20. package/lib/cjs/string.js +3 -3
  21. package/lib/cjs/tooltip.js +2 -2
  22. package/lib/cjs/tree.js +4 -4
  23. package/lib/cjs/type.js +69 -3
  24. package/lib/cjs/unique.js +2 -2
  25. package/lib/cjs/url.js +2 -2
  26. package/lib/cjs/validator.js +147 -0
  27. package/lib/cjs/variable.js +118 -0
  28. package/lib/cjs/watermark.js +2 -2
  29. package/lib/cjs/we-decode.js +4 -4
  30. package/lib/es/array.js +3 -21
  31. package/lib/es/async.js +2 -2
  32. package/lib/es/base64.js +59 -0
  33. package/lib/es/clipboard.js +2 -2
  34. package/lib/es/cookie.js +2 -2
  35. package/lib/es/date.js +2 -3
  36. package/lib/es/dom.js +2 -2
  37. package/lib/es/download.js +2 -2
  38. package/lib/es/easing.js +2 -2
  39. package/lib/es/file.js +2 -2
  40. package/lib/es/func.js +3 -3
  41. package/lib/es/index.js +9 -5
  42. package/lib/es/math.js +82 -0
  43. package/lib/es/number.js +2 -2
  44. package/lib/es/object.js +9 -18
  45. package/lib/es/path.js +2 -2
  46. package/lib/es/qs.js +2 -2
  47. package/lib/es/random.js +2 -2
  48. package/lib/es/string.js +3 -3
  49. package/lib/es/tooltip.js +2 -2
  50. package/lib/es/tree.js +4 -4
  51. package/lib/es/type.js +67 -4
  52. package/lib/es/unique.js +2 -2
  53. package/lib/es/url.js +2 -2
  54. package/lib/es/validator.js +130 -0
  55. package/lib/es/variable.js +112 -0
  56. package/lib/es/watermark.js +2 -2
  57. package/lib/es/we-decode.js +4 -4
  58. package/lib/index.d.ts +236 -21
  59. package/lib/tsdoc-metadata.json +11 -0
  60. package/lib/umd/index.js +571 -155
  61. package/package.json +2 -2
package/lib/cjs/type.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present 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
@@ -43,7 +68,7 @@ const isRegExp = (any) => typeIs(any) === 'RegExp';
43
68
  /**
44
69
  * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
45
70
  * @param {string} str
46
- * @return {Object | boolean}
71
+ * @returns {Object | boolean}
47
72
  */
48
73
  function isJsonString(str) {
49
74
  try {
@@ -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
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
package/lib/cjs/url.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -0,0 +1,147 @@
1
+ /*!
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
+ * Released under the MIT License.
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ // 邮箱
10
+ const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
11
+ /**
12
+ * 判断字符串是否为邮箱格式,不对邮箱真实性做验证,如域名是否正确等
13
+ * @param {string} value
14
+ * @returns {boolean}
15
+ */
16
+ const isEmail = (value) => EMAIL_REGEX.test(value);
17
+ // 手机号码 (中国大陆)
18
+ // reference: https://www.runoob.com/regexp/regexp-syntax.html (?: 是非捕获元之一)
19
+ const PHONE_REGEX = /^(?:(?:\+|00)86)?1\d{10}$/;
20
+ /**
21
+ * 判断字符串是否为宽松手机格式,即首位为 1 的 11 位数字都属于手机号
22
+ * @param {string} value
23
+ * @returns {boolean}
24
+ */
25
+ const isPhone = (value) => PHONE_REGEX.test(value);
26
+ // 身份证号码
27
+ // http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/
28
+ // ["北京市", "天津市", "河北省", "山西省", "内蒙古自治区",
29
+ // "辽宁省", "吉林省", "黑龙江省",
30
+ // "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省",
31
+ // "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省",
32
+ // "重庆市", "四川省", "贵州省", "云南省", "西藏自治区",
33
+ // "陕西省", "甘肃省", "青海省","宁夏回族自治区", "新疆维吾尔自治区",
34
+ // "台湾省",
35
+ // "香港特别行政区", "澳门特别行政区"]
36
+ // ["11", "12", "13", "14", "15",
37
+ // "21", "22", "23",
38
+ // "31", "32", "33", "34", "35", "36", "37",
39
+ // "41", "42", "43", "44", "45", "46",
40
+ // "50", "51", "52", "53", "54",
41
+ // "61", "62", "63", "64", "65",
42
+ // "71",
43
+ // "81", "82"]
44
+ // 91 国外
45
+ const IDNO_RE = /^(1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|7[1]|8[1-2]|9[1])\d{4}(18|19|20)\d{2}[01]\d[0123]\d{4}[\dxX]$/;
46
+ /**
47
+ * 判断字符串是否为身份证号码格式
48
+ * @param {string} value
49
+ * @returns {boolean}
50
+ */
51
+ const isIdNo = (value) => {
52
+ const isSameFormat = IDNO_RE.test(value);
53
+ if (!isSameFormat)
54
+ return false;
55
+ const year = Number(value.slice(6, 10));
56
+ const month = Number(value.slice(10, 12));
57
+ const date = Number(value.slice(12, 14));
58
+ const d = new Date(year, month - 1, date);
59
+ const isSameDate = d.getFullYear() === year && d.getMonth() + 1 === month && d.getDate() === date;
60
+ if (!isSameDate)
61
+ return false;
62
+ // 将身份证号码前面的17位数分别乘以不同的系数;
63
+ // 从第一位到第十七位的系数分别为:7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2
64
+ // 将这17位数字和系数相乘的结果相加;
65
+ // 用加出来和除以11,看余数是多少;
66
+ // 余数只可能有0-1-2-3-4-5-6-7-8-9-10这11个数字;
67
+ // 其分别对应的最后一位身份证的号码为1-0-X-9-8-7-6-5-4-3-2
68
+ // 通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
69
+ const coefficientList = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
70
+ const residueList = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
71
+ let sum = 0;
72
+ for (let start = 0; start < 17; start++) {
73
+ sum += Number(value.slice(start, start + 1)) * coefficientList[start];
74
+ }
75
+ return residueList[sum % 11] === value.slice(-1);
76
+ };
77
+ const URL_REGEX = /^(https?|ftp):\/\/([^\s/$.?#].[^\s]*)$/i;
78
+ const HTTP_URL_REGEX = /^https?:\/\/([^\s/$.?#].[^\s]*)$/i;
79
+ /**
80
+ * 判断字符串是否为 url 格式,支持 http、https、ftp 协议,支持域名或者 ipV4
81
+ * @param {string} value
82
+ * @returns {boolean}
83
+ */
84
+ const isUrl = (url, includeFtp = false) => {
85
+ const regex = includeFtp ? URL_REGEX : HTTP_URL_REGEX;
86
+ return regex.test(url);
87
+ };
88
+ // ipv4
89
+ const IPV4_REGEX = /^(?:(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/;
90
+ // ipv6
91
+ const IPV6_REGEX = /^(([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}|([\da-fA-F]{1,4}:){1,7}:|([\da-fA-F]{1,4}:){1,6}:[\da-fA-F]{1,4}|([\da-fA-F]{1,4}:){1,5}(:[\da-fA-F]{1,4}){1,2}|([\da-fA-F]{1,4}:){1,4}(:[\da-fA-F]{1,4}){1,3}|([\da-fA-F]{1,4}:){1,3}(:[\da-fA-F]{1,4}){1,4}|([\da-fA-F]{1,4}:){1,2}(:[\da-fA-F]{1,4}){1,5}|[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,6})|:((:[\da-fA-F]{1,4}){1,7}|:)|fe80:(:[\da-fA-F]{0,4}){0,4}%[\da-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d)|([\da-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d))$/i;
92
+ /**
93
+ * 判断字符串是否为 IPV4 格式,不对 ip 真实性做验证
94
+ * @param {string} value
95
+ * @returns {boolean}
96
+ */
97
+ const isIpV4 = (value) => IPV4_REGEX.test(value);
98
+ /**
99
+ * 判断字符串是否为 IPV6 格式,不对 ip 真实性做验证
100
+ * @param {string} value
101
+ * @returns {boolean}
102
+ */
103
+ const isIpV6 = (value) => IPV6_REGEX.test(value);
104
+ const INTEGER_RE = /^(-?[1-9]\d*|0)$/;
105
+ /**
106
+ * 判断字符串是否为整数(自然数),即 ...,-3,-2,-1,0,1,2,3,...
107
+ * @param {string} value
108
+ * @returns {boolean}
109
+ */
110
+ const isInteger = (value) => INTEGER_RE.test(value);
111
+ const FLOAT_RE = /^-?([1-9]\d*|0)\.\d*[1-9]$/;
112
+ /**
113
+ * 判断字符串是否为浮点数,即必须有小数点的有理数
114
+ * @param {string} value
115
+ * @returns {boolean}
116
+ */
117
+ const isFloat = (value) => FLOAT_RE.test(value);
118
+ /**
119
+ * 判断字符串是否为正确数值,包括整数和浮点数
120
+ * @param {string} value
121
+ * @returns {boolean}
122
+ */
123
+ const isNumerical = (value) => isInteger(value) || isFloat(value);
124
+ const DIGIT_RE = /^\d+$/;
125
+ /**
126
+ * 判断字符串是否为数字,例如六位数字短信验证码(093031)
127
+ * @param {string} value
128
+ * @returns {boolean}
129
+ */
130
+ const isDigit = (value) => DIGIT_RE.test(value);
131
+
132
+ exports.EMAIL_REGEX = EMAIL_REGEX;
133
+ exports.HTTP_URL_REGEX = HTTP_URL_REGEX;
134
+ exports.IPV4_REGEX = IPV4_REGEX;
135
+ exports.IPV6_REGEX = IPV6_REGEX;
136
+ exports.PHONE_REGEX = PHONE_REGEX;
137
+ exports.URL_REGEX = URL_REGEX;
138
+ exports.isDigit = isDigit;
139
+ exports.isEmail = isEmail;
140
+ exports.isFloat = isFloat;
141
+ exports.isIdNo = isIdNo;
142
+ exports.isInteger = isInteger;
143
+ exports.isIpV4 = isIpV4;
144
+ exports.isIpV6 = isIpV6;
145
+ exports.isNumerical = isNumerical;
146
+ exports.isPhone = isPhone;
147
+ exports.isUrl = isUrl;
@@ -0,0 +1,118 @@
1
+ /*!
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
+ * Released under the MIT License.
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ var type = require('./type.js');
10
+
11
+ /**
12
+ * 去除字符串中重复字符
13
+ * @param {string} str
14
+ * @returns string
15
+ * @example
16
+ *
17
+ * uniqueSymbol('1a1bac');
18
+ * // => '1abc'
19
+ */
20
+ function uniqueSymbol(str) {
21
+ return [...new Set(str.trim().split(''))].join('');
22
+ }
23
+ /**
24
+ * 转义所有特殊字符
25
+ * @param {string} str 原字符串
26
+ * reference: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions
27
+ * @returns string
28
+ */
29
+ function escapeRegExp(str) {
30
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); //$&表示整个被匹配的字符串
31
+ }
32
+ /**
33
+ * 根据左右匹配符号生产解析变量(自动删除变量内的空白)
34
+ * @param {string} leftMatchSymbol
35
+ * @param {string} rightMatchSymbol
36
+ * @returns RegExp
37
+ */
38
+ function parseVariableRegExp(leftMatchSymbol, rightMatchSymbol) {
39
+ return new RegExp(`${escapeRegExp(leftMatchSymbol.trim())}\\s*([^${escapeRegExp(uniqueSymbol(leftMatchSymbol))}${escapeRegExp(uniqueSymbol(rightMatchSymbol))}\\s]*)\\s*${rightMatchSymbol.trim()}`, 'g');
40
+ }
41
+ /**
42
+ * 解析字符串的插值变量
43
+ * @param {string} str 字符串
44
+ * @param {string} leftMatchSymbol 变量左侧匹配符号,默认:{
45
+ * @param {string} rightMatchSymbol 变量右侧匹配符号,默认:}
46
+ * @returns string[]
47
+ * @example
48
+ *
49
+ * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
50
+ */
51
+ function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}') {
52
+ return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => el?.[1]);
53
+ }
54
+ /**
55
+ * 替换字符串中的插值变量
56
+ * @param {string} sourceStr
57
+ * @param {Record<string, any>} targetObj
58
+ * @param {string} leftMatchSymbol 变量左侧匹配符号,默认:{
59
+ * @param {string} rightMatchSymbol 变量右侧匹配符号,默认:}
60
+ * @returns string
61
+ */
62
+ function replaceVarFromString(sourceStr, targetObj, leftMatchSymbol = '{', rightMatchSymbol = '}') {
63
+ return sourceStr.replace(new RegExp(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol)), function (m, p1) {
64
+ return type.objectHas(targetObj, p1) ? targetObj[p1] : m;
65
+ });
66
+ }
67
+ /**
68
+ * 在指定作用域中执行代码
69
+ * @param {string} code 要执行的代码(需包含 return 语句或表达式)
70
+ * @param {Object} scope 作用域对象(键值对形式的变量环境)
71
+ * @returns 代码执行结果
72
+ *
73
+ * @example
74
+ * // 测试用例 1: 基本变量访问
75
+ * executeInScope("return a + b;", { a: 1, b: 2 });
76
+ * // 3
77
+ *
78
+ * // 测试用例 2: 支持复杂表达式和运算
79
+ * executeInScope(
80
+ * "return Array.from({ length: 3 }, (_, i) => base + i);",
81
+ * { base: 100 }
82
+ * );
83
+ * // [100, 101, 102]
84
+ *
85
+ * // 支持外传函数作用域执行
86
+ * const scope = {
87
+ * $: {
88
+ * fun: {
89
+ * time: {
90
+ * now: function () {
91
+ * return new Date();
92
+ * },
93
+ * },
94
+ * },
95
+ * },
96
+ * };
97
+ * executeInScope("return $.fun.time.now()", scope)
98
+ */
99
+ function executeInScope(code, scope = {}) {
100
+ // 提取作用域对象的键和值
101
+ const keys = Object.keys(scope);
102
+ const values = keys.map(key => scope[key]);
103
+ try {
104
+ // 动态创建函数,将作用域的键作为参数,代码作为函数体
105
+ const func = new Function(...keys, `return (() => { ${code} })()`);
106
+ // 调用函数并传入作用域的值
107
+ return func(...values);
108
+ }
109
+ catch (error) {
110
+ throw new Error(`代码执行失败: ${error.message}`);
111
+ }
112
+ }
113
+
114
+ exports.escapeRegExp = escapeRegExp;
115
+ exports.executeInScope = executeInScope;
116
+ exports.parseVarFromString = parseVarFromString;
117
+ exports.replaceVarFromString = replaceVarFromString;
118
+ exports.uniqueSymbol = uniqueSymbol;
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -12,7 +12,7 @@ const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3
12
12
  /**
13
13
  * 字符串编码成Base64 (适用于任何环境,包括小程序)
14
14
  * @param {string} string
15
- * @return {string}
15
+ * @returns {string}
16
16
  */
17
17
  function weBtoa(string) {
18
18
  // 同window.btoa: 字符串编码成Base64
@@ -34,7 +34,7 @@ function weBtoa(string) {
34
34
  /**
35
35
  * Base64解码为原始字符串(适用于任何环境,包括小程序)
36
36
  * @param {string} string
37
- * @return {string}
37
+ * @returns {string}
38
38
  */
39
39
  function weAtob(string) {
40
40
  // 同window.atob: Base64解码为原始字符串
package/lib/es/array.js CHANGED
@@ -1,27 +1,9 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { objectHas } from './object.js';
8
- import { isArray, isString, isObject } from './type.js';
9
-
10
- /**
11
- * 判断一个对象是否为类数组
12
- *
13
- * @param any
14
- * @returns {boolean}
15
- */
16
- function arrayLike(any) {
17
- if (isArray(any))
18
- return true;
19
- if (isString(any))
20
- return true;
21
- if (!isObject(any))
22
- return false;
23
- return objectHas(any, 'length');
24
- }
25
7
  /**
26
8
  * 遍历数组,返回 false 中断遍历(支持continue和break操作)
27
9
  *
@@ -108,4 +90,4 @@ function arrayRemove(array, expect) {
108
90
  return array;
109
91
  }
110
92
 
111
- export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove };
93
+ export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayRemove };
package/lib/es/async.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -0,0 +1,59 @@
1
+ /*!
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
+ * Released under the MIT License.
5
+ */
6
+
7
+ import { getGlobal } from './func.js';
8
+ import { isNullOrUnDef } from './type.js';
9
+ import { weAtob, weBtoa } from './we-decode.js';
10
+
11
+ function stringToUint8Array(str) {
12
+ const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
13
+ const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
14
+ for (let i = 0; i < utf8.length; i++) {
15
+ uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
16
+ }
17
+ return uint8Array;
18
+ }
19
+ function uint8ArrayToString(uint8Array) {
20
+ const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
21
+ return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
22
+ }
23
+ /**
24
+ * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
25
+ * @param base64 base64编码的字符串
26
+ * @returns 原始字符串,包括中文内容
27
+ */
28
+ function decodeFromBase64(base64) {
29
+ const binaryString = !isNullOrUnDef(getGlobal('atob')) ? getGlobal('atob')(base64) : weAtob(base64);
30
+ const len = binaryString.length;
31
+ const bytes = new Uint8Array(len);
32
+ for (let i = 0; i < len; i++) {
33
+ bytes[i] = binaryString.charCodeAt(i);
34
+ }
35
+ // 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
36
+ return !isNullOrUnDef(getGlobal('TextDecoder'))
37
+ ? new (getGlobal('TextDecoder'))('utf-8').decode(bytes)
38
+ : uint8ArrayToString(bytes);
39
+ }
40
+ /**
41
+ * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
42
+ * @param rawStr 原始字符串,包括中文内容
43
+ * @returns base64编码的字符串
44
+ */
45
+ function encodeToBase64(rawStr) {
46
+ const utf8Array = !isNullOrUnDef(getGlobal('TextEncoder'))
47
+ ? new (getGlobal('TextEncoder'))().encode(rawStr)
48
+ : stringToUint8Array(rawStr);
49
+ // 将 Uint8Array 转换为二进制字符串
50
+ let binaryString = '';
51
+ const len = utf8Array.length;
52
+ for (let i = 0; i < len; i++) {
53
+ binaryString += String.fromCharCode(utf8Array[i]);
54
+ }
55
+ // 将二进制字符串转换为base64编码的字符串
56
+ return !isNullOrUnDef(getGlobal('btoa')) ? getGlobal('btoa')(binaryString) : weBtoa(binaryString);
57
+ }
58
+
59
+ export { decodeFromBase64, encodeToBase64 };
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
package/lib/es/cookie.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
package/lib/es/date.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -127,7 +127,6 @@ function dateToEnd(value) {
127
127
  * - DD:日
128
128
  * - dd: 日
129
129
  * - HH:时(24 小时制)
130
- * - hh:时(12 小时制)
131
130
  * - mm:分
132
131
  * - ss:秒
133
132
  * - SSS:毫秒
package/lib/es/dom.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
package/lib/es/easing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
package/lib/es/file.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
package/lib/es/func.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
@@ -124,7 +124,7 @@ function setGlobal(key, val) {
124
124
  throw new SyntaxError('当前环境下无法设置全局属性');
125
125
  }
126
126
  /**
127
- * 设置全局变量
127
+ * 获取全局变量
128
128
  * @param {string | number | symbol} key
129
129
  * @param val
130
130
  */
package/lib/es/index.js CHANGED
@@ -1,20 +1,20 @@
1
1
  /*!
2
- * sculp-js v1.5.0
3
- * (c) 2023-2024 chandq
2
+ * sculp-js v1.7.0
3
+ * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove } from './array.js';
7
+ export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayRemove } from './array.js';
8
8
  export { copyText } from './clipboard.js';
9
9
  export { cookieDel, cookieGet, cookieSet } from './cookie.js';
10
10
  export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.js';
11
11
  export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
12
12
  export { crossOriginDownload, downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
13
- export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
13
+ export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
14
14
  export { pathJoin, pathNormalize } from './path.js';
15
15
  export { qsParse, qsStringify } from './qs.js';
16
16
  export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, parseQueryParams, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
17
- export { isArray, isBigInt, isBoolean, isDate, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs } from './type.js';
17
+ export { arrayLike, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs } from './type.js';
18
18
  export { urlDelParams, urlParse, urlSetParams, urlStringify } from './url.js';
19
19
  export { asyncMap, wait } from './async.js';
20
20
  export { chooseLocalFile, compressImg, supportCanvas } from './file.js';
@@ -25,4 +25,8 @@ export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
25
25
  export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
26
26
  export { tooltipEvent } from './tooltip.js';
27
27
  export { buildTree, flatTree, forEachDeep, forEachMap, formatTree, fuzzySearchTree, searchTreeById } from './tree.js';
28
+ export { add, divide, multiply, strip, subtract } from './math.js';
28
29
  export { weAtob, weBtoa } from './we-decode.js';
30
+ export { decodeFromBase64, encodeToBase64 } from './base64.js';
31
+ export { EMAIL_REGEX, HTTP_URL_REGEX, IPV4_REGEX, IPV6_REGEX, PHONE_REGEX, URL_REGEX, isDigit, isEmail, isFloat, isIdNo, isInteger, isIpV4, isIpV6, isNumerical, isPhone, isUrl } from './validator.js';
32
+ export { escapeRegExp, executeInScope, parseVarFromString, replaceVarFromString, uniqueSymbol } from './variable.js';