diginext-utils 2.1.20 → 2.1.21

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 (205) hide show
  1. package/dist/Checker.d.ts +8 -8
  2. package/dist/Checker.js +31 -31
  3. package/dist/EventDispatcher.d.ts +13 -13
  4. package/dist/EventDispatcher.js +51 -51
  5. package/dist/FileUpload.d.ts +12 -12
  6. package/dist/FileUpload.js +64 -64
  7. package/dist/Slug.d.ts +9 -9
  8. package/dist/Slug.js +333 -333
  9. package/dist/Timer.d.ts +4 -4
  10. package/dist/Timer.js +8 -8
  11. package/dist/Validation.d.ts +5 -5
  12. package/dist/Validation.js +38 -38
  13. package/dist/array.d.ts +113 -113
  14. package/dist/array.js +297 -297
  15. package/dist/color.d.ts +25 -25
  16. package/dist/color.js +95 -95
  17. package/dist/console/enableConsole.d.ts +2 -2
  18. package/dist/console/enableConsole.js +13 -13
  19. package/dist/console/index.d.ts +11 -11
  20. package/dist/console/index.js +17 -17
  21. package/dist/console/log.d.ts +15 -15
  22. package/dist/console/log.js +44 -44
  23. package/dist/device/browser.d.ts +5 -5
  24. package/dist/device/browser.js +37 -37
  25. package/dist/device/camera.d.ts +7 -7
  26. package/dist/device/camera.js +171 -171
  27. package/dist/device/index.d.ts +5 -5
  28. package/dist/device/index.js +224 -224
  29. package/dist/device/os.d.ts +11 -11
  30. package/dist/device/os.js +37 -37
  31. package/dist/file/createDir.d.ts +5 -5
  32. package/dist/file/createDir.js +15 -15
  33. package/dist/file/fileMove.d.ts +4 -4
  34. package/dist/file/fileMove.js +32 -32
  35. package/dist/file/findFilesByExt.d.ts +13 -13
  36. package/dist/file/findFilesByExt.js +49 -49
  37. package/dist/file/getAllFiles.d.ts +1 -0
  38. package/dist/file/getAllFiles.js +27 -0
  39. package/dist/file/getAllFiles.js.map +1 -0
  40. package/dist/file/index.d.ts +9 -9
  41. package/dist/file/index.js +10 -10
  42. package/dist/gameboi/index.d.ts +10 -10
  43. package/dist/gameboi/index.js +67 -64
  44. package/dist/gameboi/index.js.map +1 -1
  45. package/dist/images/downloadByUrl.d.ts +1 -1
  46. package/dist/images/downloadByUrl.js +55 -55
  47. package/dist/images/index.d.ts +2 -2
  48. package/dist/images/index.js +8 -8
  49. package/dist/images/loadImage.d.ts +1 -1
  50. package/dist/images/loadImage.js +17 -17
  51. package/dist/images/resize.d.ts +2 -2
  52. package/dist/images/resize.js +37 -37
  53. package/dist/images/upload.d.ts +10 -10
  54. package/dist/images/upload.js +26 -26
  55. package/dist/index.d.ts +37 -37
  56. package/dist/index.js +62 -62
  57. package/dist/json.d.ts +8 -8
  58. package/dist/json.js +31 -31
  59. package/dist/math/diffDate.d.ts +5 -5
  60. package/dist/math/diffDate.js +13 -13
  61. package/dist/math/index.d.ts +30 -30
  62. package/dist/math/index.js +92 -92
  63. package/dist/math/positiveNumber.d.ts +2 -2
  64. package/dist/math/positiveNumber.js +16 -16
  65. package/dist/name/en.d.ts +5 -5
  66. package/dist/name/en.js +25 -25
  67. package/dist/name/index.d.ts +12 -12
  68. package/dist/name/index.js +12 -12
  69. package/dist/name/vi.d.ts +5 -5
  70. package/dist/name/vi.js +27 -27
  71. package/dist/object.d.ts +59 -59
  72. package/dist/object.js +79 -79
  73. package/dist/permission/index.d.ts +8 -8
  74. package/dist/permission/index.js +6 -6
  75. package/dist/permission/requestCamera.d.ts +5 -5
  76. package/dist/permission/requestCamera.js +42 -42
  77. package/dist/permission/requestDeviceOrientationControl.d.ts +2 -2
  78. package/dist/permission/requestDeviceOrientationControl.js +38 -38
  79. package/dist/response/index.d.ts +49 -49
  80. package/dist/response/index.js +51 -51
  81. package/dist/string/convertPathnameAndQuery.d.ts +4 -4
  82. package/dist/string/convertPathnameAndQuery.js +24 -24
  83. package/dist/string/formatNumber.d.ts +6 -6
  84. package/dist/string/formatNumber.js +14 -14
  85. package/dist/string/generatePassword.d.ts +9 -9
  86. package/dist/string/generatePassword.js +23 -23
  87. package/dist/string/generateUUID.d.ts +2 -2
  88. package/dist/string/generateUUID.js +36 -36
  89. package/dist/string/getTextBetweenCharByIndex.d.ts +1 -1
  90. package/dist/string/getTextBetweenCharByIndex.js +20 -20
  91. package/dist/string/index.d.ts +65 -65
  92. package/dist/string/index.js +161 -161
  93. package/dist/string/indexesOf.d.ts +1 -1
  94. package/dist/string/indexesOf.js +14 -14
  95. package/dist/string/makeDaySlug.d.ts +31 -31
  96. package/dist/string/makeDaySlug.js +22 -22
  97. package/dist/string/random.d.ts +18 -18
  98. package/dist/string/random.js +40 -40
  99. package/dist/string/trimNull.d.ts +2 -2
  100. package/dist/string/trimNull.js +20 -20
  101. package/dist/string/url.d.ts +22 -22
  102. package/dist/string/url.js +74 -74
  103. package/esm/Checker.d.ts +8 -8
  104. package/esm/Checker.js +27 -27
  105. package/esm/EventDispatcher.d.ts +13 -13
  106. package/esm/EventDispatcher.js +48 -48
  107. package/esm/FileUpload.d.ts +12 -12
  108. package/esm/FileUpload.js +61 -61
  109. package/esm/Slug.d.ts +9 -9
  110. package/esm/Slug.js +329 -329
  111. package/esm/Timer.d.ts +4 -4
  112. package/esm/Timer.js +6 -6
  113. package/esm/Validation.d.ts +5 -5
  114. package/esm/Validation.js +36 -36
  115. package/esm/array.d.ts +113 -113
  116. package/esm/array.js +275 -275
  117. package/esm/color.d.ts +25 -25
  118. package/esm/color.js +85 -85
  119. package/esm/console/enableConsole.d.ts +2 -2
  120. package/esm/console/enableConsole.js +6 -6
  121. package/esm/console/index.d.ts +11 -11
  122. package/esm/console/index.js +12 -12
  123. package/esm/console/log.d.ts +15 -15
  124. package/esm/console/log.js +32 -32
  125. package/esm/device/browser.d.ts +5 -5
  126. package/esm/device/browser.js +29 -29
  127. package/esm/device/camera.d.ts +7 -7
  128. package/esm/device/camera.js +167 -167
  129. package/esm/device/index.d.ts +5 -5
  130. package/esm/device/index.js +216 -216
  131. package/esm/device/os.d.ts +11 -11
  132. package/esm/device/os.js +27 -27
  133. package/esm/file/createDir.d.ts +5 -5
  134. package/esm/file/createDir.js +12 -12
  135. package/esm/file/fileMove.d.ts +4 -4
  136. package/esm/file/fileMove.js +28 -28
  137. package/esm/file/findFilesByExt.d.ts +13 -13
  138. package/esm/file/findFilesByExt.js +45 -45
  139. package/esm/file/getAllFiles.d.ts +1 -0
  140. package/esm/file/getAllFiles.js +21 -0
  141. package/esm/file/getAllFiles.js.map +1 -0
  142. package/esm/file/index.d.ts +9 -9
  143. package/esm/file/index.js +5 -5
  144. package/esm/gameboi/index.d.ts +10 -10
  145. package/esm/gameboi/index.js +61 -61
  146. package/esm/gameboi/index.js.map +1 -1
  147. package/esm/images/downloadByUrl.d.ts +1 -1
  148. package/esm/images/downloadByUrl.js +52 -52
  149. package/esm/images/index.d.ts +2 -2
  150. package/esm/images/index.js +3 -3
  151. package/esm/images/loadImage.d.ts +1 -1
  152. package/esm/images/loadImage.js +14 -14
  153. package/esm/images/resize.d.ts +2 -2
  154. package/esm/images/resize.js +30 -30
  155. package/esm/images/upload.d.ts +10 -10
  156. package/esm/images/upload.js +19 -19
  157. package/esm/index.d.ts +37 -37
  158. package/esm/index.js +37 -37
  159. package/esm/json.d.ts +8 -8
  160. package/esm/json.js +27 -27
  161. package/esm/math/diffDate.d.ts +5 -5
  162. package/esm/math/diffDate.js +9 -9
  163. package/esm/math/index.d.ts +30 -30
  164. package/esm/math/index.js +77 -77
  165. package/esm/math/positiveNumber.d.ts +2 -2
  166. package/esm/math/positiveNumber.js +12 -12
  167. package/esm/name/en.d.ts +5 -5
  168. package/esm/name/en.js +21 -21
  169. package/esm/name/index.d.ts +12 -12
  170. package/esm/name/index.js +5 -5
  171. package/esm/name/vi.d.ts +5 -5
  172. package/esm/name/vi.js +23 -23
  173. package/esm/object.d.ts +59 -59
  174. package/esm/object.js +69 -69
  175. package/esm/permission/index.d.ts +8 -8
  176. package/esm/permission/index.js +4 -4
  177. package/esm/permission/requestCamera.d.ts +5 -5
  178. package/esm/permission/requestCamera.js +38 -38
  179. package/esm/permission/requestDeviceOrientationControl.d.ts +2 -2
  180. package/esm/permission/requestDeviceOrientationControl.js +34 -34
  181. package/esm/response/index.d.ts +49 -49
  182. package/esm/response/index.js +45 -45
  183. package/esm/string/convertPathnameAndQuery.d.ts +4 -4
  184. package/esm/string/convertPathnameAndQuery.js +21 -21
  185. package/esm/string/formatNumber.d.ts +6 -6
  186. package/esm/string/formatNumber.js +10 -10
  187. package/esm/string/generatePassword.d.ts +9 -9
  188. package/esm/string/generatePassword.js +19 -19
  189. package/esm/string/generateUUID.d.ts +2 -2
  190. package/esm/string/generateUUID.js +32 -32
  191. package/esm/string/getTextBetweenCharByIndex.d.ts +1 -1
  192. package/esm/string/getTextBetweenCharByIndex.js +14 -14
  193. package/esm/string/index.d.ts +65 -65
  194. package/esm/string/index.js +150 -150
  195. package/esm/string/indexesOf.d.ts +1 -1
  196. package/esm/string/indexesOf.js +11 -11
  197. package/esm/string/makeDaySlug.d.ts +31 -31
  198. package/esm/string/makeDaySlug.js +15 -15
  199. package/esm/string/random.d.ts +18 -18
  200. package/esm/string/random.js +33 -33
  201. package/esm/string/trimNull.d.ts +2 -2
  202. package/esm/string/trimNull.js +13 -13
  203. package/esm/string/url.d.ts +22 -22
  204. package/esm/string/url.js +64 -64
  205. package/package.json +4 -4
