sard-uniapp 1.19.5 → 1.20.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.
Files changed (177) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/components/calendar/README.md +20 -20
  4. package/components/calendar/calendar.vue +1 -1
  5. package/components/calendar-input/README.md +10 -10
  6. package/components/calendar-input/calendar-input.vue +2 -2
  7. package/components/calendar-month/calendar-month.vue +17 -21
  8. package/components/calendar-popout/calendar-popout.vue +1 -1
  9. package/components/card/README.md +16 -8
  10. package/components/card/card.vue +7 -1
  11. package/components/card/common.d.ts +2 -0
  12. package/components/card/index.scss +30 -2
  13. package/components/card/variables.scss +16 -1
  14. package/components/checkbox/common.d.ts +1 -0
  15. package/components/checkbox/common.js +1 -0
  16. package/components/checkbox-input/checkbox-input.vue +9 -0
  17. package/components/checkbox-popout/README.md +27 -6
  18. package/components/checkbox-popout/checkbox-popout.vue +113 -47
  19. package/components/checkbox-popout/common.d.ts +3 -0
  20. package/components/checkbox-popout/index.scss +16 -0
  21. package/components/config/index.d.ts +6 -0
  22. package/components/config/index.js +6 -0
  23. package/components/datetime-picker/README.md +1 -71
  24. package/components/datetime-picker/common.d.ts +1 -0
  25. package/components/datetime-picker/common.js +21 -8
  26. package/components/datetime-picker/datetime-picker.vue +3 -3
  27. package/components/datetime-picker-input/README.md +10 -10
  28. package/components/datetime-picker-input/datetime-picker-input.vue +2 -2
  29. package/components/datetime-picker-popout/datetime-picker-popout.vue +1 -1
  30. package/components/datetime-range-picker/datetime-range-picker.vue +12 -10
  31. package/components/datetime-range-picker-input/README.md +10 -10
  32. package/components/datetime-range-picker-input/datetime-range-picker-input.vue +2 -2
  33. package/components/datetime-range-picker-popout/README.md +0 -6
  34. package/components/datetime-range-picker-popout/datetime-range-picker-popout.vue +11 -8
  35. package/components/floating-bubble/floating-bubble.vue +3 -3
  36. package/components/form/README.md +19 -19
  37. package/components/form/form.vue +1 -1
  38. package/components/icon/icon.d.ts +1 -1
  39. package/components/indexes/README.md +4 -0
  40. package/components/indexes-nav/indexes-nav.vue +2 -2
  41. package/components/keyboard/common.d.ts +1 -2
  42. package/components/keyboard/common.js +2 -11
  43. package/components/keyboard/keyboard.d.ts +2 -2
  44. package/components/list-item/index.scss +4 -0
  45. package/components/locale/lang/en-US.d.ts +4 -0
  46. package/components/locale/lang/en-US.js +4 -0
  47. package/components/locale/lang/zh-CN.d.ts +4 -0
  48. package/components/locale/lang/zh-CN.js +4 -0
  49. package/components/marquee/README.md +8 -2
  50. package/components/marquee/marquee.vue +9 -1
  51. package/components/notice-bar/README.md +8 -2
  52. package/components/notice-bar/notice-bar.vue +14 -8
  53. package/components/notify/notify.d.ts +1 -1
  54. package/components/notify-agent/notify-agent.d.ts +1 -1
  55. package/components/pagination/pagination.vue +2 -2
  56. package/components/popover/utils.js +4 -4
  57. package/components/pull-down-refresh/common.d.ts +1 -1
  58. package/components/radio/common.d.ts +1 -0
  59. package/components/radio/common.js +1 -0
  60. package/components/radio-input/radio-input.vue +6 -0
  61. package/components/radio-popout/README.md +20 -6
  62. package/components/radio-popout/common.d.ts +2 -0
  63. package/components/radio-popout/index.scss +4 -0
  64. package/components/radio-popout/radio-popout.vue +91 -45
  65. package/components/read-more/README.md +82 -0
  66. package/components/read-more/common.d.ts +24 -0
  67. package/components/read-more/common.js +2 -0
  68. package/components/read-more/index.d.ts +1 -0
  69. package/components/read-more/index.js +1 -0
  70. package/components/read-more/index.scss +41 -0
  71. package/components/read-more/read-more.d.ts +20 -0
  72. package/components/read-more/read-more.vue +168 -0
  73. package/components/read-more/variables.scss +12 -0
  74. package/components/resize-sensor/README.md +55 -0
  75. package/components/resize-sensor/common.d.ts +19 -0
  76. package/components/resize-sensor/common.js +2 -0
  77. package/components/resize-sensor/index.d.ts +1 -0
  78. package/components/resize-sensor/index.js +1 -0
  79. package/components/resize-sensor/index.scss +33 -0
  80. package/components/resize-sensor/resize-sensor.d.ts +16 -0
  81. package/components/resize-sensor/resize-sensor.vue +152 -0
  82. package/components/scroll-list/README.md +79 -0
  83. package/components/scroll-list/common.d.ts +23 -0
  84. package/components/scroll-list/common.js +1 -0
  85. package/components/scroll-list/index.d.ts +1 -0
  86. package/components/scroll-list/index.js +1 -0
  87. package/components/scroll-list/index.scss +35 -0
  88. package/components/scroll-list/scroll-list.d.ts +20 -0
  89. package/components/scroll-list/scroll-list.vue +158 -0
  90. package/components/scroll-list/variables.scss +11 -0
  91. package/components/sidebar/README.md +8 -8
  92. package/components/sidebar/sidebar.vue +1 -1
  93. package/components/slider/slider.vue +4 -4
  94. package/components/stepper/stepper.vue +2 -2
  95. package/components/sticky/README.md +92 -0
  96. package/components/sticky/common.d.ts +15 -0
  97. package/components/sticky/common.js +1 -0
  98. package/components/sticky/index.d.ts +1 -0
  99. package/components/sticky/index.js +1 -0
  100. package/components/sticky/index.scss +18 -0
  101. package/components/sticky/sticky.d.ts +10 -0
  102. package/components/sticky/sticky.vue +190 -0
  103. package/components/sticky-box/common.d.ts +19 -0
  104. package/components/sticky-box/common.js +1 -0
  105. package/components/sticky-box/index.d.ts +1 -0
  106. package/components/sticky-box/index.js +1 -0
  107. package/components/sticky-box/index.scss +19 -0
  108. package/components/sticky-box/sticky-box.d.ts +10 -0
  109. package/components/sticky-box/sticky-box.vue +82 -0
  110. package/components/style/mixins/border.scss +101 -38
  111. package/components/style/variables-dark.scss +4 -0
  112. package/components/style/variables.scss +8 -0
  113. package/components/table/table.vue +2 -1
  114. package/components/table-fixation/table-fixation.vue +2 -1
  115. package/components/toast/toast.d.ts +1 -1
  116. package/components/toast-agent/toast-agent.d.ts +1 -1
  117. package/components/tree/tree.d.ts +1 -1
  118. package/components/tree-node/tree-node.vue +2 -2
  119. package/components/upload/README.md +23 -15
  120. package/components/upload/common.d.ts +6 -4
  121. package/components/upload/upload.d.ts +2 -0
  122. package/components/upload/upload.vue +51 -13
  123. package/components/upload/utils.d.ts +1 -0
  124. package/components/upload/utils.js +2 -0
  125. package/components/upload-preview/index.scss +1 -0
  126. package/components/upload-preview/upload-preview.d.ts +6 -4
  127. package/components/upload-preview/upload-preview.vue +17 -24
  128. package/global.d.ts +5 -0
  129. package/index.d.ts +5 -0
  130. package/index.js +5 -0
  131. package/index.scss +2 -0
  132. package/package.json +4 -2
  133. package/use/index.d.ts +4 -0
  134. package/use/index.js +4 -0
  135. package/use/useIndeterminate.d.ts +10 -0
  136. package/use/useIndeterminate.js +27 -0
  137. package/use/useIntersectionObserver.d.ts +16 -0
  138. package/use/useIntersectionObserver.js +52 -0
  139. package/use/useSimulatedClick.js +2 -2
  140. package/use/useSimulatedPress.js +2 -2
  141. package/use/useSingleTask.d.ts +6 -0
  142. package/use/useSingleTask.js +40 -0
  143. package/use/useWindowResize.d.ts +4 -0
  144. package/use/useWindowResize.js +15 -0
  145. package/utils/array.d.ts +28 -0
  146. package/utils/array.js +90 -0
  147. package/utils/common.d.ts +3 -0
  148. package/utils/common.js +1 -0
  149. package/utils/date.d.ts +84 -11
  150. package/utils/date.js +120 -63
  151. package/utils/dom.js +2 -0
  152. package/utils/geometry.d.ts +56 -38
  153. package/utils/geometry.js +56 -30
  154. package/utils/index.d.ts +8 -1
  155. package/utils/index.js +8 -1
  156. package/utils/is.d.ts +12 -0
  157. package/utils/is.js +16 -0
  158. package/utils/number.d.ts +24 -0
  159. package/utils/number.js +37 -0
  160. package/utils/object.d.ts +29 -0
  161. package/utils/object.js +139 -0
  162. package/utils/persist.d.ts +15 -0
  163. package/utils/persist.js +89 -0
  164. package/utils/physics.d.ts +34 -0
  165. package/utils/physics.js +66 -0
  166. package/utils/request.d.ts +227 -0
  167. package/utils/request.js +249 -0
  168. package/utils/router.d.ts +47 -0
  169. package/utils/router.js +115 -0
  170. package/utils/string.d.ts +46 -0
  171. package/utils/string.js +134 -0
  172. package/utils/url-query.d.ts +19 -0
  173. package/utils/url-query.js +95 -0
  174. package/utils/utils.d.ts +0 -166
  175. package/utils/utils.js +0 -441
  176. package/utils/case.d.ts +0 -4
  177. package/utils/case.js +0 -26
