sculp-js 1.13.3-beta.0 → 1.13.6

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 (119) hide show
  1. package/dist/cjs/_virtual/_commonjsHelpers.js +3 -3
  2. package/dist/cjs/array.js +36 -46
  3. package/dist/cjs/async.js +41 -43
  4. package/dist/cjs/base64.js +77 -66
  5. package/dist/cjs/clipboard.js +54 -53
  6. package/dist/cjs/cloneDeep.js +90 -91
  7. package/dist/cjs/cookie.js +27 -30
  8. package/dist/cjs/date.js +101 -98
  9. package/dist/cjs/dom.js +114 -121
  10. package/dist/cjs/download.js +77 -78
  11. package/dist/cjs/easing.js +29 -32
  12. package/dist/cjs/file.js +147 -152
  13. package/dist/cjs/func.js +64 -78
  14. package/dist/cjs/index.js +1 -3
  15. package/dist/cjs/math.js +32 -38
  16. package/dist/cjs/node_modules/bezier-easing/src/index.js +35 -23
  17. package/dist/cjs/number.js +58 -61
  18. package/dist/cjs/object.js +112 -126
  19. package/dist/cjs/path.js +39 -43
  20. package/dist/cjs/qs.js +34 -41
  21. package/dist/cjs/random.js +31 -34
  22. package/dist/cjs/string.js +62 -63
  23. package/dist/cjs/tooltip.js +66 -69
  24. package/dist/cjs/tree.js +265 -263
  25. package/dist/cjs/type.js +42 -46
  26. package/dist/cjs/unique.js +39 -42
  27. package/dist/cjs/url.js +47 -48
  28. package/dist/cjs/validator.js +38 -38
  29. package/dist/cjs/variable.js +27 -21
  30. package/dist/cjs/watermark.js +78 -67
  31. package/dist/esm/array.js +36 -46
  32. package/dist/esm/async.js +41 -43
  33. package/dist/esm/base64.js +77 -66
  34. package/dist/esm/clipboard.js +55 -54
  35. package/dist/esm/cloneDeep.js +90 -91
  36. package/dist/esm/cookie.js +27 -30
  37. package/dist/esm/date.js +101 -98
  38. package/dist/esm/dom.js +114 -121
  39. package/dist/esm/download.js +78 -79
  40. package/dist/esm/easing.js +29 -32
  41. package/dist/esm/file.js +147 -152
  42. package/dist/esm/func.js +64 -78
  43. package/dist/esm/index.js +96 -8
  44. package/dist/esm/math.js +32 -38
  45. package/dist/esm/number.js +58 -61
  46. package/dist/esm/object.js +124 -127
  47. package/dist/esm/path.js +39 -43
  48. package/dist/esm/qs.js +34 -41
  49. package/dist/esm/random.js +31 -34
  50. package/dist/esm/string.js +74 -64
  51. package/dist/esm/tooltip.js +66 -69
  52. package/dist/esm/tree.js +265 -263
  53. package/dist/esm/type.js +68 -47
  54. package/dist/esm/unique.js +39 -42
  55. package/dist/esm/url.js +47 -48
  56. package/dist/esm/validator.js +56 -39
  57. package/dist/esm/variable.js +27 -21
  58. package/dist/esm/watermark.js +79 -68
  59. package/dist/types/array.d.ts +0 -1
  60. package/dist/types/async.d.ts +0 -1
  61. package/dist/types/base64.d.ts +0 -1
  62. package/dist/types/clipboard.d.ts +0 -1
  63. package/dist/types/cloneDeep.d.ts +0 -1
  64. package/dist/types/cookie.d.ts +0 -1
  65. package/dist/types/date.d.ts +0 -1
  66. package/dist/types/dom.d.ts +0 -1
  67. package/dist/types/download.d.ts +0 -1
  68. package/dist/types/easing.d.ts +0 -1
  69. package/dist/types/file.d.ts +0 -1
  70. package/dist/types/func.d.ts +0 -1
  71. package/dist/types/index.d.ts +0 -1
  72. package/dist/types/math.d.ts +0 -1
  73. package/dist/types/number.d.ts +0 -1
  74. package/dist/types/object.d.ts +0 -1
  75. package/dist/types/path.d.ts +0 -1
  76. package/dist/types/qs.d.ts +0 -1
  77. package/dist/types/random.d.ts +0 -1
  78. package/dist/types/string.d.ts +0 -1
  79. package/dist/types/tooltip.d.ts +0 -1
  80. package/dist/types/tree.d.ts +2 -2
  81. package/dist/types/type.d.ts +0 -1
  82. package/dist/types/unique.d.ts +0 -1
  83. package/dist/types/url.d.ts +0 -1
  84. package/dist/types/validator.d.ts +0 -1
  85. package/dist/types/variable.d.ts +0 -1
  86. package/dist/types/watermark.d.ts +0 -1
  87. package/dist/umd/index.min.js +2 -2
  88. package/package.json +12 -6
  89. package/dist/types/array.d.ts.map +0 -1
  90. package/dist/types/async.d.ts.map +0 -1
  91. package/dist/types/base64.d.ts.map +0 -1
  92. package/dist/types/clipboard.d.ts.map +0 -1
  93. package/dist/types/cloneDeep.d.ts.map +0 -1
  94. package/dist/types/cookie.d.ts.map +0 -1
  95. package/dist/types/core-index.d.ts +0 -17
  96. package/dist/types/core-index.d.ts.map +0 -1
  97. package/dist/types/date.d.ts.map +0 -1
  98. package/dist/types/dom.d.ts.map +0 -1
  99. package/dist/types/download.d.ts.map +0 -1
  100. package/dist/types/easing.d.ts.map +0 -1
  101. package/dist/types/file.d.ts.map +0 -1
  102. package/dist/types/func.d.ts.map +0 -1
  103. package/dist/types/index.d.ts.map +0 -1
  104. package/dist/types/index.js +0 -3278
  105. package/dist/types/math.d.ts.map +0 -1
  106. package/dist/types/number.d.ts.map +0 -1
  107. package/dist/types/object.d.ts.map +0 -1
  108. package/dist/types/path.d.ts.map +0 -1
  109. package/dist/types/qs.d.ts.map +0 -1
  110. package/dist/types/random.d.ts.map +0 -1
  111. package/dist/types/string.d.ts.map +0 -1
  112. package/dist/types/tooltip.d.ts.map +0 -1
  113. package/dist/types/tree.d.ts.map +0 -1
  114. package/dist/types/type.d.ts.map +0 -1
  115. package/dist/types/unique.d.ts.map +0 -1
  116. package/dist/types/url.d.ts.map +0 -1
  117. package/dist/types/validator.d.ts.map +0 -1
  118. package/dist/types/variable.d.ts.map +0 -1
  119. package/dist/types/watermark.d.ts.map +0 -1
