sculp-js 1.4.0 → 1.4.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.
Files changed (51) hide show
  1. package/lib/cjs/array.js +1 -1
  2. package/lib/cjs/async.js +1 -1
  3. package/lib/cjs/clipboard.js +1 -1
  4. package/lib/cjs/cookie.js +1 -1
  5. package/lib/cjs/date.js +1 -1
  6. package/lib/cjs/dom.js +32 -1
  7. package/lib/cjs/download.js +1 -1
  8. package/lib/cjs/easing.js +1 -1
  9. package/lib/cjs/file.js +1 -1
  10. package/lib/cjs/func.js +1 -1
  11. package/lib/cjs/index.js +4 -2
  12. package/lib/cjs/number.js +1 -1
  13. package/lib/cjs/object.js +1 -1
  14. package/lib/cjs/path.js +1 -1
  15. package/lib/cjs/qs.js +1 -1
  16. package/lib/cjs/random.js +1 -1
  17. package/lib/cjs/string.js +17 -29
  18. package/lib/cjs/tooltip.js +5 -5
  19. package/lib/cjs/tree.js +1 -1
  20. package/lib/cjs/type.js +16 -1
  21. package/lib/cjs/unique.js +1 -1
  22. package/lib/cjs/url.js +1 -1
  23. package/lib/cjs/watermark.js +1 -1
  24. package/lib/cjs/we-decode.js +1 -1
  25. package/lib/es/array.js +1 -1
  26. package/lib/es/async.js +1 -1
  27. package/lib/es/clipboard.js +1 -1
  28. package/lib/es/cookie.js +1 -1
  29. package/lib/es/date.js +1 -1
  30. package/lib/es/dom.js +33 -3
  31. package/lib/es/download.js +1 -1
  32. package/lib/es/easing.js +1 -1
  33. package/lib/es/file.js +1 -1
  34. package/lib/es/func.js +1 -1
  35. package/lib/es/index.js +4 -4
  36. package/lib/es/number.js +1 -1
  37. package/lib/es/object.js +1 -1
  38. package/lib/es/path.js +1 -1
  39. package/lib/es/qs.js +1 -1
  40. package/lib/es/random.js +1 -1
  41. package/lib/es/string.js +17 -29
  42. package/lib/es/tooltip.js +2 -2
  43. package/lib/es/tree.js +1 -1
  44. package/lib/es/type.js +16 -2
  45. package/lib/es/unique.js +1 -1
  46. package/lib/es/url.js +1 -1
  47. package/lib/es/watermark.js +1 -1
  48. package/lib/es/we-decode.js +1 -1
  49. package/lib/index.d.ts +19 -7
  50. package/lib/umd/index.js +62 -26
  51. package/package.json +1 -1
package/lib/cjs/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -154,9 +154,40 @@ function getComputedCssVal(el, property, reNumber = true) {
154
154
  const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
155
155
  return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
156
156
  }
157
+ /**
158
+ * 字符串的像素宽度
159
+ * @param {string} str 目标字符串
160
+ * @param {number} fontSize 字符串字体大小
161
+ * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
162
+ * @returns {*}
163
+ */
164
+ function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
165
+ let strWidth = 0;
166
+ console.assert(type.isString(str), `${str} 不是有效的字符串`);
167
+ if (type.isString(str) && str.length > 0) {
168
+ let getEle = document.querySelector('#getStrWidth1494304949567');
169
+ if (!getEle) {
170
+ const _ele = document.createElement('span');
171
+ _ele.id = 'getStrWidth1494304949567';
172
+ _ele.style.fontSize = fontSize + 'px';
173
+ _ele.style.whiteSpace = 'nowrap';
174
+ _ele.style.visibility = 'hidden';
175
+ _ele.textContent = str;
176
+ document.body.appendChild(_ele);
177
+ getEle = _ele;
178
+ }
179
+ getEle.textContent = str;
180
+ strWidth = getEle.offsetWidth;
181
+ if (isRemoveDom) {
182
+ document.body.appendChild(getEle);
183
+ }
184
+ }
185
+ return strWidth;
186
+ }
157
187
 
158
188
  exports.addClass = addClass;
159
189
  exports.getComputedCssVal = getComputedCssVal;
