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
@@ -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
  */
@@ -27,18 +27,30 @@ var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
27
27
 
28
28
  var float32ArraySupported = typeof Float32Array === 'function';
29
29
 
30
- function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
31
- function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
32
- function C (aA1) { return 3.0 * aA1; }
30
+ function A(aA1, aA2) {
31
+ return 1.0 - 3.0 * aA2 + 3.0 * aA1;
32
+ }
33
+ function B(aA1, aA2) {
34
+ return 3.0 * aA2 - 6.0 * aA1;
35
+ }
36
+ function C(aA1) {
37
+ return 3.0 * aA1;
38
+ }
33
39
 
34
40
  // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
35
- function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; }
41
+ function calcBezier(aT, aA1, aA2) {
42
+ return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
43
+ }
36
44
 
37
45
  // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
38
- function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); }
46
+ function getSlope(aT, aA1, aA2) {
47
+ return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
48
+ }
39
49
 
40
- function binarySubdivide (aX, aA, aB, mX1, mX2) {
41
- var currentX, currentT, i = 0;
50
+ function binarySubdivide(aX, aA, aB, mX1, mX2) {
51
+ var currentX,
52
+ currentT,
53
+ i = 0;
42
54
  do {
43
55
  currentT = aA + (aB - aA) / 2.0;
44
56
  currentX = calcBezier(currentT, mX1, mX2) - aX;
@@ -51,23 +63,23 @@ function binarySubdivide (aX, aA, aB, mX1, mX2) {
51
63
  return currentT;
52
64
  }
53
65
 
54
- function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
55
- for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
56
- var currentSlope = getSlope(aGuessT, mX1, mX2);
57
- if (currentSlope === 0.0) {
58
- return aGuessT;
59
- }
60
- var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
61
- aGuessT -= currentX / currentSlope;
62
- }
63
- return aGuessT;
66
+ function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
67
+ for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
68
+ var currentSlope = getSlope(aGuessT, mX1, mX2);
69
+ if (currentSlope === 0.0) {
70
+ return aGuessT;
71
+ }
72
+ var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
73
+ aGuessT -= currentX / currentSlope;
74
+ }
75
+ return aGuessT;
64
76
  }
65
77
 