package/dist/esm/type.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  // 常用类型定义
8
- const { toString, hasOwnProperty, propertyIsEnumerable } = Object.prototype;
8
+ const { toString, hasOwnProperty } = Object.prototype;
9
9
  /**
10
10
  * 判断对象内是否有该静态属性
11
11
  * @param {object} obj
@@ -13,7 +13,7 @@ const { toString, hasOwnProperty, propertyIsEnumerable } = Object.prototype;
13
13
  * @returns {boolean}
14
14
  */
15
15
  function objectHas(obj, key) {
16
- return hasOwnProperty.call(obj, key);
16
+ return hasOwnProperty.call(obj, key);
17
17
  }
18
18
  /**
19
19
  * 判断一个对象是否为类数组
@@ -22,13 +22,10 @@ function objectHas(obj, key) {
22
22
  * @returns {boolean}
23
23
  */
24
24
  function arrayLike(any) {
25
- if (isArray(any))
26
- return true;
27
- if (isString(any))
28
- return true;
29
- if (!isObject(any))
30
- return false;
31
- return objectHas(any, 'length');
25
+ if (isArray(any)) return true;
26
+ if (isString(any)) return true;
27
+ if (!isObject(any)) return false;
28
+ return objectHas(any, 'length');
32
29
  }
33
30
  /**
34
31
  * 判断任意值的数据类型,检查非对象时不如typeof、instanceof的性能高
@@ -40,47 +37,46 @@ function arrayLike(any) {
40
37
  * @returns
41
38
  */
42
39
  function typeIs(any) {
43
- return toString.call(any).slice(8, -1);
40
+ return toString.call(any).slice(8, -1);
44
41
  }
45
42
  // 基本数据类型判断