190
+ exports.getStrWidthPx = getStrWidthPx;
160
191
  exports.getStyle = getStyle;
161
192
  exports.hasClass = hasClass;
162
193
  exports.isDomReady = isDomReady;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -49,6 +49,7 @@ exports.formatDate = date.formatDate;
49
49
  exports.isValidDate = date.isValidDate;
50
50
  exports.addClass = dom.addClass;
51
51
  exports.getComputedCssVal = dom.getComputedCssVal;
52
+ exports.getStrWidthPx = dom.getStrWidthPx;
52
53
  exports.getStyle = dom.getStyle;
53
54
  exports.hasClass = dom.hasClass;
54
55
  exports.isDomReady = dom.isDomReady;
@@ -79,7 +80,7 @@ exports.qsStringify = qs.qsStringify;
79
80
  exports.STRING_ARABIC_NUMERALS = string.STRING_ARABIC_NUMERALS;
80
81
  exports.STRING_LOWERCASE_ALPHA = string.STRING_LOWERCASE_ALPHA;
81
82
  exports.STRING_UPPERCASE_ALPHA = string.STRING_UPPERCASE_ALPHA;
82
- exports.getStrWidthPx = string.getStrWidthPx;
83
+ exports.parseQueryParams = string.parseQueryParams;
83
84
  exports.stringAssign = string.stringAssign;
84
85
  exports.stringCamelCase = string.stringCamelCase;
85
86
  exports.stringEscapeHtml = string.stringEscapeHtml;
@@ -92,6 +93,7 @@ exports.isBoolean = type.isBoolean;
92
93
  exports.isDate = type.isDate;
93
94
  exports.isError = type.isError;
94
95
  exports.isFunction = type.isFunction;
96
+ exports.isJsonString = type.isJsonString;
95
97
  exports.isNaN = type.isNaN;
96
98
  exports.isNull = type.isNull;
97
99
  exports.isNullOrUnDef = type.isNullOrUnDef;
package/lib/cjs/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/string.js CHANGED
@@ -1,13 +1,11 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  'use strict';
8
8
 
9
- var type = require('./type.js');
10
-
11
9
  /**
12
10
  * 将字符串转换为驼峰格式
13
11
  * @param {string} string
@@ -125,40 +123,30 @@ const stringEscapeHtml = (html) => {
125
123
  */
126
124
  const stringFill = (length, value = ' ') => new Array(length).fill(value).join('');
127
125
  /**
128
- * 字符串的像素宽度
129
- * @param {string} str 目标字符串
130
- * @param {number} fontSize 字符串字体大小
131
- * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
132
- * @returns {*}
126
+ * 解析URL查询参数
127
+ * @param {string} searchStr
128
+ * @return {Record<string, string | string[]>}
133
129
  */