package/esm/array.js CHANGED
@@ -1,276 +1,276 @@
1
- import { randInt } from "./math";
2
- export const sumArray = (array, key) => {
3
- if (!array) {
4
- console.warn("ARRAY NOT EXITED !");
5
- return 0;
6
- }
7
- if (key)
8
- return array.reduce((c, v) => c + v[key], 0);
9
- else
10
- return array.reduce((c, v) => c + v, 0);
11
- };
12
- /**
13
- *
14
- * @param {Array} array
15
- * @param {string} key
16
- * @returns {Number}
17
- */
18
- export const averageArray = (array, key) => {
19
- if (!array) {
20
- console.warn("ARRAY NOT EXITED !");
21
- return 0;
22
- }
23
- return sumArray(array, key) / array.length || 0;
24
- };
25
- /**
26
- *
27
- * @param {Array} array
28
- * @param {string} key
29
- * @returns {Number}
30
- */
31
- export const minArray = (array, key) => {
32
- if (!array) {
33
- console.warn("ARRAY NOT EXITED !");
34
- return 0;
35
- }
36
- if (array.length > 0) {
37
- if (key)
38
- return array.reduce((c, v) => (c < v[key] ? c : v[key]));
39
- else
40
- return array.reduce((c, v) => (c < v ? c : v));
41
- }
42
- return 0;
43
- };
44
- /**
45
- *
46
- * @param {Array} array
47
- * @param {string} key
48
- * @returns {Number}
49
- */
50
- export const maxArray = (array, key) => {
51
- if (!array) {
52
- console.warn("ARRAY NOT EXITED !");
53
- return 0;
54
- }
55
- if (array.length > 0) {
56
- if (key)
57
- return array.reduce((c, v) => (c > v[key] ? c : v[key]));
58
- else
59
- return array.reduce((c, v) => (c > v ? c : v));
60
- }
61
- return 0;
62
- };
63
- /**
64
- *
65
- * @param {Array} array
66
- * @param {string} key
67
- * @returns {Array}
68
- */
69
- export const sortElementByString = (array, key) => {
70
- if (!Array.isArray(array))
71
- return [];
72
- if (key)
73
- return array.sort((x, y) => {
74
- var a = x[key].toUpperCase(), b = y[key].toUpperCase();
75
- return a == b ? 0 : a > b ? 1 : -1;
76
- });
77
- console.log("NO KEY");
78
- };
79
- /**
80
- *
81
- * @param {Array} array
82
- * @param {string} key
83
- * @returns {Array}
84
- */
85
- export const sortElementByNumber = (array, key) => {
86
- if (!Array.isArray(array))
87
- return [];
88
- if (key)
89
- return array.sort((a, b) => {
90
- return a[key] - b[key];
91
- });
92
- console.log("NO KEY");
93
- };
94
- /**
95
- *
96
- * @param {Array} array
97
- * @returns {any}
98
- */
99
- export const firstElement = (array) => {
100
- if (array)
101
- if (array.length || array.length > 0)
102
- return array[0];
103
- return null;
104
- };
105
- /**
106
- *
107
- * @param {Array} array
108
- * @returns {any}
109
- */
110
- export const lastElement = (array) => {
111
- if (array)
112
- if (array.length || array.length > 0)
113
- return array[array.length - 1];
114
- return null;
115
- };
116
- /**
117
- *
118
- * @param {Array} array
119
- * @returns {any}
120
- */
121
- export const randomIndex = (array) => {
122
- if (array)
123
- return randInt(0, array.length - 1);
124
- return -1;
125
- };
126
- /**
127
- *
128
- * @param {Array} array
129
- * @returns {any}
130
- */
131
- export const randomElement = (array) => {
132
- if (array)
133
- return array[randomIndex(array)];
134
- return null;
135
- };
136
- /**
137
- * Remove same elements from 2 arrays
138
- */
139
- export const mergeAndMakeUniqueElement = (list1, list2, key) => {
140
- if (!list1 || !list2)
141
- return;
142
- if (key) {
143
- return list1.concat(list2).filter((item, index, self) => {
144
- return self.findIndex((x) => x[key] == item[key]) === index;
145
- });
146
- }
147
- else {
148
- return list1.concat(list2).filter((x, index, self) => {
149
- return self.indexOf(x) === index;
150
- });
151
- }
152
- };
153
- /**
154
- * check target == toMatch
155
- * @param {Array} target
156
- * @param {Array} toMatch
157
- * @returns {Boolean}
158
- */
159
- export const allMatchInArray = (target, toMatch) => {
160
- if (!target || !toMatch)
161
- return false;
162
- const found = toMatch.every((item) => {
163
- return target.includes(item);
164
- });
165
- return found;
166
- };
167
- export const removeItem = (item, array) => {
168
- const index = array.indexOf(item);
169
- if (index == -1) {
170
- console.warn("[ArrayExtra.removeItem] Item not found.");
171
- return array;
172
- }
173
- array.splice(index, 1);
174
- return array;
175
- };
176
- export const removeItemByKey = (key, value, array) => {
177
- const foundIndex = array.findIndex((item) => {
178
- return item[key] == value;
179
- });
180
- if (foundIndex < 0) {
181
- console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
182
- return array;
183
- }
184
- array.splice(foundIndex, 1);
185
- return array;
186
- };
187
- export const getRandom = (array, n) => {
188
- n = n || array.length;
189
- var result = new Array(n), len = array.length, taken = new Array(len);
190
- if (n > len)
191
- throw new RangeError("getRandom: more elements taken than available");
192
- while (n--) {
193
- var x = Math.floor(Math.random() * len);
194
- result[n] = array[x in taken ? taken[x] : x];
195
- taken[x] = --len in taken ? taken[len] : len;
196
- }
197
- return result;
198
- };
199
- /**
200
- * Get an array with shuffle element
201
- */
202
- export const getHalfRandom = (array, n) => {
203
- var n = Math.ceil(array.length / 2);
204
- return getRandom(array, n);
205
- };
206
- /**
207
- * Make array shuffle itself
208
- */
209
- export const shuffle = (array) => {
210
- var i = array.length, j, temp;
211
- if (array.length < 1)
212
- return array;
213
- while (--i) {
214
- j = Math.floor(Math.random() * (i + 1));
215
- temp = array[i];
216
- array[i] = array[j];
217
- array[j] = temp;
218
- }
219
- return array;
220
- };
221
- /**
222
- *
223
- * @param {Array} array
224
- * @param {Number} oldIndex
225
- * @param {Number} newIndex
226
- * @returns {Array}
227
- */
228
- export const moveIndex = (array, oldIndex, newIndex) => {
229
- if (newIndex >= array.length) {
230
- var k = newIndex - array.length + 1;
231
- while (k--) {
232
- array.push(undefined);
233
- }
234
- }
235
- array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
236
- return array;
237
- };
238
- export const moveArray = (array, oldIndex, newIndex) => {
239
- while (oldIndex < 0) {
240
- oldIndex += array.length;
241
- }
242
- while (newIndex < 0) {
243
- newIndex += array.length;
244
- }
245
- if (newIndex >= array.length) {
246
- var k = newIndex - array.length;
247
- while (k-- + 1) {
248
- array.push(999);
249
- }
250
- }
251
- array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
252
- return array;
253
- };
254
- const xarray = {
255
- sumArray,
256
- averageArray,
257
- minArray,
258
- maxArray,
259
- sortElementByString,
260
- sortElementByNumber,
261
- firstElement,
262
- lastElement,
263
- randomIndex,
264
- randomElement,
265
- mergeAndMakeUniqueElement,
266
- allMatchInArray,
267
- removeItem,
268
- removeItemByKey,
269
- getRandom,
270
- getHalfRandom,
271
- shuffle,
272
- moveIndex,
273
- moveArray,
274
- };
275
- export default xarray;
1
+ import { randInt } from "./math";
2
+ export const sumArray = (array, key) => {
3
+ if (!array) {
4
+ console.warn("ARRAY NOT EXITED !");
5
+ return 0;
6
+ }
7
+ if (key)
8
+ return array.reduce((c, v) => c + v[key], 0);
9
+ else
10
+ return array.reduce((c, v) => c + v, 0);
11
+ };
12
+ /**
13
+ *
14
+ * @param {Array} array
15
+ * @param {string} key
16
+ * @returns {Number}
17
+ */
18
+ export const averageArray = (array, key) => {
19
+ if (!array) {
20
+ console.warn("ARRAY NOT EXITED !");
21
+ return 0;
22
+ }
23
+ return sumArray(array, key) / array.length || 0;
24
+ };
25
+ /**
26
+ *
27
+ * @param {Array} array
28
+ * @param {string} key
29
+ * @returns {Number}
30
+ */
31
+ export const minArray = (array, key) => {
32
+ if (!array) {
33
+ console.warn("ARRAY NOT EXITED !");
34
+ return 0;
35
+ }
36
+ if (array.length > 0) {
37
+ if (key)
38
+ return array.reduce((c, v) => (c < v[key] ? c : v[key]));
39
+ else
40
+ return array.reduce((c, v) => (c < v ? c : v));
41
+ }
42
+ return 0;
43
+ };
44
+ /**
45
+ *
46
+ * @param {Array} array
47
+ * @param {string} key
48
+ * @returns {Number}
49
+ */
50
+ export const maxArray = (array, key) => {
51
+ if (!array) {
52
+ console.warn("ARRAY NOT EXITED !");
53
+ return 0;
54
+ }
55
+ if (array.length > 0) {
56
+ if (key)
57
+ return array.reduce((c, v) => (c > v[key] ? c : v[key]));
58
+ else
59
+ return array.reduce((c, v) => (c > v ? c : v));
60
+ }
61
+ return 0;
62
+ };
63
+ /**
64
+ *
65
+ * @param {Array} array
66
+ * @param {string} key
67
+ * @returns {Array}
68
+ */
69
+ export const sortElementByString = (array, key) => {
70
+ if (!Array.isArray(array))
71
+ return [];
72
+ if (key)
73
+ return array.sort((x, y) => {
74
+ var a = x[key].toUpperCase(), b = y[key].toUpperCase();
75
+ return a == b ? 0 : a > b ? 1 : -1;
76
+ });
77
+ console.log("NO KEY");
78
+ };
79
+ /**
80
+ *
81
+ * @param {Array} array
82
+ * @param {string} key
83
+ * @returns {Array}
84
+ */
85
+ export const sortElementByNumber = (array, key) => {
86
+ if (!Array.isArray(array))
87
+ return [];
88
+ if (key)
89
+ return array.sort((a, b) => {
90
+ return a[key] - b[key];
91
+ });
92
+ console.log("NO KEY");
93
+ };
94
+ /**
95
+ *
96
+ * @param {Array} array
97
+ * @returns {any}
98
+ */
99
+ export const firstElement = (array) => {
100
+ if (array)
101
+ if (array.length || array.length > 0)
102
+ return array[0];
103
+ return null;
104
+ };
105
+ /**
106
+ *
107
+ * @param {Array} array
108
+ * @returns {any}
109
+ */
110
+ export const lastElement = (array) => {
111
+ if (array)
112
+ if (array.length || array.length > 0)
113
+ return array[array.length - 1];
114
+ return null;
115
+ };
116
+ /**
117
+ *
118
+ * @param {Array} array
119
+ * @returns {any}
120
+ */
121
+ export const randomIndex = (array) => {
122
+ if (array)
123
+ return randInt(0, array.length - 1);
124
+ return -1;
125
+ };
126
+ /**
127
+ *
128
+ * @param {Array} array
129
+ * @returns {any}
130
+ */
131
+ export const randomElement = (array) => {
132
+ if (array)
133
+ return array[randomIndex(array)];
134
+ return null;
135
+ };
136
+ /**
137
+ * Remove same elements from 2 arrays
138
+ */
139
+ export const mergeAndMakeUniqueElement = (list1, list2, key) => {
140
+ if (!list1 || !list2)
141
+ return;
142
+ if (key) {
143
+ return list1.concat(list2).filter((item, index, self) => {
144
+ return self.findIndex((x) => x[key] == item[key]) === index;
145
+ });
146
+ }
147
+ else {
148
+ return list1.concat(list2).filter((x, index, self) => {
149
+ return self.indexOf(x) === index;
150
+ });
151
+ }
152
+ };
153
+ /**
154
+ * check target == toMatch
155
+ * @param {Array} target
156
+ * @param {Array} toMatch
157
+ * @returns {Boolean}
158
+ */
159
+ export const allMatchInArray = (target, toMatch) => {
160
+ if (!target || !toMatch)
161
+ return false;
162
+ const found = toMatch.every((item) => {
163
+ return target.includes(item);
164
+ });
165
+ return found;
166
+ };
167
+ export const removeItem = (item, array) => {
168
+ const index = array.indexOf(item);
169
+ if (index == -1) {
170
+ console.warn("[ArrayExtra.removeItem] Item not found.");
171
+ return array;
172
+ }
173
+ array.splice(index, 1);
174
+ return array;
175
+ };
176
+ export const removeItemByKey = (key, value, array) => {
177
+ const foundIndex = array.findIndex((item) => {
178
+ return item[key] == value;
179
+ });
180
+ if (foundIndex < 0) {
181
+ console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
182
+ return array;
183
+ }
184
+ array.splice(foundIndex, 1);
185
+ return array;
186
+ };
187
+ export const getRandom = (array, n) => {
188
+ n = n || array.length;
189
+ var result = new Array(n), len = array.length, taken = new Array(len);
190
+ if (n > len)
191
+ throw new RangeError("getRandom: more elements taken than available");
192
+ while (n--) {
193
+ var x = Math.floor(Math.random() * len);
194
+ result[n] = array[x in taken ? taken[x] : x];
195
+ taken[x] = --len in taken ? taken[len] : len;
196
+ }
197
+ return result;
198
+ };
199
+ /**
200
+ * Get an array with shuffle element
201
+ */
202
+ export const getHalfRandom = (array, n) => {
203
+ var n = Math.ceil(array.length / 2);
204
+ return getRandom(array, n);
205
+ };
206
+ /**
207
+ * Make array shuffle itself
208
+ */
209
+ export const shuffle = (array) => {
210
+ var i = array.length, j, temp;
211
+ if (array.length < 1)
212
+ return array;
213
+ while (--i) {
214
+ j = Math.floor(Math.random() * (i + 1));
215
+ temp = array[i];
216
+ array[i] = array[j];
217
+ array[j] = temp;
218
+ }
219
+ return array;
220
+ };
221
+ /**
222
+ *
223
+ * @param {Array} array
224
+ * @param {Number} oldIndex
225
+ * @param {Number} newIndex
226
+ * @returns {Array}
227
+ */
228
+ export const moveIndex = (array, oldIndex, newIndex) => {
229
+ if (newIndex >= array.length) {
230
+ var k = newIndex - array.length + 1;
231
+ while (k--) {
232
+ array.push(undefined);
233
+ }
234
+ }
235
+ array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
236
+ return array;
237
+ };
238
+ export const moveArray = (array, oldIndex, newIndex) => {
239
+ while (oldIndex < 0) {
240
+ oldIndex += array.length;
241
+ }
242
+ while (newIndex < 0) {
243
+ newIndex += array.length;
244
+ }
245
+ if (newIndex >= array.length) {
246
+ var k = newIndex - array.length;
247
+ while (k-- + 1) {
248
+ array.push(999);
249
+ }
250
+ }
251
+ array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
252
+ return array;
253
+ };
254
+ const xarray = {
255
+ sumArray,
256
+ averageArray,
257
+ minArray,
258
+ maxArray,
259
+ sortElementByString,
260
+ sortElementByNumber,
261
+ firstElement,
262
+ lastElement,
263
+ randomIndex,
264
+ randomElement,
265
+ mergeAndMakeUniqueElement,
266
+ allMatchInArray,
267
+ removeItem,
268
+ removeItemByKey,
269
+ getRandom,
270
+ getHalfRandom,
271
+ shuffle,
272
+ moveIndex,
273
+ moveArray,
274
+ };
275
+ export default xarray;
276
276
  //# sourceMappingURL=array.js.map