46
- const isString = (any) => typeof any === 'string';
47
- const isBoolean = (any) => typeof any === 'boolean';
48
- const isSymbol = (any) => typeof any === 'symbol';
49
- const isBigInt = (any) => typeof any === 'bigint';
50
- const isNumber = (any) => typeof any === 'number' && !Number.isNaN(any);
51
- const isUndefined = (any) => typeof any === 'undefined';
52
- const isNull = (any) => any === null;
53
- const isPrimitive = (any) => any === null || typeof any !== 'object';
43
+ const isString = any => typeof any === 'string';
44
+ const isBoolean = any => typeof any === 'boolean';
45
+ const isSymbol = any => typeof any === 'symbol';
46
+ const isBigInt = any => typeof any === 'bigint';
47
+ const isNumber = any => typeof any === 'number' && !Number.isNaN(any);
48
+ const isUndefined = any => typeof any === 'undefined';
49
+ const isNull = any => any === null;
50
+ const isPrimitive = any => any === null || typeof any !== 'object';
54
51
  function isNullOrUnDef(val) {
55
- return isUndefined(val) || isNull(val);
52
+ return isUndefined(val) || isNull(val);
56
53
  }
57
54
  // 复合数据类型判断
58
- const isObject = (any) => typeIs(any) === 'Object';
59
- const isArray = (any) => Array.isArray(any);
55
+ const isObject = any => typeIs(any) === 'Object';
56
+ const isArray = any => Array.isArray(any);
60
57
  /**
61
58
  * 判断是否为函数
62
59
  * @param {unknown} any
63
60
  * @returns {boolean}
64
61
  */
65
- const isFunction = (any) => typeof any === 'function';
62
+ const isFunction = any => typeof any === 'function';
66
63
  // 对象类型判断
67
- const isNaN = (any) => Number.isNaN(any);
68
- const isDate = (any) => typeIs(any) === 'Date';
69
- const isError = (any) => typeIs(any) === 'Error';
70
- const isRegExp = (any) => typeIs(any) === 'RegExp';
64
+ const isNaN = any => Number.isNaN(any);
65
+ const isDate = any => typeIs(any) === 'Date';
66
+ const isError = any => typeIs(any) === 'Error';
67
+ const isRegExp = any => typeIs(any) === 'RegExp';
71
68
  /**
72
69
  * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
73
70
  * @param {string} str
74
71
  * @returns {Object | boolean}
75
72
  */
76
73
  function isJsonString(str) {
77
- try {
78
- const parsed = JSON.parse(str);
79
- return typeof parsed === 'object' && parsed !== null ? parsed : false;
80
- }
81
- catch (e) {
82
- return false;
83
- }
74
+ try {
75
+ const parsed = JSON.parse(str);
76
+ return typeof parsed === 'object' && parsed !== null ? parsed : false;
77
+ } catch (e) {
78
+ return false;
79
+ }
84
80
  }
85
81
  /**
86
82
  * Checks if `value` is an empty object, collection, map, or set.
@@ -112,23 +108,48 @@ function isJsonString(str) {
112
108
  * // => false
113
109
  */
114
110
  function isEmpty(value) {
115
- if (isNullOrUnDef(value) || Number.isNaN(value)) {
116
- return true;
117
- }
118
- const tag = typeIs(value);
119
- if (arrayLike(value) || 'Arguments' === tag) {
120
- return !value.length;
121
- }
122
- if ('Set' === tag || 'Map' === tag) {
123
- return !value.size;
124
- }
125
- return !Object.keys(value).length;
111
+ if (isNullOrUnDef(value) || Number.isNaN(value)) {
112
+ return true;
113
+ }
114
+ const tag = typeIs(value);
115
+ if (arrayLike(value) || 'Arguments' === tag) {
116
+ return !value.length;
117
+ }
118
+ if ('Set' === tag || 'Map' === tag) {
119
+ return !value.size;
120
+ }
121
+ return !Object.keys(value).length;
126
122
  }
127
123
  /**
128
124
  * Checks if `value` is an NodeList object
129
125
  */
130
126
  function isNodeList(value) {
131
- return isUndefined(NodeList) ? false : NodeList.prototype.isPrototypeOf(value);
127
+ return isUndefined(NodeList) ? false : NodeList.prototype.isPrototypeOf(value);
132
128
  }
133
129
 