134
- function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
135
- let strWidth = 0;
136
- console.assert(type.isString(str), `${str} 不是有效的字符串`);
137
- if (type.isString(str) && str.length > 0) {
138
- let getEle = document.querySelector('#getStrWidth1494304949567');
139
- if (!getEle) {
140
- const _ele = document.createElement('span');
141
- _ele.id = 'getStrWidth1494304949567';
142
- _ele.style.fontSize = fontSize + 'px';
143
- _ele.style.whiteSpace = 'nowrap';
144
- _ele.style.visibility = 'hidden';
145
- _ele.textContent = str;
146
- document.body.appendChild(_ele);
147
- getEle = _ele;
130
+ function parseQueryParams(searchStr = location.search) {
131
+ const queryObj = {};
132
+ Array.from(searchStr.matchAll(/[&?]?([^=&]+)=?([^=&]*)/g)).forEach((item, i) => {
133
+ if (!queryObj[item[1]]) {
134
+ queryObj[item[1]] = item[2];
148
135
  }
149
- getEle.textContent = str;
150
- strWidth = getEle.offsetWidth;
151
- if (isRemoveDom) {
152
- document.body.appendChild(getEle);
136
+ else if (typeof queryObj[item[1]] === 'string') {
137
+ queryObj[item[1]] = [queryObj[item[1]], item[2]];
153
138
  }
154
- }
155
- return strWidth;
139
+ else {
140
+ queryObj[item[1]].push(item[2]);
141
+ }
142
+ });
143
+ return queryObj;
156
144
  }
157
145
 
158
146
  exports.STRING_ARABIC_NUMERALS = STRING_ARABIC_NUMERALS;
159
147
  exports.STRING_LOWERCASE_ALPHA = STRING_LOWERCASE_ALPHA;
160
148
  exports.STRING_UPPERCASE_ALPHA = STRING_UPPERCASE_ALPHA;
161
- exports.getStrWidthPx = getStrWidthPx;
149
+ exports.parseQueryParams = parseQueryParams;
162
150
  exports.stringAssign = stringAssign;
163
151
  exports.stringCamelCase = stringCamelCase;
164
152
  exports.stringEscapeHtml = stringEscapeHtml;
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  'use strict';
8
8
 
9
- var string = require('./string.js');
9
+ var dom = require('./dom.js');
10
10
 
11
11
  /**
12
12
  * @title tooltip
@@ -79,10 +79,10 @@ function mouseenter($customTitle, title, e) {
79
79
  let x = 13;
80
80
  const y = 23;
81
81
  const $contentEle = $customTitle.children[0];
82
- if (string.getStrWidthPx(title, 12) < 180 + 50) {
82
+ if (dom.getStrWidthPx(title, 12) < 180 + 50) {
83
83
  //【弹出div自适应字符串宽度】若显示的字符串占用宽度小于180,则设置弹出div的宽度为“符串占用宽度”+20
84
- $contentEle.style.maxWidth = string.getStrWidthPx(title, 12) + 20 + 50 + 'px';
85
- diffValueX = e.clientX + (string.getStrWidthPx(title, 12) + 50) - document.body.offsetWidth;
84
+ $contentEle.style.maxWidth = dom.getStrWidthPx(title, 12) + 20 + 50 + 'px';
85
+ diffValueX = e.clientX + (dom.getStrWidthPx(title, 12) + 50) - document.body.offsetWidth;
86
86
  }
87
87
  else {
88
88
  $contentEle.style.maxWidth = '250px';
package/lib/cjs/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -40,6 +40,20 @@ const isNaN = (any) => Number.isNaN(any);
40
40
  const isDate = (any) => typeIs(any) === 'Date';
41
41
  const isError = (any) => typeIs(any) === 'Error';
42
42
  const isRegExp = (any) => typeIs(any) === 'RegExp';
43
+ /**
44
+ * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
45
+ * @param {string} str
46
+ * @return {Object | boolean}
47
+ */
48
+ function isJsonString(str) {
49
+ try {
50
+ const parsed = JSON.parse(str);
51
+ return typeof parsed === 'object' && parsed !== null ? parsed : false;
52
+ }
53
+ catch (e) {
54
+ return false;
55
+ }
56
+ }
43
57
 
44
58
  exports.default = typeIs;
45
59
  exports.isArray = isArray;
@@ -48,6 +62,7 @@ exports.isBoolean = isBoolean;
48
62
  exports.isDate = isDate;
49
63
  exports.isError = isError;
50
64
  exports.isFunction = isFunction;
65
+ exports.isJsonString = isJsonString;
51
66
  exports.isNaN = isNaN;
52
67
  exports.isNull = isNull;
53
68
  exports.isNullOrUnDef = isNullOrUnDef;
package/lib/cjs/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,7 +8,7 @@ import { arrayEach } from './array.js';
8
8
  import { easingFunctional } from './easing.js';
9
9
  import { objectEach, objectAssign } from './object.js';
10
10
  import { stringKebabCase } from './string.js';
11
- import { isObject } from './type.js';
11
+ import { isObject, isString } from './type.js';
12
12
 
13
13
  /**
14
14
  * 判断元素是否包含某个样式名
@@ -152,5 +152,35 @@ function getComputedCssVal(el, property, reNumber = true) {
152
152
  const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
153
153
  return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
154
154
  }
155
+ /**
156
+ * 字符串的像素宽度
157
+ * @param {string} str 目标字符串
158
+ * @param {number} fontSize 字符串字体大小
159
+ * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
160
+ * @returns {*}
161
+ */
162
+ function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
163
+ let strWidth = 0;
164
+ console.assert(isString(str), `${str} 不是有效的字符串`);
165
+ if (isString(str) && str.length > 0) {
166
+ let getEle = document.querySelector('#getStrWidth1494304949567');
167
+ if (!getEle) {
168
+ const _ele = document.createElement('span');
169
+ _ele.id = 'getStrWidth1494304949567';
170
+ _ele.style.fontSize = fontSize + 'px';
171
+ _ele.style.whiteSpace = 'nowrap';
172
+ _ele.style.visibility = 'hidden';
173
+ _ele.textContent = str;
174
+ document.body.appendChild(_ele);
175
+ getEle = _ele;
176
+ }
177
+ getEle.textContent = str;
178
+ strWidth = getEle.offsetWidth;
179
+ if (isRemoveDom) {
180
+ document.body.appendChild(getEle);
181
+ }
182
+ }
183
+ return strWidth;
184
+ }
155
185
 
156
- export { addClass, getComputedCssVal, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll };
186
+ export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,13 +8,13 @@ export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove }
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
- export { addClass, getComputedCssVal, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
11
+ export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
12
12
  export { downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
13
13
  export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, 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
- export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, getStrWidthPx, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
17
- export { isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs } from './type.js';
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';
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';
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/string.js CHANGED
@@ -1,11 +1,9 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { isString } from './type.js';
8
-
9
7
  /**
10
8
  * 将字符串转换为驼峰格式
11
9
  * @param {string} string
@@ -123,34 +121,24 @@ const stringEscapeHtml = (html) => {
123
121
  */
124
122
  const stringFill = (length, value = ' ') => new Array(length).fill(value).join('');
125
123
  /**
126
- * 字符串的像素宽度
127
- * @param {string} str 目标字符串
128
- * @param {number} fontSize 字符串字体大小
129
- * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
130
- * @returns {*}
124
+ * 解析URL查询参数
125
+ * @param {string} searchStr
126
+ * @return {Record<string, string | string[]>}
131
127
  */
132
- function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
133
- let strWidth = 0;
134
- console.assert(isString(str), `${str} 不是有效的字符串`);
135
- if (isString(str) && str.length > 0) {
136
- let getEle = document.querySelector('#getStrWidth1494304949567');
137
- if (!getEle) {
138
- const _ele = document.createElement('span');
139
- _ele.id = 'getStrWidth1494304949567';
140
- _ele.style.fontSize = fontSize + 'px';
141
- _ele.style.whiteSpace = 'nowrap';
142
- _ele.style.visibility = 'hidden';
143
- _ele.textContent = str;
144
- document.body.appendChild(_ele);
145
- getEle = _ele;
128
+ function parseQueryParams(searchStr = location.search) {
129
+ const queryObj = {};
130
+ Array.from(searchStr.matchAll(/[&?]?([^=&]+)=?([^=&]*)/g)).forEach((item, i) => {
131
+ if (!queryObj[item[1]]) {
132
+ queryObj[item[1]] = item[2];
146
133
  }
147
- getEle.textContent = str;
148
- strWidth = getEle.offsetWidth;
149
- if (isRemoveDom) {
150
- document.body.appendChild(getEle);
134
+ else if (typeof queryObj[item[1]] === 'string') {
135
+ queryObj[item[1]] = [queryObj[item[1]], item[2]];
151
136
  }
152
- }
153
- return strWidth;
137
+ else {
138
+ queryObj[item[1]].push(item[2]);
139
+ }
140
+ });
141
+ return queryObj;
154
142
  }
155
143
 
156
- export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, getStrWidthPx, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase };
144
+ export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, parseQueryParams, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase };
package/lib/es/tooltip.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- import { getStrWidthPx } from './string.js';
7
+ import { getStrWidthPx } from './dom.js';
8
8
 
9
9
  /**
10
10
  * @title tooltip
package/lib/es/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -36,5 +36,19 @@ const isNaN = (any) => Number.isNaN(any);
36
36
  const isDate = (any) => typeIs(any) === 'Date';
37
37
  const isError = (any) => typeIs(any) === 'Error';
38
38
  const isRegExp = (any) => typeIs(any) === 'RegExp';
39
+ /**
40
+ * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
41
+ * @param {string} str
42
+ * @return {Object | boolean}
43
+ */
44
+ function isJsonString(str) {
45
+ try {
46
+ const parsed = JSON.parse(str);
47
+ return typeof parsed === 'object' && parsed !== null ? parsed : false;
48
+ }
49
+ catch (e) {
50
+ return false;
51
+ }
52
+ }
39
53
 
40
- export { typeIs as default, isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs };
54
+ export { typeIs as default, isArray, isBigInt, isBoolean, isDate, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs };
package/lib/es/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/index.d.ts CHANGED
@@ -36,6 +36,12 @@ declare const isNaN: (any: unknown) => any is number;
36
36
  declare const isDate: (any: unknown) => any is Date;
37
37
  declare const isError: (any: unknown) => any is Error;
38
38
  declare const isRegExp: (any: unknown) => any is RegExp;
39
+ /**
40
+ * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
41
+ * @param {string} str
42
+ * @return {Object | boolean}
43
+ */
44
+ declare function isJsonString(str: string): Object | boolean;
39
45
 
40
46
  /**
41
47
  * 判断一个对象是否为类数组
@@ -237,6 +243,14 @@ declare function onDomReady(callback: ReadyCallback): void;
237
243
  * @returns {string|number}
238
244
  */
239
245
  declare function getComputedCssVal(el: HTMLElement, property: string, reNumber?: boolean): string | number;
246
+ /**
247
+ * 字符串的像素宽度
248
+ * @param {string} str 目标字符串
249
+ * @param {number} fontSize 字符串字体大小
250
+ * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
251
+ * @returns {*}
252
+ */
253
+ declare function getStrWidthPx(str: string, fontSize?: number, isRemoveDom?: boolean): number;
240
254
 
241
255
  interface Params<T = string | number> {
242
256
  [key: string]: T | Array<T>;
@@ -438,13 +452,11 @@ declare const stringEscapeHtml: (html: string) => string;
438
452
  */
439
453
  declare const stringFill: (length: number, value?: string) => string;
440
454
  /**
441
- * 字符串的像素宽度
442
- * @param {string} str 目标字符串
443
- * @param {number} fontSize 字符串字体大小
444
- * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
445
- * @returns {*}
455
+ * 解析URL查询参数
456
+ * @param {string} searchStr
457
+ * @return {Record<string, string | string[]>}
446
458
  */
447
- declare function getStrWidthPx(str: string, fontSize?: number, isRemoveDom?: boolean): number;
459
+ declare function parseQueryParams(searchStr?: string): Record<string, string | string[]>;
448
460
 
449
461
  interface Url {
450
462
  protocol: string;
@@ -822,4 +834,4 @@ declare function weBtoa(string: string): string;
822
834
  declare function weAtob(string: string): string;
823
835
  declare function weAppJwtDecode(token: any, options: any): any;
824
836
 
825
- export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ICompressOptions, type IFieldOptions, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, flatTree, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAppJwtDecode, weAtob, weBtoa };
837
+ export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ICompressOptions, type IFieldOptions, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, flatTree, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAppJwtDecode, weAtob, weBtoa };
package/lib/umd/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.4.0
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -42,6 +42,20 @@
42
42
  const isDate = (any) => typeIs(any) === 'Date';
43
43
  const isError = (any) => typeIs(any) === 'Error';
44
44
  const isRegExp = (any) => typeIs(any) === 'RegExp';
45
+ /**
46
+ * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
47
+ * @param {string} str
48
+ * @return {Object | boolean}
49
+ */
50
+ function isJsonString(str) {
51
+ try {
52
+ const parsed = JSON.parse(str);
53
+ return typeof parsed === 'object' && parsed !== null ? parsed : false;
54
+ }
55
+ catch (e) {
56
+ return false;
57
+ }
58
+ }
45
59
 
46
60
  /**
47
61
  * 判断对象是否为纯对象
@@ -510,34 +524,24 @@
510
524
  */
511
525
  const stringFill = (length, value = ' ') => new Array(length).fill(value).join('');
512
526
  /**
513
- * 字符串的像素宽度
514
- * @param {string} str 目标字符串
515
- * @param {number} fontSize 字符串字体大小
516
- * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
517
- * @returns {*}
527
+ * 解析URL查询参数
528
+ * @param {string} searchStr
529
+ * @return {Record<string, string | string[]>}
518
530
  */
519
- function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
520
- let strWidth = 0;
521
- console.assert(isString(str), `${str} 不是有效的字符串`);
522
- if (isString(str) && str.length > 0) {
523
- let getEle = document.querySelector('#getStrWidth1494304949567');
524
- if (!getEle) {
525
- const _ele = document.createElement('span');
526
- _ele.id = 'getStrWidth1494304949567';
527
- _ele.style.fontSize = fontSize + 'px';
528
- _ele.style.whiteSpace = 'nowrap';
529
- _ele.style.visibility = 'hidden';
530
- _ele.textContent = str;
531
- document.body.appendChild(_ele);
532
- getEle = _ele;
531
+ function parseQueryParams(searchStr = location.search) {
532
+ const queryObj = {};
533
+ Array.from(searchStr.matchAll(/[&?]?([^=&]+)=?([^=&]*)/g)).forEach((item, i) => {
534
+ if (!queryObj[item[1]]) {
535
+ queryObj[item[1]] = item[2];
533
536
  }
534
- getEle.textContent = str;
535
- strWidth = getEle.offsetWidth;
536
- if (isRemoveDom) {
537
- document.body.appendChild(getEle);
537
+ else if (typeof queryObj[item[1]] === 'string') {
538
+ queryObj[item[1]] = [queryObj[item[1]], item[2]];
538
539
  }
539
- }
540
- return strWidth;
540
+ else {
541
+ queryObj[item[1]].push(item[2]);
542
+ }
543
+ });
544
+ return queryObj;
541
545
  }
542
546
 
543
547
  /**
@@ -682,6 +686,36 @@
682
686
  const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
683
687
  return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
684
688
  }
689
+ /**
690
+ * 字符串的像素宽度
691
+ * @param {string} str 目标字符串
692
+ * @param {number} fontSize 字符串字体大小
693
+ * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
694
+ * @returns {*}
695
+ */
696
+ function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
697
+ let strWidth = 0;
698
+ console.assert(isString(str), `${str} 不是有效的字符串`);
699
+ if (isString(str) && str.length > 0) {
700
+ let getEle = document.querySelector('#getStrWidth1494304949567');
701
+ if (!getEle) {
702
+ const _ele = document.createElement('span');
703
+ _ele.id = 'getStrWidth1494304949567';
704
+ _ele.style.fontSize = fontSize + 'px';
705
+ _ele.style.whiteSpace = 'nowrap';
706
+ _ele.style.visibility = 'hidden';
707
+ _ele.textContent = str;
708
+ document.body.appendChild(_ele);
709
+ getEle = _ele;
710
+ }
711
+ getEle.textContent = str;
712
+ strWidth = getEle.offsetWidth;
713
+ if (isRemoveDom) {
714
+ document.body.appendChild(getEle);
715
+ }
716
+ }
717
+ return strWidth;
718
+ }
685
719
 
686
720
  const textEl = document.createElement('textarea');
687
721
  setStyle(textEl, {
@@ -2422,6 +2456,7 @@
2422
2456
  exports.isDomReady = isDomReady;
2423
2457
  exports.isError = isError;
2424
2458
  exports.isFunction = isFunction;
2459
+ exports.isJsonString = isJsonString;
2425
2460
  exports.isNaN = isNaN;
2426
2461
  exports.isNull = isNull;
2427
2462
  exports.isNullOrUnDef = isNullOrUnDef;
@@ -2448,6 +2483,7 @@
2448
2483
  exports.objectPick = objectPick;
2449
2484
  exports.onDomReady = onDomReady;
2450
2485
  exports.once = once;
2486
+ exports.parseQueryParams = parseQueryParams;
2451
2487
  exports.pathJoin = pathJoin;
2452
2488
  exports.pathNormalize = pathNormalize;
2453
2489
  exports.qsParse = qsParse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sculp-js",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "packageManager": "npm@8.19.2",
5
5
  "description": "js工具库",
6
6
  "scripts": {