66
- function LinearEasing (x) {
78
+ function LinearEasing(x) {
67
79
  return x;
68
80
  }
69
81
 
70
- var src = function bezier (mX1, mY1, mX2, mY2) {
82
+ var src = function bezier(mX1, mY1, mX2, mY2) {
71
83
  if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) {
72
84
  throw new Error('bezier x values must be in [0, 1] range');
73
85
  }
@@ -82,7 +94,7 @@ var src = function bezier (mX1, mY1, mX2, mY2) {
82
94
  sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
83
95
  }
84
96
 
85
- function getTForX (aX) {
97
+ function getTForX(aX) {
86
98
  var intervalStart = 0.0;
87
99
  var currentSample = 1;
88
100
  var lastSample = kSplineTableSize - 1;
@@ -106,7 +118,7 @@ var src = function bezier (mX1, mY1, mX2, mY2) {
106
118
  }
107
119
  }
108
120
 
109
- return function BezierEasing (x) {
121
+ return function BezierEasing(x) {
110
122
  // Because JavaScript number are imprecise, we should guarantee the extremes are right.
111
123
  if (x === 0) {
112
124
  return 0;
@@ -118,6 +130,6 @@ var src = function bezier (mX1, mY1, mX2, mY2) {
118
130
  };
119
131
  };
120
132
 
121
- var bezier = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(src);
133
+ var bezier = /*@__PURE__*/ _commonjsHelpers.getDefaultExportFromCjs(src);
122
134
 
123
135
  exports.default = bezier;
@@ -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 @@ var type = require('./type.js');
13
13
  const HEX_POOL = `${string.STRING_ARABIC_NUMERALS}${string.STRING_UPPERCASE_ALPHA}${string.STRING_LOWERCASE_ALPHA}`;
14
14
  const supportBigInt = typeof BigInt !== 'undefined';
15
15
  const jsbi = () => func.getGlobal('JSBI');
16
- const toBigInt = (n) => (supportBigInt ? BigInt(n) : jsbi().BigInt(n));
16
+ const toBigInt = n => (supportBigInt ? BigInt(n) : jsbi().BigInt(n));
17
17
  const divide = (x, y) => (supportBigInt ? x / y : jsbi().divide(x, y));
18
18
  const remainder = (x, y) => (supportBigInt ? x % y : jsbi().remainder(x, y));
19
19
  /**
@@ -23,27 +23,26 @@ const remainder = (x, y) => (supportBigInt ? x % y : jsbi().remainder(x, y));
23
23
  * @returns {string}
24
24
  */
25
25
  function numberToHex(decimal, hexPool = HEX_POOL) {
26
- if (hexPool.length < 2)
27
- throw new Error('进制池长度不能少于 2');
28
- if (!supportBigInt) {
29
- throw new Error('需要安装 jsbi 模块并将 JSBI 设置为全局变量:\nimport JSBI from "jsbi"; window.JSBI = JSBI;');
26
+ if (hexPool.length < 2) throw new Error('进制池长度不能少于 2');
27
+ if (!supportBigInt) {
28
+ throw new Error('需要安装 jsbi 模块并将 JSBI 设置为全局变量:\nimport JSBI from "jsbi"; window.JSBI = JSBI;');
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
31
+ let bigInt = toBigInt(decimal);
32
+ const ret = [];
33
+ const { length } = hexPool;
34
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
35
+ const bigLength = toBigInt(length);
36
+ const execute = () => {
37
+ const y = Number(remainder(bigInt, bigLength));
38
+ bigInt = divide(bigInt, bigLength);
39
+ ret.unshift(hexPool[y]);
40
+ if (bigInt > 0) {
41
+ execute();
30
42
  }
31
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
32
- let bigInt = toBigInt(decimal);
33
- const ret = [];
34
- const { length } = hexPool;
35
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
36
- const bigLength = toBigInt(length);
37
- const execute = () => {
38
- const y = Number(remainder(bigInt, bigLength));
39
- bigInt = divide(bigInt, bigLength);
40
- ret.unshift(hexPool[y]);
41
- if (bigInt > 0) {
42
- execute();
43
- }
44
- };
45
- execute();
46
- return ret.join('');
43
+ };
44
+ execute();
45
+ return ret.join('');
47
46
  }
48
47
  /**
49
48
  * 将数字转换为携带单位的字符串
@@ -53,19 +52,18 @@ function numberToHex(decimal, hexPool = HEX_POOL) {
53
52
  * @returns {string}
54
53
  */
55
54
  const numberAbbr = (num, units, options = { ratio: 1000, decimals: 0, separator: ' ' }) => {
56
- const { ratio = 1000, decimals = 0, separator = ' ' } = options;
57
- const { length } = units;
58
- if (length === 0)
59
- throw new Error('At least one unit is required');
60
- let num2 = Number(num);
61
- let times = 0;
62
- while (num2 >= ratio && times < length - 1) {
63
- num2 = num2 / ratio;
64
- times++;
65
- }
66
- const value = num2.toFixed(decimals);
67
- const unit = units[times];
68
- return String(value) + separator + unit;
55
+ const { ratio = 1000, decimals = 0, separator = ' ' } = options;
56
+ const { length } = units;
57
+ if (length === 0) throw new Error('At least one unit is required');
58
+ let num2 = Number(num);
59
+ let times = 0;
60
+ while (num2 >= ratio && times < length - 1) {
61
+ num2 = num2 / ratio;
62
+ times++;
63
+ }
64
+ const value = num2.toFixed(decimals);
65
+ const unit = units[times];
66
+ return String(value) + separator + unit;
69
67
  };
70
68
  /**
71
69
  * Converting file size in bytes to human-readable string
@@ -79,23 +77,23 @@ const numberAbbr = (num, units, options = { ratio: 1000, decimals: 0, separator:
79
77
  * @returns
80
78
  */
81
79
  function humanFileSize(num, options = { decimals: 0, si: false, separator: ' ' }) {
82
- const { decimals = 0, si = false, separator = ' ', baseUnit, maxUnit } = options;
83
- let 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(baseUnit)) {
87
- const targetIndex = units.findIndex(el => el === baseUnit);
88
- if (targetIndex !== -1) {
89
- units = units.slice(targetIndex);
90
- }
80
+ const { decimals = 0, si = false, separator = ' ', baseUnit, maxUnit } = options;
81
+ let units = si
82
+ ? ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
83
+ : ['Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
84
+ if (!type.isNullOrUnDef(baseUnit)) {
85
+ const targetIndex = units.findIndex(el => el === baseUnit);
86
+ if (targetIndex !== -1) {
87
+ units = units.slice(targetIndex);
91
88
  }
92
- if (!type.isNullOrUnDef(maxUnit)) {
93
- const targetIndex = units.findIndex(el => el === maxUnit);
94
- if (targetIndex !== -1) {
95
- units.splice(targetIndex + 1);
96
- }
89
+ }
90
+ if (!type.isNullOrUnDef(maxUnit)) {
91
+ const targetIndex = units.findIndex(el => el === maxUnit);
92
+ if (targetIndex !== -1) {
93
+ units.splice(targetIndex + 1);
97
94
  }
98
- return numberAbbr(num, units, { ratio: si ? 1000 : 1024, decimals, separator });
95
+ }
96
+ return numberAbbr(num, units, { ratio: si ? 1000 : 1024, decimals, separator });
99
97
  }
100
98
  /**
101
99
  * 将数字格式化成千位分隔符显示的字符串
@@ -104,17 +102,16 @@ function humanFileSize(num, options = { decimals: 0, si: false, separator: ' ' }
104
102
  * @returns {string}
105
103
  */
106
104
  function formatNumber(num, decimals) {
107
- if (type.isNullOrUnDef(decimals)) {
108
- return parseInt(String(num)).toLocaleString();
109
- }
110
- let prec = 0;
111
- if (!type.isNumber(decimals)) {
112
- throw new Error('Decimals must be a positive number not less than zero');
113
- }
114
- else if (decimals > 0) {
115
- prec = decimals;
116
- }
117
- return Number(Number(num).toFixed(prec)).toLocaleString('en-US');
105
+ if (type.isNullOrUnDef(decimals)) {
106
+ return parseInt(String(num)).toLocaleString();
107
+ }
108
+ let prec = 0;
109
+ if (!type.isNumber(decimals)) {
110
+ throw new Error('Decimals must be a positive number not less than zero');
111
+ } else if (decimals > 0) {
112
+ prec = decimals;
113
+ }
114
+ return Number(Number(num).toFixed(prec)).toLocaleString('en-US');
118
115
  }
119
116
 
120
117
  exports.HEX_POOL = HEX_POOL;
@@ -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,15 +13,13 @@ var type = require('./type.js');
13
13
  * @param {object} obj
14
14
  * @returns {boolean}
15
15
  */
16
- const isPlainObject = (obj) => {
17
- if (!type.isObject(obj))
18
- return false;
19
- const proto = Object.getPrototypeOf(obj);
20
- // 对象无原型
21
- if (!proto)
22
- return true;
23
- // 是否对象直接实例
24
- return proto === Object.prototype;
16
+ const isPlainObject = obj => {
17
+ if (!type.isObject(obj)) return false;
18
+ const proto = Object.getPrototypeOf(obj);
19
+ // 对象无原型
20
+ if (!proto) return true;
21
+ // 是否对象直接实例
22
+ return proto === Object.prototype;
25
23
  };
26
24
  /**
27
25
  * 遍历对象,返回 false 中断遍历
@@ -29,14 +27,12 @@ const isPlainObject = (obj) => {
29
27
  * @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
30
28
  */
31
29
  function objectEach(obj, iterator) {
32
- for (const key in obj) {
33
- if (!type.objectHas(obj, key))
34
- continue;
35
- if (iterator(obj[key], key) === false)
36
- break;
37
- }
38
- // @ts-ignore
39
- obj = null;
30
+ for (const key in obj) {
31
+ if (!type.objectHas(obj, key)) continue;
32
+ if (iterator(obj[key], key) === false) break;
33
+ }
34
+ // @ts-ignore
35
+ obj = null;
40
36
  }
41
37
  /**
42
38
  * 异步遍历对象,返回 false 中断遍历
@@ -44,12 +40,10 @@ function objectEach(obj, iterator) {
44
40
  * @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
45
41
  */
46
42
  async function objectEachAsync(obj, iterator) {
47
- for (const key in obj) {
48
- if (!type.objectHas(obj, key))
49
- continue;
50
- if ((await iterator(obj[key], key)) === false)
51
- break;
52
- }
43
+ for (const key in obj) {
44
+ if (!type.objectHas(obj, key)) continue;
45
+ if ((await iterator(obj[key], key)) === false) break;
46
+ }
53
47
  }
54
48
  /**
55
49
  * 对象映射
@@ -58,15 +52,14 @@ async function objectEachAsync(obj, iterator) {
58
52
  * @returns {Record<Extract<keyof O, string>, T>}
59
53
  */
60
54
  function objectMap(obj, iterator) {
61
- const obj2 = {};
62
- for (const key in obj) {
63
- if (!type.objectHas(obj, key))
64
- continue;
65
- obj2[key] = iterator(obj[key], key);
66
- }
67
- // @ts-ignore
68
- obj = null;
69
- return obj2;
55
+ const obj2 = {};
56
+ for (const key in obj) {
57
+ if (!type.objectHas(obj, key)) continue;
58
+ obj2[key] = iterator(obj[key], key);
59
+ }
60
+ // @ts-ignore
61
+ obj = null;
62
+ return obj2;
70
63
  }
71
64
  /**
72
65
  * 对象提取
@@ -75,16 +68,16 @@ function objectMap(obj, iterator) {
75
68
  * @returns {Pick<O, ArrayElements<K>>}
76
69
  */
77
70
  function objectPick(obj, keys) {
78
- const obj2 = {};
79
- objectEach(obj, (v, k) => {
80
- if (keys.includes(k)) {
81
- // @ts-ignore
82
- obj2[k] = v;
83
- }
84
- });
85
- // @ts-ignore
86
- obj = null;
87
- return obj2;
71
+ const obj2 = {};
72
+ objectEach(obj, (v, k) => {
73
+ if (keys.includes(k)) {
74
+ // @ts-ignore
75
+ obj2[k] = v;
76
+ }
77
+ });
78
+ // @ts-ignore
79
+ obj = null;
80
+ return obj2;
88
81
  }
89
82
  /**
90
83
  * 对象去除
@@ -93,52 +86,47 @@ function objectPick(obj, keys) {
93
86
  * @returns {Pick<O, ArrayElements<K>>}
94
87
  */
95
88
  function objectOmit(obj, keys) {
96
- const obj2 = {};
97
- objectEach(obj, (v, k) => {
98
- if (!keys.includes(k)) {
99
- // @ts-ignore
100
- obj2[k] = v;
101
- }
102
- });
103
- // @ts-ignore
104
- obj = null;
105
- return obj2;
89
+ const obj2 = {};
90
+ objectEach(obj, (v, k) => {
91
+ if (!keys.includes(k)) {
92
+ // @ts-ignore
93
+ obj2[k] = v;
94
+ }
95
+ });
96
+ // @ts-ignore
97
+ obj = null;
98
+ return obj2;
106
99
  }
107
100
  const merge = (map, source, target) => {
108
- if (type.isUndefined(target))
109
- return source;
110
- const sourceType = type.typeIs(source);
111
- const targetType = type.typeIs(target);
112
- if (sourceType !== targetType) {
113
- if (type.isArray(target))
114
- return merge(map, [], target);
115
- if (type.isObject(target))
116
- return merge(map, {}, target);
117
- return target;
118
- }
119
- // 朴素对象
120
- if (isPlainObject(target)) {
121
- const exist = map.get(target);
122
- if (exist)
123
- return exist;
124
- map.set(target, source);
125
- objectEach(target, (val, key) => {
126
- source[key] = merge(map, source[key], val);
127
- });
128
- return source;
129
- }
130
- // 数组
131
- else if (type.isArray(target)) {
132
- const exist = map.get(target);
133
- if (exist)
134
- return exist;
135
- map.set(target, source);
136
- target.forEach((val, index) => {
137
- source[index] = merge(map, source[index], val);
138
- });
139
- return source;
140
- }
101
+ if (type.isUndefined(target)) return source;
102
+ const sourceType = type.typeIs(source);
103
+ const targetType = type.typeIs(target);
104
+ if (sourceType !== targetType) {
105
+ if (type.isArray(target)) return merge(map, [], target);
106
+ if (type.isObject(target)) return merge(map, {}, target);
141
107
  return target;
108
+ }
109
+ // 朴素对象
110
+ if (isPlainObject(target)) {
111
+ const exist = map.get(target);
112
+ if (exist) return exist;
113
+ map.set(target, source);
114
+ objectEach(target, (val, key) => {
115
+ source[key] = merge(map, source[key], val);
116
+ });
117
+ return source;
118
+ }
119
+ // 数组
120
+ else if (type.isArray(target)) {
121
+ const exist = map.get(target);
122
+ if (exist) return exist;
123
+ map.set(target, source);
124
+ target.forEach((val, index) => {
125
+ source[index] = merge(map, source[index], val);
126
+ });
127
+ return source;
128
+ }
129
+ return target;
142
130
  };
143
131
  /**
144
132
  * 对象合并,返回原始对象
@@ -147,14 +135,14 @@ const merge = (map, source, target) => {
147
135
  * @returns {R}
148
136
  */
149
137
  function objectAssign(source, ...targets) {
150
- const map = new Map();
151
- for (let i = 0, len = targets.length; i < len; i++) {
152
- const target = targets[i];
153
- // @ts-ignore
154
- source = merge(map, source, target);
155
- }
156
- map.clear();
157
- return source;
138
+ const map = new Map();
139
+ for (let i = 0, len = targets.length; i < len; i++) {
140
+ const target = targets[i];
141
+ // @ts-ignore
142
+ source = merge(map, source, target);
143
+ }
144
+ map.clear();
145
+ return source;
158
146
  }
159
147
  /**
160
148
  * 对象填充
@@ -164,13 +152,13 @@ function objectAssign(source, ...targets) {
164
152
  * @returns {R}
165
153
  */
166
154
  function objectFill(source, target, fillable) {
167
- const _fillable = fillable || ((source, target, key) => source[key] === undefined);
168
- objectEach(target, (val, key) => {
169
- if (_fillable(source, target, key)) {
170
- source[key] = val;
171
- }
172
- });
173
- return source;
155
+ const _fillable = fillable || ((source, target, key) => source[key] === undefined);
156
+ objectEach(target, (val, key) => {
157
+ if (_fillable(source, target, key)) {
158
+ source[key] = val;
159
+ }
160
+ });
161
+ return source;
174
162
  }
175
163
  /**
176
164
  * 获取对象/数组指定层级下的属性值(现在可用ES6+的可选链?.来替代)
@@ -180,32 +168,30 @@ function objectFill(source, target, fillable) {
180
168
  * @returns
181
169
  */
182
170
  function objectGet(obj, path, strict = false) {
183
- path = path.replace(/\[(\w+)\]/g, '.$1');
184
- path = path.replace(/^\./, '');
185
- const keyArr = path.split('.');
186
- let tempObj = obj;
187
- let i = 0;
188
- for (let len = keyArr.length; i < len - 1; ++i) {
189
- const key = keyArr[i];
190
- if (type.isNumber(Number(key)) && Array.isArray(tempObj)) {
191
- tempObj = tempObj[key];
192
- }
193
- else if (type.isObject(tempObj) && type.objectHas(tempObj, key)) {
194
- tempObj = tempObj[key];
195
- }
196
- else {
197
- tempObj = undefined;
198
- if (strict) {
199
- throw new Error('[Object] objectGet path 路径不正确');
200
- }
201
- break;
202
- }
171
+ path = path.replace(/\[(\w+)\]/g, '.$1');
172
+ path = path.replace(/^\./, '');
173
+ const keyArr = path.split('.');
174
+ let tempObj = obj;
175
+ let i = 0;
176
+ for (let len = keyArr.length; i < len - 1; ++i) {
177
+ const key = keyArr[i];
178
+ if (type.isNumber(Number(key)) && Array.isArray(tempObj)) {
179
+ tempObj = tempObj[key];
180
+ } else if (type.isObject(tempObj) && type.objectHas(tempObj, key)) {
181
+ tempObj = tempObj[key];
182
+ } else {
183
+ tempObj = undefined;
184
+ if (strict) {
185
+ throw new Error('[Object] objectGet path 路径不正确');
186
+ }
187
+ break;
203
188
  }
204
- return {
205
- p: tempObj,
206
- k: tempObj ? keyArr[i] : undefined,
207
- v: tempObj ? tempObj[keyArr[i]] : undefined
208
- };
189
+ }
190
+ return {
191
+ p: tempObj,
192
+ k: tempObj ? keyArr[i] : undefined,
193
+ v: tempObj ? tempObj[keyArr[i]] : undefined
194
+ };
209
195
  }
210
196
 
211
197
  exports.isPlainObject = isPlainObject;
package/dist/cjs/path.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
  */
@@ -11,48 +11,44 @@
11
11
  * @param {string} path
12
12
  * @returns {string}
13
13
  */
14
- const pathNormalize = (path) => {
15
- const slices = path
16
- .replace(/\\/g, '/')
17
- .replace(/\/{2,}/g, '/')
18
- .replace(/\.{3,}/g, '..')
19
- .replace(/\/\.\//g, '/')
20
- .split('/')
21
- .map(point => point.trim());
22
- const isCurrentSlice = (slice) => slice === '.';
23
- const isParentSlice = (slice) => slice === '..';
24
- const points = [];
25
- let inPoints = false;
26
- const push = (point) => {
27
- points.push(point);
28
- };
29
- const back = () => {
30
- if (points.length === 0)
31
- return;
32
- const lastSlice = points[points.length - 1];
33
- if (isParentSlice(lastSlice)) {
34
- points.push('..');
35
- }
36
- else {
37
- points.pop();
38
- }
39
- };
40
- slices.forEach(slice => {
41
- const isCurrent = isCurrentSlice(slice);
42
- const isParent = isParentSlice(slice);
43
- // 未进入实际路径
44
- if (!inPoints) {
45
- push(slice);
46
- inPoints = !isCurrent && !isParent;
47
- return;
48
- }
49
- if (isCurrent)
50
- return;
51
- if (isParent)
52
- return back();
53
- push(slice);
54
- });
55
- return points.join('/');
14
+ const pathNormalize = path => {
15
+ const slices = path
16
+ .replace(/\\/g, '/')
17
+ .replace(/\/{2,}/g, '/')
18
+ .replace(/\.{3,}/g, '..')
19
+ .replace(/\/\.\//g, '/')
20
+ .split('/')
21
+ .map(point => point.trim());
22
+ const isCurrentSlice = slice => slice === '.';
23
+ const isParentSlice = slice => slice === '..';
24
+ const points = [];
25
+ let inPoints = false;
26
+ const push = point => {
27
+ points.push(point);
28
+ };
29
+ const back = () => {
30
+ if (points.length === 0) return;
31
+ const lastSlice = points[points.length - 1];
32
+ if (isParentSlice(lastSlice)) {
33
+ points.push('..');
34
+ } else {
35
+ points.pop();
36
+ }
37
+ };
38
+ slices.forEach(slice => {
39
+ const isCurrent = isCurrentSlice(slice);
40
+ const isParent = isParentSlice(slice);
41
+ // 未进入实际路径
42
+ if (!inPoints) {
43
+ push(slice);
44
+ inPoints = !isCurrent && !isParent;
45
+ return;
46
+ }
47
+ if (isCurrent) return;
48
+ if (isParent) return back();
49
+ push(slice);
50
+ });
51
+ return points.join('/');
56
52
  };
57
53
  /**
58
54
  * 路径合并