sculp-js 1.8.4 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/array.js +1 -1
- package/lib/cjs/async.js +1 -1
- package/lib/cjs/base64.js +1 -1
- package/lib/cjs/clipboard.js +7 -11
- package/lib/cjs/cloneDeep.js +1 -1
- package/lib/cjs/cookie.js +1 -1
- package/lib/cjs/date.js +1 -1
- package/lib/cjs/dom.js +1 -1
- package/lib/cjs/download.js +1 -1
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +1 -1
- package/lib/cjs/func.js +1 -1
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/isEqual.js +1 -1
- package/lib/cjs/math.js +1 -1
- package/lib/cjs/number.js +49 -12
- package/lib/cjs/object.js +1 -1
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +1 -1
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +1 -1
- package/lib/cjs/tooltip.js +1 -1
- package/lib/cjs/tree.js +2 -2
- package/lib/cjs/type.js +1 -1
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +15 -5
- package/lib/cjs/validator.js +1 -1
- package/lib/cjs/variable.js +1 -1
- package/lib/cjs/watermark.js +1 -1
- package/lib/cjs/we-decode.js +1 -1
- package/lib/es/array.js +1 -1
- package/lib/es/async.js +1 -1
- package/lib/es/base64.js +1 -1
- package/lib/es/clipboard.js +7 -11
- package/lib/es/cloneDeep.js +1 -1
- package/lib/es/cookie.js +1 -1
- package/lib/es/date.js +1 -1
- package/lib/es/dom.js +1 -1
- package/lib/es/download.js +1 -1
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +1 -1
- package/lib/es/func.js +1 -1
- package/lib/es/index.js +2 -2
- package/lib/es/isEqual.js +1 -1
- package/lib/es/math.js +1 -1
- package/lib/es/number.js +48 -13
- package/lib/es/object.js +1 -1
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +1 -1
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +1 -1
- package/lib/es/tooltip.js +1 -1
- package/lib/es/tree.js +2 -2
- package/lib/es/type.js +1 -1
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +15 -5
- package/lib/es/validator.js +1 -1
- package/lib/es/variable.js +1 -1
- package/lib/es/watermark.js +1 -1
- package/lib/es/we-decode.js +1 -1
- package/lib/index.d.ts +32 -9
- package/lib/umd/index.js +561 -518
- package/package.json +1 -1
package/lib/cjs/array.js
CHANGED
package/lib/cjs/async.js
CHANGED
package/lib/cjs/base64.js
CHANGED
package/lib/cjs/clipboard.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var dom = require('./dom.js');
|
|
10
|
-
|
|
11
|
-
const textEl = document.createElement('textarea');
|
|
12
|
-
dom.setStyle(textEl, {
|
|
13
|
-
position: 'absolute',
|
|
14
|
-
top: '-9999px',
|
|
15
|
-
left: '-9999px',
|
|
16
|
-
opacity: 0
|
|
17
|
-
});
|
|
18
|
-
document.body.appendChild(textEl);
|
|
19
9
|
/**
|
|
20
10
|
* 复制文本
|
|
21
11
|
* @param {string} text
|
|
22
12
|
*/
|
|
23
13
|
function copyText(text) {
|
|
14
|
+
const textEl = document.createElement('textarea');
|
|
15
|
+
textEl.style.position = 'absolute';
|
|
16
|
+
textEl.style.top = '-9999px';
|
|
17
|
+
textEl.style.left = '-9999px';
|
|
24
18
|
textEl.value = text;
|
|
19
|
+
document.body.appendChild(textEl);
|
|
25
20
|
textEl.focus({ preventScroll: true });
|
|
26
21
|
textEl.select();
|
|
27
22
|
try {
|
|
28
23
|
document.execCommand('copy');
|
|
29
24
|
textEl.blur();
|
|
25
|
+
document.body.removeChild(textEl);
|
|
30
26
|
}
|
|
31
27
|
catch (err) {
|
|
32
28
|
// ignore
|
package/lib/cjs/cloneDeep.js
CHANGED
package/lib/cjs/cookie.js
CHANGED
package/lib/cjs/date.js
CHANGED
package/lib/cjs/dom.js
CHANGED
package/lib/cjs/download.js
CHANGED
package/lib/cjs/easing.js
CHANGED
package/lib/cjs/file.js
CHANGED
package/lib/cjs/func.js
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -131,7 +131,9 @@ exports.randomNumber = random.randomNumber;
|
|
|
131
131
|
exports.randomString = random.randomString;
|
|
132
132
|
exports.randomUuid = random.randomUuid;
|
|
133
133
|
exports.HEX_POOL = number.HEX_POOL;
|
|
134
|
+
exports.formatMoney = number.formatNumber;
|
|
134
135
|
exports.formatNumber = number.formatNumber;
|
|
136
|
+
exports.humanFileSize = number.humanFileSize;
|
|
135
137
|
exports.numberAbbr = number.numberAbbr;
|
|
136
138
|
exports.numberToHex = number.numberToHex;
|
|
137
139
|
exports.UNIQUE_NUMBER_SAFE_LENGTH = unique.UNIQUE_NUMBER_SAFE_LENGTH;
|
package/lib/cjs/isEqual.js
CHANGED
package/lib/cjs/math.js
CHANGED
package/lib/cjs/number.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
var func = require('./func.js');
|
|
10
10
|
var string = require('./string.js');
|
|
11
|
+
var type = require('./type.js');
|
|
11
12
|
|
|
12
13
|
const HEX_POOL = `${string.STRING_ARABIC_NUMERALS}${string.STRING_UPPERCASE_ALPHA}${string.STRING_LOWERCASE_ALPHA}`;
|
|
13
14
|
const supportBigInt = typeof BigInt !== 'undefined';
|
|
@@ -45,38 +46,74 @@ function numberToHex(decimal, hexPool = HEX_POOL) {
|
|
|
45
46
|
return ret.join('');
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
|
-
*
|
|
49
|
+
* 将数字转换为携带单位的字符串
|
|
49
50
|
* @param {number | string} num
|
|
50
51
|
* @param {Array<string>} units
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {number} exponent
|
|
52
|
+
* @param {INumberAbbr} options default: { ratio: 1000, decimals: 0, separator: ' ' }
|
|
53
53
|
* @returns {string}
|
|
54
54
|
*/
|
|
55
|
-
const numberAbbr = (num, units,
|
|
55
|
+
const numberAbbr = (num, units, options = { ratio: 1000, decimals: 0, separator: ' ' }) => {
|
|
56
|
+
const { ratio = 1000, decimals = 0, separator = ' ' } = options;
|
|
56
57
|
const { length } = units;
|
|
57
58
|
if (length === 0)
|
|
58
|
-
throw new Error('
|
|
59
|
+
throw new Error('At least one unit is required');
|
|
59
60
|
let num2 = Number(num);
|
|
60
61
|
let times = 0;
|
|
61
62
|
while (num2 >= ratio && times < length - 1) {
|
|
62
63
|
num2 = num2 / ratio;
|
|
63
64
|
times++;
|
|
64
65
|
}
|
|
65
|
-
const value = num2.toFixed(
|
|
66
|
+
const value = num2.toFixed(decimals);
|
|
66
67
|
const unit = units[times];
|
|
67
|
-
return value
|
|
68
|
+
return String(value) + separator + unit;
|
|
68
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Converting file size in bytes to human-readable string
|
|
72
|
+
* reference: https://zh.wikipedia.org/wiki/%E5%8D%83%E5%AD%97%E8%8A%82
|
|
73
|
+
* @param {number | string} num bytes Number in Bytes
|
|
74
|
+
* @param {IHumanFileSizeOptions} options default: { decimals = 0, si = false, separator = ' ' }
|
|
75
|
+
* si: True to use metric (SI) units, aka powers of 1000, the units is
|
|
76
|
+
* ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'].
|
|
77
|
+
* False to use binary (IEC), aka powers of 1024, the units is
|
|
78
|
+
* ['Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
function humanFileSize(num, options) {
|
|
82
|
+
const { decimals = 0, si = false, separator = ' ', maxUnit } = options;
|
|
83
|
+
const units = si
|
|
84
|
+
? ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
85
|
+
: ['Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
86
|
+
if (!type.isNullOrUnDef(maxUnit)) {
|
|
87
|
+
const targetIndex = units.findIndex(el => el === maxUnit);
|
|
88
|
+
if (targetIndex !== -1) {
|
|
89
|
+
units.splice(targetIndex + 1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return numberAbbr(num, units, { ratio: si ? 1000 : 1024, decimals, separator });
|
|
93
|
+
}
|
|
69
94
|
/**
|
|
70
95
|
* 将数字格式化成千位分隔符显示的字符串
|
|
71
|
-
* @param {number}
|
|
72
|
-
* @param {
|
|
96
|
+
* @param {number|string} num 数字
|
|
97
|
+
* @param {number} decimals 格式化成指定小数位精度的参数
|
|
73
98
|
* @returns {string}
|
|
74
99
|
*/
|
|
75
|
-
function formatNumber(
|
|
76
|
-
|
|
100
|
+
function formatNumber(num, decimals) {
|
|
101
|
+
if (type.isNullOrUnDef(decimals)) {
|
|
102
|
+
return parseInt(String(num)).toLocaleString();
|
|
103
|
+
}
|
|
104
|
+
let prec = 0;
|
|
105
|
+
if (!type.isNumber(decimals)) {
|
|
106
|
+
throw new Error('Decimals must be a positive number not less than zero');
|
|
107
|
+
}
|
|
108
|
+
else if (decimals > 0) {
|
|
109
|
+
prec = decimals;
|
|
110
|
+
}
|
|
111
|
+
return Number(Number(num).toFixed(prec)).toLocaleString('en-US');
|
|
77
112
|
}
|
|
78
113
|
|
|
79
114
|
exports.HEX_POOL = HEX_POOL;
|
|
115
|
+
exports.formatMoney = formatNumber;
|
|
80
116
|
exports.formatNumber = formatNumber;
|
|
117
|
+
exports.humanFileSize = humanFileSize;
|
|
81
118
|
exports.numberAbbr = numberAbbr;
|
|
82
119
|
exports.numberToHex = numberToHex;
|
package/lib/cjs/object.js
CHANGED
package/lib/cjs/path.js
CHANGED
package/lib/cjs/qs.js
CHANGED
package/lib/cjs/random.js
CHANGED
package/lib/cjs/string.js
CHANGED
package/lib/cjs/tooltip.js
CHANGED
package/lib/cjs/tree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -212,7 +212,7 @@ function flatTree(treeList, options = defaultFieldOptions) {
|
|
|
212
212
|
...node,
|
|
213
213
|
[childField]: [] // 清空子级
|
|
214
214
|
};
|
|
215
|
-
|
|
215
|
+
type.objectHas(item, childField) && delete item[childField];
|
|
216
216
|
res.push(item);
|
|
217
217
|
if (node[childField]) {
|
|
218
218
|
const children = node[childField].map(item => ({
|
package/lib/cjs/type.js
CHANGED
package/lib/cjs/unique.js
CHANGED
package/lib/cjs/url.js
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var type = require('./type.js');
|
|
9
10
|
var path = require('./path.js');
|
|
10
11
|
var qs = require('./qs.js');
|
|
11
12
|
|
|
12
|
-
const anchorEl = document.createElement('a');
|
|
13
13
|
/**
|
|
14
14
|
* url 解析
|
|
15
15
|
* @param {string} url
|
|
16
|
+
* @param {boolean} isModernApi 使用现代API:URL, 默认true (对无效url解析会抛错), 否则使用a标签来解析(兼容性更强)
|
|
16
17
|
* @returns {Url}
|
|
17
18
|
*/
|
|
18
|
-
const urlParse = (url) => {
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
|
21
30
|
// fix: ie 浏览器下,解析出来的 pathname 是没有 / 根的
|
|
22
31
|
const pathname = path.pathJoin('/', _pathname);
|
|
23
32
|
const auth = username && password ? `${username}:${password}` : '';
|
|
24
33
|
const query = search.replace(/^\?/, '');
|
|
25
34
|
const searchParams = qs.qsParse(query);
|
|
26
35
|
const path$1 = `${pathname}${search}`;
|
|
36
|
+
urlObj = null;
|
|
27
37
|
return {
|
|
28
38
|
protocol,
|
|
29
39
|
auth,
|
package/lib/cjs/validator.js
CHANGED
package/lib/cjs/variable.js
CHANGED
package/lib/cjs/watermark.js
CHANGED
package/lib/cjs/we-decode.js
CHANGED
package/lib/es/array.js
CHANGED
package/lib/es/async.js
CHANGED
package/lib/es/base64.js
CHANGED
package/lib/es/clipboard.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { setStyle } from './dom.js';
|
|
8
|
-
|
|
9
|
-
const textEl = document.createElement('textarea');
|
|
10
|
-
setStyle(textEl, {
|
|
11
|
-
position: 'absolute',
|
|
12
|
-
top: '-9999px',
|
|
13
|
-
left: '-9999px',
|
|
14
|
-
opacity: 0
|
|
15
|
-
});
|
|
16
|
-
document.body.appendChild(textEl);
|
|
17
7
|
/**
|
|
18
8
|
* 复制文本
|
|
19
9
|
* @param {string} text
|
|
20
10
|
*/
|
|
21
11
|
function copyText(text) {
|
|
12
|
+
const textEl = document.createElement('textarea');
|
|
13
|
+
textEl.style.position = 'absolute';
|
|
14
|
+
textEl.style.top = '-9999px';
|
|
15
|
+
textEl.style.left = '-9999px';
|
|
22
16
|
textEl.value = text;
|
|
17
|
+
document.body.appendChild(textEl);
|
|
23
18
|
textEl.focus({ preventScroll: true });
|
|
24
19
|
textEl.select();
|
|
25
20
|
try {
|
|
26
21
|
document.execCommand('copy');
|
|
27
22
|
textEl.blur();
|
|
23
|
+
document.body.removeChild(textEl);
|
|
28
24
|
}
|
|
29
25
|
catch (err) {
|
|
30
26
|
// ignore
|
package/lib/es/cloneDeep.js
CHANGED
package/lib/es/cookie.js
CHANGED
package/lib/es/date.js
CHANGED
package/lib/es/dom.js
CHANGED
package/lib/es/download.js
CHANGED
package/lib/es/easing.js
CHANGED
package/lib/es/file.js
CHANGED
package/lib/es/func.js
CHANGED
package/lib/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.9.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -21,7 +21,7 @@ export { chooseLocalFile, compressImg, supportCanvas } from './file.js';
|
|
|
21
21
|
export { genCanvasWM } from './watermark.js';
|
|
22
22
|
export { debounce, getGlobal, once, setGlobal, throttle } from './func.js';
|
|
23
23
|
export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js';
|
|
24
|
-
export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
|
|
24
|
+
export { HEX_POOL, formatNumber as formatMoney, formatNumber, humanFileSize, numberAbbr, numberToHex } from './number.js';
|
|
25
25
|
export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
|
|
26
26
|
export { tooltipEvent } from './tooltip.js';
|
|
27
27
|
export { flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById } from './tree.js';
|
package/lib/es/isEqual.js
CHANGED
package/lib/es/math.js
CHANGED