package/esm/color.d.ts CHANGED
@@ -1,25 +1,25 @@
1
- export declare const random: (hex?: boolean) => string;
2
- export declare const pSBC: (p: any, c0: any, c1?: any, l?: any) => string | null;
3
- export declare const hexToRgb: (hex: string) => {
4
- r: number;
5
- g: number;
6
- b: number;
7
- } | null;
8
- export declare const hexDarken: (hex: string, amount: number) => string | null;
9
- export declare const hexLighten: (hex: string, amount: number) => string | null;
10
- export declare const RGBToHex: (rgb: string | any) => string | null;
11
- export declare const hexToVBColor: (rrggbb: string) => number;
12
- declare const color: {
13
- random: (hex?: boolean) => string;
14
- pSBC: (p: any, c0: any, c1?: any, l?: any) => string | null;
15
- hexToRgb: (hex: string) => {
16
- r: number;
17
- g: number;
18
- b: number;
19
- } | null;
20
- hexDarken: (hex: string, amount: number) => string | null;
21
- hexLighten: (hex: string, amount: number) => string | null;
22
- RGBToHex: (rgb: string | any) => string | null;
23
- hexToVBColor: (rrggbb: string) => number;
24
- };
25
- export default color;
1
+ export declare const random: (hex?: boolean) => string;
2
+ export declare const pSBC: (p: any, c0: any, c1?: any, l?: any) => string | null;
3
+ export declare const hexToRgb: (hex: string) => {
4
+ r: number;
5
+ g: number;
6
+ b: number;
7
+ } | null;
8
+ export declare const hexDarken: (hex: string, amount: number) => string | null;
9
+ export declare const hexLighten: (hex: string, amount: number) => string | null;
10
+ export declare const RGBToHex: (rgb: string | any) => string | null;
11
+ export declare const hexToVBColor: (rrggbb: string) => number;
12
+ declare const color: {
13
+ random: (hex?: boolean) => string;
14
+ pSBC: (p: any, c0: any, c1?: any, l?: any) => string | null;
15
+ hexToRgb: (hex: string) => {
16
+ r: number;
17
+ g: number;
18
+ b: number;
19
+ } | null;
20
+ hexDarken: (hex: string, amount: number) => string | null;
21
+ hexLighten: (hex: string, amount: number) => string | null;
22
+ RGBToHex: (rgb: string | any) => string | null;
23
+ hexToVBColor: (rrggbb: string) => number;
24
+ };
25
+ export default color;