package/utils/utils.js CHANGED
@@ -1,226 +1,4 @@
1
- import { toKebabCase } from './case';
2
1
  import { isPlainObject, isPrimitive } from './is';
3
- /**
4
- * @description: 确保目标是一个数组
5
- * @param {any} target
6
- * @return {array}
7
- */
8
- export function toArray(target) {
9
- return Array.isArray(target) ? target : [target];
10
- }
11
- /**
12
- * @description: 限定数值范围
13
- * @param {number} n 被限定的值
14
- * @param {number} min 最小值
15
- * @param {number} max 最大值
16
- * @return {number} 限定后的值
17
- */
18
- export function minmax(n, min, max) {
19
- return n < min ? min : n > max ? max : n;
20
- }
21
- /**
22
- * @description: 获取小数位数
23
- * @param {number | string} n 要操作的数值
24
- * @return {number}
25
- */
26
- export function getDecimalsLength(n) {
27
- n = n.toString().split('.')[1];
28
- return n ? n.length : 0;
29
- }
30
- /**
31
- * @description: 把一个数四舍五入到指定位数小数
32
- * @param {number} n 要操作的数值
33
- * @param {number} precision 精准度,即小数个数
34
- * @return {number}
35
- */
36
- export function round(n, precision = 0) {
37
- return Math.round(+(n + 'e' + precision)) / 10 ** precision;
38
- }
39
- /**
40
- * @description: 把一个数舍入到指定数的倍数
41
- * @param {number} n 要舍入的数值
42
- * @param {number} m 结果值的因数
43
- * @return {number}
44
- */
45
- export function mround(n, m) {
46
- return round(n - (n % m) + Math.round((n % m) / m) * m, getDecimalsLength(m));
47
- }
48
- /**
49
- * @description: 生成唯一ID,用于设置元素的ID,以便获取
50
- * @param {string} prefix
51
- * @return {string}
52
- */
53
- export function uniqid(prefix = '__sar_') {
54
- return prefix + (~~(Math.random() * 10e8)).toString(36);
55
- }
56
- /**
57
- * @description: 获取阻尼值
58
- * @param {number} value
59
- * @param {number} min
60
- * @param {number} max
61
- * @param {number} damping
62
- * @return {number}
63
- */
64
- export function getDampingValue(value, min, max, damping) {
65
- if (value < min) {
66
- return min + (value - min) * damping;
67
- }
68
- if (value > max) {
69
- return max + (value - max) * damping;
70
- }
71
- return value;
72
- }
73
- /**
74
- * @description: 获取矩形阻尼值
75
- * @param {number} offset 当前的偏移量
76
- * @param {number} areaSize 范围值
77
- * @param {number} viewSize 范围内某个视图尺寸值
78
- * @param {number} damping 阻尼系数
79
- * @return {number}
80
- */
81
- export function getRectDampingValue(offset, areaSize, viewSize, damping) {
82
- const diff = areaSize - viewSize;
83
- let min, max;
84
- if (diff < 0) {
85
- min = diff;
86
- max = 0;
87
- }
88
- else {
89
- min = 0;
90
- max = diff;
91
- }
92
- return getDampingValue(offset, min, max, damping);
93
- }
94
- /**
95
- * @description: 获取范围值
96
- * @param {number} offset 当前的偏移量
97
- * @param {number} areaSize 范围值
98
- * @param {number} viewSize 范围内某个视图尺寸值
99
- * @return {number}
100
- */
101
- export function getInBoundValue(offset, areaSize, viewSize) {
102
- const diff = areaSize - viewSize;
103
- const [min, max] = [0, diff].sort((a, b) => a - b);
104
- return minmax(offset, min, max);
105
- }
106
- /**
107
- * @description: 获取溢出值范围
108
- * @param {number} overflow 最大溢出值
109
- * @param {number} areaSize 范围值
110
- * @param {number} viewSize 范围内某个视图尺寸值
111
- * @return {*}
112
- */
113
- export function getOverflowRangeInArea(overflow, areaSize, viewSize) {
114
- if (areaSize > viewSize) {
115
- return [-overflow, areaSize + overflow];
116
- }
117
- else {
118
- return [areaSize - viewSize - overflow, overflow];
119
- }
120
- }
121
- /**
122
- * @description: 扩散性遍历
123
- * @param {any[]} array 要遍历的数组
124
- * @param {(el: any, spreadIndex: number, index: number) => any} callback 回调函数,接收当前元素、扩散性下标、迭代下标作为参数,
125
- * 如果返回true,则中止遍历
126
- * @param {number} currIndex 遍历开始的下标
127
- * @param {number} direction 开始遍历的方向
128
- * @return {number} 扩散性下标、或开始下标
129
- */
130
- export function spreadEach(array, callback, startIndex = 0, direction = -1) {
131
- const len = array.length;
132
- let spreadIndex = startIndex;
133
- let edge = 0;
134
- direction = -direction;
135
- for (let i = 0; i < len; i++) {
136
- if (edge < 0) {
137
- spreadIndex = len - 1 - i;
138
- }
139
- else if (edge > 0) {
140
- spreadIndex = i;
141
- }
142
- else {
143
- spreadIndex = spreadIndex + direction * i;
144
- edge = spreadIndex === 0 ? 1 : spreadIndex === len - 1 ? -1 : 0;
145
- direction = -direction;
146
- }
147
- if (typeof callback === 'function') {
148
- if (callback(array[spreadIndex], spreadIndex, i)) {
149
- return spreadIndex;
150
- }
151
- }
152
- }
153
- return startIndex;
154
- }
155
- /**
156
- * @description: 深度克隆对象,仅克隆数组和无格式对象,其他类型会被直接返回
157
- * @param {any} target
158
- * @return {any}
159
- */
160
- export function deepClone(target) {
161
- if (Array.isArray(target)) {
162
- return target.map((item) => {
163
- return deepClone(item);
164
- });
165
- }
166
- if (isPlainObject(target)) {
167
- const obj = {};
168
- Object.keys(target).forEach((k) => {
169
- obj[k] = deepClone(target[k]);
170
- });
171
- return obj;
172
- }
173
- return target;
174
- }
175
- /**
176
- * @description: 深拷贝其他对象到第一个对象
177
- * @param args 任意长度参数对象
178
- * @return 返回第一个参数对象
179
- */
180
- export function extend(...args) {
181
- const target = args[0], l = args.length;
182
- let i = 1, options, name, src, copy, copyIsArray, clone;
183
- for (; i < l; i++) {
184
- options = args[i];
185
- if (options !== null && options !== undefined) {
186
- for (name in options) {
187
- src = target[name];
188
- copy = options[name];
189
- // 防止有环
190
- if (target === copy) {
191
- continue;
192
- }
193
- // 深复制
194
- if (copy &&
195
- (isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
196
- if (copyIsArray) {
197
- copyIsArray = false;
198
- clone = src && Array.isArray(src) ? src : [];
199
- }
200
- else {
201
- clone = isPlainObject(src) ? src : {};
202
- }
203
- // 只克隆对象,不移动
204
- target[name] = extend(clone, copy);
205
- // 不添加未定义的值
206
- }
207
- else if (copy !== undefined) {
208
- target[name] = copy;
209
- }
210
- }
211
- }
212
- }
213
- return target;
214
- }
215
- /**
216
- * @description: 判断两数组是否相等,浅比较
217
- * @param {any[]} arr1
218
- * @param {any[]} arr2
219
- * @return {boolean}
220
- */
221
- export function arrayEqual(arr1, arr2) {
222
- return arr1.length === arr1.length && arr1.every((el, i) => el === arr2[i]);
223
- }
224
2
  /**
225
3
  * @description: 判断一个对象是否为看得到的空
226
4
  * @param {any} target
@@ -428,55 +206,6 @@ export function getPageRange(current, pageCount, pageItemCount) {
428
206
  }
429
207
  return [min, max];
430
208
  }
431
- export function treeToMap(tree, keyName, childrenName, parentName) {
432
- const map = {};
433
- function recurse(children, parent) {
434
- children.forEach((node) => {
435
- map[node[keyName]] = node;
436
- node[parentName] = parent;
437
- if (Array.isArray(node[childrenName])) {
438
- recurse(node[childrenName], node);
439
- }
440
- });
441
- }
442
- recurse(tree, null);
443
- return map;
444
- }
445
- /**
446
- * @description: 打乱数组
447
- * @param {any[]} arr 要打乱的数组
448
- * @param {boolean} inPlace 是否改变原数组
449
- * @return {any[]}
450
- */
451
- export function shuffle(arr, inPlace = false) {
452
- if (!inPlace) {
453
- arr = arr.slice();
454
- }
455
- const len = arr.length;
456
- for (let i = len - 1; i >= 0; i--) {
457
- const randomIndex = ~~(Math.random() * (i + 1));
458
- const temp = arr[randomIndex];
459
- arr[randomIndex] = arr[i];
460
- arr[i] = temp;
461
- }
462
- return arr;
463
- }
464
- /**
465
- * @description: 根据原始坐标尺寸和缩放后的坐标尺寸算出转换的原点
466
- * @param {Rect} rect
467
- * @param {Rect} scaleRect
468
- * @return {[number, number]}
469
- */
470
- export function getTransformOrigin(rect, scaleRect) {
471
- const ratio = scaleRect.width / rect.width;
472
- const originX = (rect.x + rect.width / 2 - scaleRect.x - scaleRect.width / 2) /
473
- (ratio - 1) +
474
- rect.width / 2;
475
- const originY = (rect.y + rect.height / 2 - scaleRect.y - scaleRect.height / 2) /
476
- (ratio - 1) +
477
- rect.height / 2;
478
- return [originX, originY];
479
- }
480
209
  /**
481
210
  * @description: 将一个可选单位的字符串或数值拆分为数值和单位组成的数组
482
211
  * @param {number | string} target
@@ -486,177 +215,7 @@ export function splitUnit(target) {
486
215
  const result = /([+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|))([a-z]+|%|)$/i.exec(String(target)) || [0, ''];
487
216
  return [+result[1], result[2]];
488
217
  }
489
- /**
490
- * @description: 链式获取对象值
491
- * @param object
492
- * @param chain 通过点分割的字符串或者字符串数组
493
- */
494
- export function chainGet(object, chain) {
495
- let target = object;
496
- if (chain) {
497
- chain = typeof chain === 'string' ? chain.split('.') : chain;
498
- for (const key of chain) {
499
- if (target && typeof target === 'object') {
500
- target = target[key];
501
- }
502
- else {
503
- return target;
504
- }
505
- }
506
- }
507
- return target;
508
- }
509
- /**
510
- * @description: 链式设置对象值
511
- * @param object
512
- * @param chain 通过点分割的字符串或者字符串数组
513
- * @param value 要设置的值
514
- */
515
- export function chainSet(object, chain, value) {
516
- let target = object;
517
- chain = typeof chain === 'string' ? chain.split('.') : chain;
518
- if (chain.length === 0) {
519
- return;
520
- }
521
- for (let i = 0, l = chain.length; i < l; i++) {
522
- if (target && typeof target === 'object') {
523
- const key = chain[i];
524
- if (i === l - 1) {
525
- target[key] = value;
526
- return;
527
- }
528
- else {
529
- target = target[key];
530
- }
531
- }
532
- else {
533
- return;
534
- }
535
- }
536
- }
537
- /**
538
- * @description: 移动数组中的元素
539
- * @param array
540
- * @param fromIndex
541
- * @param toIndex
542
- * @return 移动后的新数组
543
- */
544
- export function arrayMove(array, fromIndex, toIndex) {
545
- if (fromIndex === toIndex ||
546
- fromIndex < 0 ||
547
- fromIndex >= array.length ||
548
- toIndex < 0 ||
549
- toIndex >= array.length) {
550
- return array;
551
- }
552
- const fromValue = array[fromIndex];
553
- if (fromIndex > toIndex) {
554
- return [
555
- ...array.slice(0, fromIndex),
556
- ...array.slice(fromIndex + 1, toIndex + 1),
557
- fromValue,
558
- ...array.slice(toIndex + 1),
559
- ];
560
- }
561
- else {
562
- return [
563
- ...array.slice(0, toIndex),
564
- fromValue,
565
- ...array.slice(toIndex, fromIndex),
566
- ...array.slice(fromIndex + 1),
567
- ];
568
- }
569
- }
570
- // 把对象拼接成字符串,解决小程序不支持styleObject的问题
571
- export function stringifyStyle(...args) {
572
- let result = '';
573
- for (let i = 0; i < args.length; i++) {
574
- const arg = args[i];
575
- if (!arg)
576
- continue;
577
- if (typeof arg === 'string') {
578
- result += arg + ';';
579
- }
580
- else if (Array.isArray(arg)) {
581
- if (arg.length) {
582
- const string = stringifyStyle(...arg);
583
- if (string) {
584
- result += string + ';';
585
- }
586
- }
587
- }
588
- else if (typeof arg === 'object') {
589
- for (const key in arg) {
590
- const value = arg[key];
591
- if (value || value === 0) {
592
- result += `${toKebabCase(key)}:${value};`;
593
- }
594
- }
595
- }
596
- }
597
- return result;
598
- }
599
- // 把各种类型的参数拼接成字符串类名,以便小程序不支持classObject的问题
600
- export function classNames(...args) {
601
- let result = '';
602
- for (let i = 0; i < args.length; i++) {
603
- const arg = args[i];
604
- if (!arg)
605
- continue;
606
- if (typeof arg === 'string' || typeof arg === 'number') {
607
- result += arg + ' ';
608
- }
609
- else if (Array.isArray(arg)) {
610
- if (arg.length) {
611
- const className = classNames(...arg);
612
- if (className) {
613
- result += className + ' ';
614
- }
615
- }
616
- }
617
- else if (typeof arg === 'object') {
618
- for (const key in arg) {
619
- const value = arg[key];
620
- if (value) {
621
- result += key + ' ';
622
- }
623
- }
624
- }
625
- }
626
- return result;
627
- }
628
218
  export const noop = () => { };
629
- // 将嵌套数据结构转换为多维数组
630
- export function nestedToMulti(nested, values, fieldKeys) {
631
- const columns = [];
632
- function recurse(list, index = 0) {
633
- columns.push(list);
634
- const selectedValue = values[index];
635
- let selectedOption = list.find((option) => option[fieldKeys.value] === selectedValue);
636
- if (!selectedOption) {
637
- selectedOption = list[0];
638
- }
639
- if (selectedOption) {
640
- const nextList = selectedOption[fieldKeys.children];
641
- if (Array.isArray(nextList)) {
642
- recurse(nextList, ++index);
643
- }
644
- }
645
- }
646
- recurse(nested);
647
- return columns;
648
- }
649
- // 生成两数间的一个随机整数
650
- export function random(min, max) {
651
- return Math.round(min + Math.random() * (max - min));
652
- }
653
- // 每n位数字添加一个分隔符
654
- export function addSeparator(num, separator = ',', digit = 3) {
655
- return String(num).replace(new RegExp(`\\B(?=(\\d{${digit}})+(?!\\d))`, 'g'), separator);
656
- }
657
- export function getDistanceBetweenTwoPoints(c1, c2) {
658
- return Math.sqrt(Math.pow(c1.x - c2.x, 2) + Math.pow(c1.y - c2.y, 2));
659
- }
660
219
  export function getMayPrimitiveOption(option, key) {
661
220
  return isPrimitive(option) ? option : option[key];
662
221
  }
package/utils/case.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare function toUpperCamelCase(str: string): string;
2
- export declare function toLowerCamelCase(str: string): string;
3
- export declare function toKebabCase(str: string): string;
4
- export declare function toSnakeCase(str: string): string;
package/utils/case.js DELETED
@@ -1,26 +0,0 @@
1
- // 把字符串转换为 CamelCase
2
- export function toUpperCamelCase(str) {
3
- return str
4
- .replace(/^[a-z]/, (m) => m.toUpperCase())
5
- .replace(/[-_]([a-z])/g, (_, g1) => g1.toUpperCase());
6
- }
7
- // 把字符串转换为 camelCase
8
- export function toLowerCamelCase(str) {
9
- return str
10
- .replace(/^[A-Z]/, (m) => m.toLowerCase())
11
- .replace(/[-_]([a-z])/g, (_, g1) => g1.toUpperCase());
12
- }
13
- // 把字符串转换为 kebab-case
14
- export function toKebabCase(str) {
15
- return str
16
- .replace(/^[A-Z]/, (m) => m.toLowerCase())
17
- .replace(/_/g, '-')
18
- .replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
19
- }
20
- // 把字符串转换为 snake_case
21
- export function toSnakeCase(str) {
22
- return str
23
- .replace(/^[A-Z]/, (m) => m.toLowerCase())
24
- .replace(/-/g, '_')
25
- .replace(/[A-Z]/g, (m) => '_' + m.toLowerCase());
26
- }