134
- export { arrayLike, typeIs as default, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFunction, isJsonString, isNaN, isNodeList, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, objectHas, typeIs };
130
+ export {
131
+ arrayLike,
132
+ typeIs as default,
133
+ isArray,
134
+ isBigInt,
135
+ isBoolean,
136
+ isDate,
137
+ isEmpty,
138
+ isError,
139
+ isFunction,
140
+ isJsonString,
141
+ isNaN,
142
+ isNodeList,
143
+ isNull,
144
+ isNullOrUnDef,
145
+ isNullOrUnDef as isNullish,
146
+ isNumber,
147
+ isObject,
148
+ isPrimitive,
149
+ isRegExp,
150
+ isString,
151
+ isSymbol,
152
+ isUndefined,
153
+ objectHas,
154
+ typeIs
155
+ };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -24,28 +24,28 @@ const TIMESTAMP_LENGTH = 13;
24
24
  * @returns {string}
25
25
  */
26
26
  const uniqueNumber = (length = UNIQUE_NUMBER_SAFE_LENGTH) => {
27
- const now = Date.now();
28
- length = Math.max(length, UNIQUE_NUMBER_SAFE_LENGTH);
29
- if (now !== lastTimestamp) {
30
- lastTimestamp = now;
31
- safeNo = 0;
32
- }
33
- const timestamp = `${now}`;
34
- let random = '';
35
- const rndLength = length - FIX_SAFE_LENGTH - TIMESTAMP_LENGTH;
36
- if (rndLength > 0) {
37
- const rndMin = 10 ** (rndLength - 1);
38
- const rndMax = 10 ** rndLength - 1;
39
- const rnd = randomNumber(rndMin, rndMax);
40
- random = `${rnd}`;
41
- }
42
- const safe = padStartWithZero(safeNo, FIX_SAFE_LENGTH);
43
- safeNo++;
44
- return `${timestamp}${random}${safe}`;
27
+ const now = Date.now();
28
+ length = Math.max(length, UNIQUE_NUMBER_SAFE_LENGTH);
29
+ if (now !== lastTimestamp) {
30
+ lastTimestamp = now;
31
+ safeNo = 0;
32
+ }
33
+ const timestamp = `${now}`;
34
+ let random = '';
35
+ const rndLength = length - FIX_SAFE_LENGTH - TIMESTAMP_LENGTH;
36
+ if (rndLength > 0) {
37
+ const rndMin = 10 ** (rndLength - 1);
38
+ const rndMax = 10 ** rndLength - 1;
39
+ const rnd = randomNumber(rndMin, rndMax);
40
+ random = `${rnd}`;
41
+ }
42
+ const safe = padStartWithZero(safeNo, FIX_SAFE_LENGTH);
43
+ safeNo++;
44
+ return `${timestamp}${random}${safe}`;
45
45
  };
46
- const randomFromPool = (pool) => {
47
- const poolIndex = randomNumber(0, pool.length - 1);
48
- return pool[poolIndex];
46
+ const randomFromPool = pool => {
47
+ const poolIndex = randomNumber(0, pool.length - 1);
48
+ return pool[poolIndex];
49
49
  };
50
50
  /**
51
51
  * 生成唯一不重复字符串
@@ -54,26 +54,23 @@ const randomFromPool = (pool) => {
54
54
  * @returns {string}
55
55
  */
56
56
  const uniqueString = (length, pool) => {
57
- let _length = 0;
58
- let _pool = HEX_POOL;
59
- if (isString(pool)) {
60
- _length = length;
61
- _pool = pool;
62
- }
63
- else if (isNumber(length)) {
64
- _length = length;
65
- }
66
- else if (isString(length)) {
67
- _pool = length;
68
- }
69
- let uniqueString = numberToHex(uniqueNumber(), _pool);
70
- let insertLength = _length - uniqueString.length;
71
- if (insertLength <= 0)
72
- return uniqueString;
73
- while (insertLength--) {
74
- uniqueString += randomFromPool(_pool);
75
- }
76
- return uniqueString;
57
+ let _length = 0;
58
+ let _pool = HEX_POOL;
59
+ if (isString(pool)) {
60
+ _length = length;
61
+ _pool = pool;
62
+ } else if (isNumber(length)) {
63
+ _length = length;
64
+ } else if (isString(length)) {
65
+ _pool = length;
66
+ }
67
+ let uniqueString = numberToHex(uniqueNumber(), _pool);
68
+ let insertLength = _length - uniqueString.length;
69
+ if (insertLength <= 0) return uniqueString;
70
+ while (insertLength--) {
71
+ uniqueString += randomFromPool(_pool);
72
+ }
73
+ return uniqueString;
77
74
  };
78
75
 
79
76
  export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString };
