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