package/dist/esm/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -15,53 +15,52 @@ import { qsParse, qsStringify } from './qs.js';
15
15
  * @returns {Url}
16
16
  */
17
17
  const urlParse = (url, isModernApi = true) => {
18
- // @ts-ignore
19
- let urlObj = null;
20
- if (isFunction(URL) && isModernApi) {
21
- urlObj = new URL(url);
22
- }
23
- else {
24
- urlObj = document.createElement('a');
25
- urlObj.href = url;
26
- }
27
- const { protocol, username, password, host, port, hostname, hash, search, pathname: _pathname } = urlObj;
28
- // fix: ie 浏览器下,解析出来的 pathname 是没有 / 根的
29
- const pathname = pathJoin('/', _pathname);
30
- const auth = username && password ? `${username}:${password}` : '';
31
- const query = search.replace(/^\?/, '');
32
- const searchParams = qsParse(query);
33
- const path = `${pathname}${search}`;
34
- urlObj = null;
35
- return {
36
- protocol,
37
- auth,
38
- username,
39
- password,
40
- host,
41
- port,
42
- hostname,
43
- hash,
44
- search,
45
- searchParams,
46
- query,
47
- pathname,
48
- path,
49
- href: url
50
- };
18
+ // @ts-ignore
19
+ let urlObj = null;
20
+ if (isFunction(URL) && isModernApi) {
21
+ urlObj = new URL(url);
22
+ } else {
23
+ urlObj = document.createElement('a');
24
+ urlObj.href = url;
25
+ }
26
+ const { protocol, username, password, host, port, hostname, hash, search, pathname: _pathname } = urlObj;
27
+ // fix: ie 浏览器下,解析出来的 pathname 是没有 / 根的
28
+ const pathname = pathJoin('/', _pathname);
29
+ const auth = username && password ? `${username}:${password}` : '';
30
+ const query = search.replace(/^\?/, '');
31
+ const searchParams = qsParse(query);
32
+ const path = `${pathname}${search}`;
33
+ urlObj = null;
34
+ return {
35
+ protocol,
36
+ auth,
37
+ username,
38
+ password,
39
+ host,
40
+ port,
41
+ hostname,
42
+ hash,
43
+ search,
44
+ searchParams,
45
+ query,
46
+ pathname,
47
+ path,
48
+ href: url
49
+ };
51
50
  };
52
51
  /**
53
52
  * url 字符化,url 对象里的 searchParams 会覆盖 url 原有的查询参数
54
53
  * @param {Url} url
55
54
  * @returns {string}
56
55
  */
57
- const urlStringify = (url) => {
58
- const { protocol, auth, host, pathname, searchParams, hash } = url;
59
- const authorize = auth ? `${auth}@` : '';
60
- const querystring = qsStringify(searchParams);
61
- const search = querystring ? `?${querystring}` : '';
62
- let hashstring = hash.replace(/^#/, '');
63
- hashstring = hashstring ? '#' + hashstring : '';
64
- return `${protocol}//${authorize}${host}${pathname}${search}${hashstring}`;
56
+ const urlStringify = url => {
57
+ const { protocol, auth, host, pathname, searchParams, hash } = url;
58
+ const authorize = auth ? `${auth}@` : '';
59
+ const querystring = qsStringify(searchParams);
60
+ const search = querystring ? `?${querystring}` : '';
61
+ let hashstring = hash.replace(/^#/, '');
62
+ hashstring = hashstring ? '#' + hashstring : '';
63
+ return `${protocol}//${authorize}${host}${pathname}${search}${hashstring}`;
65
64
  };
66
65
  /**
67
66
  * 设置 url 查询参数
@@ -70,9 +69,9 @@ const urlStringify = (url) => {
70
69
  * @returns {string}
71
70
  */
72
71
  const urlSetParams = (url, setter) => {
73
- const p = urlParse(url);
74
- Object.assign(p.searchParams, setter);
75
- return urlStringify(p);
72
+ const p = urlParse(url);
73
+ Object.assign(p.searchParams, setter);
74
+ return urlStringify(p);
76
75
  };
77
76
  /**
78
77
  * 删除 url 查询参数
@@ -81,9 +80,9 @@ const urlSetParams = (url, setter) => {
81
80
  * @returns {string}
82
81
  */
83
82
  const urlDelParams = (url, removeKeys) => {
84
- const p = urlParse(url);
85
- removeKeys.forEach(key => delete p.searchParams[key]);
86
- return urlStringify(p);
83
+ const p = urlParse(url);
84
+ removeKeys.forEach(key => delete p.searchParams[key]);
85
+ return urlStringify(p);
87
86
  };
88
87
 
89
88
  export { urlDelParams, urlParse, urlSetParams, urlStringify };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -11,7 +11,7 @@ const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
11
11
  * @param {string} value
12
12
  * @returns {boolean}
13
13
  */
14
- const isEmail = (value) => EMAIL_REGEX.test(value);
14
+ const isEmail = value => EMAIL_REGEX.test(value);
15
15
  // 手机号码 (中国大陆)
16
16
  // reference: https://www.runoob.com/regexp/regexp-syntax.html (?: 是非捕获元之一)
17
17
  const PHONE_REGEX = /^(?:(?:\+|00)86)?1\d{10}$/;
@@ -20,7 +20,7 @@ const PHONE_REGEX = /^(?:(?:\+|00)86)?1\d{10}$/;
20
20
  * @param {string} value
21
21
  * @returns {boolean}
22
22
  */
23
- const isPhone = (value) => PHONE_REGEX.test(value);
23
+ const isPhone = value => PHONE_REGEX.test(value);
24
24
  // 身份证号码
25
25
  // http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/
26
26
  // ["北京市", "天津市", "河北省", "山西省", "内蒙古自治区",
@@ -40,37 +40,36 @@ const isPhone = (value) => PHONE_REGEX.test(value);
40
40
  // "71",
41
41
  // "81", "82"]
42
42
  // 91 国外
43
- 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]$/;
43
+ const IDNO_RE =
44
+ /^(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]$/;
44
45
  /**
45
46
  * 判断字符串是否为身份证号码格式
46
47
  * @param {string} value
47
48
  * @returns {boolean}
48
49
  */
49
- const isIdNo = (value) => {
50
- const isSameFormat = IDNO_RE.test(value);
51
- if (!isSameFormat)
52
- return false;
53
- const year = Number(value.slice(6, 10));
54
- const month = Number(value.slice(10, 12));
55
- const date = Number(value.slice(12, 14));
56
- const d = new Date(year, month - 1, date);
57
- const isSameDate = d.getFullYear() === year && d.getMonth() + 1 === month && d.getDate() === date;
58
- if (!isSameDate)
59
- return false;
60
- // 将身份证号码前面的17位数分别乘以不同的系数;
61
- // 从第一位到第十七位的系数分别为:7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2
62
- // 将这17位数字和系数相乘的结果相加;
63
- // 用加出来和除以11,看余数是多少;
64
- // 余数只可能有0-1-2-3-4-5-6-7-8-9-10这11个数字;
65
- // 其分别对应的最后一位身份证的号码为1-0-X-987-6-54-3-2
66
- // 通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
67
- const coefficientList = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
68
- const residueList = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
69
- let sum = 0;
70
- for (let start = 0; start < 17; start++) {
71
- sum += Number(value.slice(start, start + 1)) * coefficientList[start];
72
- }
73
- return residueList[sum % 11] === value.slice(-1);
50
+ const isIdNo = value => {
51
+ const isSameFormat = IDNO_RE.test(value);
52
+ if (!isSameFormat) return false;
53
+ const year = Number(value.slice(6, 10));
54
+ const month = Number(value.slice(10, 12));
55
+ const date = Number(value.slice(12, 14));
56
+ const d = new Date(year, month - 1, date);
57
+ const isSameDate = d.getFullYear() === year && d.getMonth() + 1 === month && d.getDate() === date;
58
+ if (!isSameDate) return false;
59
+ // 将身份证号码前面的17位数分别乘以不同的系数;
60
+ // 从第一位到第十七位的系数分别为:7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2
61
+ // 将这17位数字和系数相乘的结果相加;
62
+ // 用加出来和除以11,看余数是多少;
63
+ // 余数只可能有0-1-2-3-4-5-6-7-8-9-10这11个数字;
64
+ // 其分别对应的最后一位身份证的号码为1-0-X-9-8-7-6-5-4-3-2
65
+ // 通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
66
+ const coefficientList = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
67
+ const residueList = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
68
+ let sum = 0;
69
+ for (let start = 0; start < 17; start++) {
70
+ sum += Number(value.slice(start, start + 1)) * coefficientList[start];
71
+ }
72
+ return residueList[sum % 11] === value.slice(-1);
74
73
  };
75
74
  const URL_REGEX = /^(https?|ftp):\/\/([^\s/$.?#].[^\s]*)$/i;
76
75
  const HTTP_URL_REGEX = /^https?:\/\/([^\s/$.?#].[^\s]*)$/i;
@@ -80,51 +79,69 @@ const HTTP_URL_REGEX = /^https?:\/\/([^\s/$.?#].[^\s]*)$/i;
80
79
  * @returns {boolean}
81
80
  */
82
81
  const isUrl = (url, includeFtp = false) => {
83
- const regex = includeFtp ? URL_REGEX : HTTP_URL_REGEX;
84
- return regex.test(url);
82
+ const regex = includeFtp ? URL_REGEX : HTTP_URL_REGEX;
83
+ return regex.test(url);
85
84
  };
86
85
  // ipv4
87
86
  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])$/;
88
87
  // ipv6
89
- 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;
88
+ const IPV6_REGEX =
89
+ /^(([\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;
90
90
  /**
91
91
  * 判断字符串是否为 IPV4 格式,不对 ip 真实性做验证
92
92
  * @param {string} value
93
93
  * @returns {boolean}
94
94
  */
95
- const isIpV4 = (value) => IPV4_REGEX.test(value);
95
+ const isIpV4 = value => IPV4_REGEX.test(value);
96
96
  /**
97
97
  * 判断字符串是否为 IPV6 格式,不对 ip 真实性做验证
98
98
  * @param {string} value
99
99
  * @returns {boolean}
100
100
  */
101
- const isIpV6 = (value) => IPV6_REGEX.test(value);
101
+ const isIpV6 = value => IPV6_REGEX.test(value);
102
102
  const INTEGER_RE = /^(-?[1-9]\d*|0)$/;
103
103
  /**
104
104
  * 判断字符串是否为整数(自然数),即 ...,-3,-2,-1,0,1,2,3,...
105
105
  * @param {string} value
106
106
  * @returns {boolean}
107
107
  */
108
- const isInteger = (value) => INTEGER_RE.test(value);
108
+ const isInteger = value => INTEGER_RE.test(value);
109
109
  const FLOAT_RE = /^-?([1-9]\d*|0)\.\d*[1-9]$/;
110
110
  /**
111
111
  * 判断字符串是否为浮点数,即必须有小数点的有理数
112
112
  * @param {string} value
113
113
  * @returns {boolean}
114
114
  */
115
- const isFloat = (value) => FLOAT_RE.test(value);
115
+ const isFloat = value => FLOAT_RE.test(value);
116
116
  /**
117
117
  * 判断字符串是否为正确数值,包括整数和浮点数
118
118
  * @param {string} value
119
119
  * @returns {boolean}
120
120
  */
121
- const isNumerical = (value) => isInteger(value) || isFloat(value);
121
+ const isNumerical = value => isInteger(value) || isFloat(value);
122
122
  const DIGIT_RE = /^\d+$/;
123
123
  /**
124
124
  * 判断字符串是否为数字,例如六位数字短信验证码(093031)
125
125
  * @param {string} value
126
126
  * @returns {boolean}
127
127
  */
128
- const isDigit = (value) => DIGIT_RE.test(value);
128
+ const isDigit = value => DIGIT_RE.test(value);
129
129
 
130
- export { EMAIL_REGEX, HTTP_URL_REGEX, IPV4_REGEX, IPV6_REGEX, PHONE_REGEX, URL_REGEX, isDigit, isEmail, isFloat, isIdNo, isInteger, isIpV4, isIpV6, isNumerical, isPhone, isUrl };
130
+ export {
131
+ EMAIL_REGEX,
132
+ HTTP_URL_REGEX,
133
+ IPV4_REGEX,
134
+ IPV6_REGEX,
135
+ PHONE_REGEX,
136
+ URL_REGEX,
137
+ isDigit,
138
+ isEmail,
139
+ isFloat,
140
+ isIdNo,
141
+ isInteger,
142
+ isIpV4,
143
+ isIpV6,
144
+ isNumerical,
145
+ isPhone,
146
+ isUrl
147
+ };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -16,7 +16,7 @@ import { isNullOrUnDef, objectHas } from './type.js';
16
16
  * // => '1abc'
17
17
  */
18
18
  function uniqueSymbol(str) {
19
- return [...new Set(str.trim().split(''))].join('');
19
+ return [...new Set(str.trim().split(''))].join('');
20
20
  }
21
21
  /**
22
22
  * 转义所有特殊字符
@@ -25,7 +25,7 @@ function uniqueSymbol(str) {
25
25
  * @returns string
26
26
  */
27
27
  function escapeRegExp(str) {
28
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); //$&表示整个被匹配的字符串
28
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); //$&表示整个被匹配的字符串
29
29
  }
30
30
  /**
31
31
  * 根据左右匹配符号生产解析变量(自动删除变量内的空白)
@@ -34,7 +34,12 @@ function escapeRegExp(str) {
34
34
  * @returns RegExp
35
35
  */
36
36
  function parseVariableRegExp(leftMatchSymbol, rightMatchSymbol) {
37
- return new RegExp(`${escapeRegExp(leftMatchSymbol.trim())}\\s*([^${escapeRegExp(uniqueSymbol(leftMatchSymbol))}${escapeRegExp(uniqueSymbol(rightMatchSymbol))}\\s]*)\\s*${rightMatchSymbol.trim()}`, 'g');
37
+ return new RegExp(
38
+ `${escapeRegExp(leftMatchSymbol.trim())}\\s*([^${escapeRegExp(uniqueSymbol(leftMatchSymbol))}${escapeRegExp(
39
+ uniqueSymbol(rightMatchSymbol)
40
+ )}\\s]*)\\s*${rightMatchSymbol.trim()}`,
41
+ 'g'
42
+ );
38
43
  }
39
44
  /**
40
45
  * 解析字符串的插值变量
@@ -47,8 +52,10 @@ function parseVariableRegExp(leftMatchSymbol, rightMatchSymbol) {
47
52
  * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
48
53
  */
49
54
  function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}') {
50
- // @ts-ignore
51
- return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => isNullOrUnDef(el) ? void 0 : el[1]);
55
+ // @ts-ignore
56
+ return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el =>
57
+ isNullOrUnDef(el) ? void 0 : el[1]
58
+ );
52
59
  }
53
60
  /**
54
61
  * 替换字符串中的插值变量
@@ -59,9 +66,9 @@ function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}')
59
66
  * @returns string
60
67
  */
61
68
  function replaceVarFromString(sourceStr, targetObj, leftMatchSymbol = '{', rightMatchSymbol = '}') {
62
- return sourceStr.replace(new RegExp(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol)), function (m, p1) {
63
- return objectHas(targetObj, p1) ? targetObj[p1] : m;
64
- });
69
+ return sourceStr.replace(new RegExp(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol)), function (m, p1) {
70
+ return objectHas(targetObj, p1) ? targetObj[p1] : m;
71
+ });
65
72
  }
66
73
  /**
67
74
  * 在指定作用域中执行代码
@@ -96,18 +103,17 @@ function replaceVarFromString(sourceStr, targetObj, leftMatchSymbol = '{', right
96
103
  * executeInScope("return $.fun.time.now()", scope)
97
104
  */
98
105
  function executeInScope(code, scope = {}) {
99
- // 提取作用域对象的键和值
100
- const keys = Object.keys(scope);
101
- const values = keys.map(key => scope[key]);
102
- try {
103
- // 动态创建函数,将作用域的键作为参数,代码作为函数体
104
- const func = new Function(...keys, `return (() => { ${code} })()`);
105
- // 调用函数并传入作用域的值
106
- return func(...values);
107
- }
108
- catch (error) {
109
- throw new Error(`代码执行失败: ${error.message}`);
110
- }
106
+ // 提取作用域对象的键和值
107
+ const keys = Object.keys(scope);
108
+ const values = keys.map(key => scope[key]);
109
+ try {
110
+ // 动态创建函数,将作用域的键作为参数,代码作为函数体
111
+ const func = new Function(...keys, `return (() => { ${code} })()`);
112
+ // 调用函数并传入作用域的值
113
+ return func(...values);
114
+ } catch (error) {
115
+ throw new Error(`代码执行失败: ${error.message}`);
116
+ }
111
117
  }
112
118
 
113
119
  export { escapeRegExp, executeInScope, parseVarFromString, replaceVarFromString, uniqueSymbol };