diginext-utils 1.2.4 → 2.0.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.
- package/dist/Checker.js +7 -8
- package/dist/Checker.mjs +25 -0
- package/dist/EventDispatcher.js +20 -19
- package/dist/EventDispatcher.mjs +51 -0
- package/dist/FileUpload.js +24 -29
- package/dist/FileUpload.mjs +60 -0
- package/dist/Slug.js +286 -340
- package/dist/Slug.mjs +327 -0
- package/dist/Timer.js +8 -11
- package/dist/Timer.mjs +2 -0
- package/dist/Validation.js +11 -19
- package/dist/Validation.mjs +33 -0
- package/dist/array.js +100 -203
- package/dist/array.mjs +3 -0
- package/dist/backend/file/createDir.js +13 -13
- package/dist/backend/file/createDir.mjs +13 -0
- package/dist/backend/file/fileMove.js +14 -14
- package/dist/backend/file/fileMove.mjs +29 -0
- package/dist/backend/file/findFilesByExt.js +22 -22
- package/dist/backend/file/findFilesByExt.mjs +40 -0
- package/dist/chunk-5AL36RZR.mjs +47 -0
- package/dist/chunk-7IYY7BKN.mjs +136 -0
- package/dist/chunk-ACLBWYEO.mjs +85 -0
- package/dist/chunk-AHFJBIQJ.mjs +9 -0
- package/dist/chunk-AKU6F3WT.mjs +9 -0
- package/dist/chunk-FOWYH6LL.mjs +32 -0
- package/dist/chunk-FTE6FZSH.mjs +17 -0
- package/dist/chunk-JKYSZLBF.mjs +27 -0
- package/dist/chunk-LXQIKFED.mjs +13 -0
- package/dist/chunk-Q5R25OIS.mjs +185 -0
- package/dist/chunk-R2BH5I6O.mjs +9 -0
- package/dist/chunk-UKRVCU5M.mjs +166 -0
- package/dist/chunk-VFKAZAWF.mjs +40 -0
- package/dist/chunk-VZGV2BTL.mjs +27 -0
- package/dist/chunk-Y4ZTQWPA.mjs +68 -0
- package/dist/color.js +44 -61
- package/dist/color.mjs +62 -0
- package/dist/console/enableConsole.js +14 -11
- package/dist/console/enableConsole.mjs +2 -0
- package/dist/console/index.js +14 -11
- package/dist/console/index.mjs +2 -0
- package/dist/device/browser.js +29 -27
- package/dist/device/browser.mjs +2 -0
- package/dist/device/camera.js +65 -125
- package/dist/device/camera.mjs +3 -0
- package/dist/device.js +76 -181
- package/dist/device.mjs +2 -0
- package/dist/index.js +879 -135
- package/dist/index.mjs +14 -0
- package/dist/math/diffDate.js +8 -15
- package/dist/math/diffDate.mjs +10 -0
- package/dist/math/positiveNumber.js +24 -10
- package/dist/math/positiveNumber.mjs +16 -0
- package/dist/math.js +27 -217
- package/dist/math.mjs +2 -0
- package/dist/object.js +33 -36
- package/dist/object.mjs +2 -0
- package/dist/permission/requestCamera.js +14 -37
- package/dist/permission/requestCamera.mjs +2 -0
- package/dist/permission/requestDeviceOrientationControl.js +161 -20
- package/dist/permission/requestDeviceOrientationControl.mjs +3 -0
- package/dist/string/formatNumber.js +27 -18
- package/dist/string/formatNumber.mjs +10 -0
- package/dist/string/generatePassword.js +25 -23
- package/dist/string/generatePassword.mjs +16 -0
- package/dist/string/generateUUID.js +11 -17
- package/dist/string/generateUUID.mjs +14 -0
- package/dist/string/name/en.js +6 -14
- package/dist/string/name/en.mjs +17 -0
- package/dist/string/name/vi.js +29 -22
- package/dist/string/name/vi.mjs +20 -0
- package/dist/string/random.js +16 -30
- package/dist/string/random.mjs +2 -0
- package/dist/string/trimNull.js +14 -14
- package/dist/string/trimNull.mjs +14 -0
- package/dist/string/url.js +45 -74
- package/dist/string/url.mjs +3 -0
- package/dist/string.js +43 -394
- package/dist/string.mjs +3 -0
- package/package.json +23 -28
- package/dist/backend/zip/extractZip.js +0 -59
package/dist/array.js
CHANGED
|
@@ -1,168 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {Array} array
|
|
15
|
-
* @param {string} key
|
|
16
|
-
* @returns {Number}
|
|
17
|
-
*/
|
|
18
|
-
const sumArray = (array, key) => {
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// src/math.ts
|
|
6
|
+
var randInt = (low, high) => {
|
|
7
|
+
return low + Math.floor(Math.random() * (high - low + 1));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/array.ts
|
|
11
|
+
var sumArray = (array, key) => {
|
|
19
12
|
if (!array) {
|
|
20
13
|
console.warn("ARRAY NOT EXITED !");
|
|
21
14
|
return 0;
|
|
22
15
|
}
|
|
23
|
-
if (key)
|
|
16
|
+
if (key)
|
|
17
|
+
return array.reduce((c, v) => c + v[key], 0);
|
|
18
|
+
else
|
|
19
|
+
return array.reduce((c, v) => c + v, 0);
|
|
24
20
|
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param {Array} array
|
|
29
|
-
* @param {string} key
|
|
30
|
-
* @returns {Number}
|
|
31
|
-
*/
|
|
32
|
-
exports.sumArray = sumArray;
|
|
33
|
-
const averageArray = (array, key) => {
|
|
21
|
+
var averageArray = (array, key) => {
|
|
34
22
|
if (!array) {
|
|
35
23
|
console.warn("ARRAY NOT EXITED !");
|
|
36
24
|
return 0;
|
|
37
25
|
}
|
|
38
26
|
return sumArray(array, key) / array.length || 0;
|
|
39
27
|
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* @param {Array} array
|
|
44
|
-
* @param {string} key
|
|
45
|
-
* @returns {Number}
|
|
46
|
-
*/
|
|
47
|
-
exports.averageArray = averageArray;
|
|
48
|
-
const minArray = (array, key) => {
|
|
28
|
+
var minArray = (array, key) => {
|
|
49
29
|
if (!array) {
|
|
50
30
|
console.warn("ARRAY NOT EXITED !");
|
|
51
31
|
return 0;
|
|
52
32
|
}
|
|
53
33
|
if (array.length > 0) {
|
|
54
|
-
if (key)
|
|
34
|
+
if (key)
|
|
35
|
+
return array.reduce((c, v) => c < v[key] ? c : v[key]);
|
|
36
|
+
else
|
|
37
|
+
return array.reduce((c, v) => c < v ? c : v);
|
|
55
38
|
}
|
|
56
39
|
return 0;
|
|
57
40
|
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {Array} array
|
|
62
|
-
* @param {string} key
|
|
63
|
-
* @returns {Number}
|
|
64
|
-
*/
|
|
65
|
-
exports.minArray = minArray;
|
|
66
|
-
const maxArray = (array, key) => {
|
|
41
|
+
var maxArray = (array, key) => {
|
|
67
42
|
if (!array) {
|
|
68
43
|
console.warn("ARRAY NOT EXITED !");
|
|
69
44
|
return 0;
|
|
70
45
|
}
|
|
71
46
|
if (array.length > 0) {
|
|
72
|
-
if (key)
|
|
47
|
+
if (key)
|
|
48
|
+
return array.reduce((c, v) => c > v[key] ? c : v[key]);
|
|
49
|
+
else
|
|
50
|
+
return array.reduce((c, v) => c > v ? c : v);
|
|
73
51
|
}
|
|
74
52
|
return 0;
|
|
75
53
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const sortElementByString = (array, key) => {
|
|
85
|
-
if (!Array.isArray(array)) return [];
|
|
86
|
-
if (key) return array.sort((x, y) => {
|
|
87
|
-
var a = x[key].toUpperCase(),
|
|
88
|
-
b = y[key].toUpperCase();
|
|
89
|
-
return a == b ? 0 : a > b ? 1 : -1;
|
|
90
|
-
});
|
|
54
|
+
var sortElementByString = (array, key) => {
|
|
55
|
+
if (!Array.isArray(array))
|
|
56
|
+
return [];
|
|
57
|
+
if (key)
|
|
58
|
+
return array.sort((x, y) => {
|
|
59
|
+
var a = x[key].toUpperCase(), b = y[key].toUpperCase();
|
|
60
|
+
return a == b ? 0 : a > b ? 1 : -1;
|
|
61
|
+
});
|
|
91
62
|
console.log("NO KEY");
|
|
92
63
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
exports.sortElementByString = sortElementByString;
|
|
101
|
-
const sortElementByNumber = (array, key) => {
|
|
102
|
-
if (!Array.isArray(array)) return [];
|
|
103
|
-
if (key) return array.sort((a, b) => {
|
|
104
|
-
return a[key] - b[key];
|
|
105
|
-
});
|
|
64
|
+
var sortElementByNumber = (array, key) => {
|
|
65
|
+
if (!Array.isArray(array))
|
|
66
|
+
return [];
|
|
67
|
+
if (key)
|
|
68
|
+
return array.sort((a, b) => {
|
|
69
|
+
return a[key] - b[key];
|
|
70
|
+
});
|
|
106
71
|
console.log("NO KEY");
|
|
107
72
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*/
|
|
114
|
-
exports.sortElementByNumber = sortElementByNumber;
|
|
115
|
-
const firstElement = array => {
|
|
116
|
-
if (array) if (array.length || array.length > 0) return array[0];
|
|
73
|
+
var firstElement = (array) => {
|
|
74
|
+
if (array) {
|
|
75
|
+
if (array.length || array.length > 0)
|
|
76
|
+
return array[0];
|
|
77
|
+
}
|
|
117
78
|
return null;
|
|
118
79
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*/
|
|
125
|
-
exports.firstElement = firstElement;
|
|
126
|
-
const lastElement = array => {
|
|
127
|
-
if (array) if (array.length || array.length > 0) return array[array.length - 1];
|
|
80
|
+
var lastElement = (array) => {
|
|
81
|
+
if (array) {
|
|
82
|
+
if (array.length || array.length > 0)
|
|
83
|
+
return array[array.length - 1];
|
|
84
|
+
}
|
|
128
85
|
return null;
|
|
129
86
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
* @param {Array} array
|
|
134
|
-
* @returns {any}
|
|
135
|
-
*/
|
|
136
|
-
exports.lastElement = lastElement;
|
|
137
|
-
const randomIndex = array => {
|
|
138
|
-
if (array) return (0, _math.randInt)(0, array.length - 1);
|
|
87
|
+
var randomIndex = (array) => {
|
|
88
|
+
if (array)
|
|
89
|
+
return randInt(0, array.length - 1);
|
|
139
90
|
return -1;
|
|
140
91
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
* @param {Array} array
|
|
145
|
-
* @returns {any}
|
|
146
|
-
*/
|
|
147
|
-
exports.randomIndex = randomIndex;
|
|
148
|
-
const randomElement = array => {
|
|
149
|
-
if (array) return array[randomIndex(array)];
|
|
92
|
+
var randomElement = (array) => {
|
|
93
|
+
if (array)
|
|
94
|
+
return array[randomIndex(array)];
|
|
150
95
|
return null;
|
|
151
96
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* @param {Array} list1
|
|
156
|
-
* @param {Array} list2
|
|
157
|
-
* @param {string} key
|
|
158
|
-
* @returns {Array}
|
|
159
|
-
*/
|
|
160
|
-
exports.randomElement = randomElement;
|
|
161
|
-
const mergeAndMakeUniqueElement = (list1, list2, key) => {
|
|
162
|
-
if (!list1 || !list2) return;
|
|
97
|
+
var mergeAndMakeUniqueElement = (list1, list2, key) => {
|
|
98
|
+
if (!list1 || !list2)
|
|
99
|
+
return;
|
|
163
100
|
if (key) {
|
|
164
101
|
return list1.concat(list2).filter((item, index, self) => {
|
|
165
|
-
return self.findIndex(x => x[key] == item[key]) === index;
|
|
102
|
+
return self.findIndex((x) => x[key] == item[key]) === index;
|
|
166
103
|
});
|
|
167
104
|
} else {
|
|
168
105
|
return list1.concat(list2).filter((x, index, self) => {
|
|
@@ -170,30 +107,15 @@ const mergeAndMakeUniqueElement = (list1, list2, key) => {
|
|
|
170
107
|
});
|
|
171
108
|
}
|
|
172
109
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* @param {Array} toMatch
|
|
178
|
-
* @returns {Boolean}
|
|
179
|
-
*/
|
|
180
|
-
exports.mergeAndMakeUniqueElement = mergeAndMakeUniqueElement;
|
|
181
|
-
const allMatchInArray = (target, toMatch) => {
|
|
182
|
-
if (!target || !toMatch) return false;
|
|
183
|
-
const found = toMatch.every(item => {
|
|
110
|
+
var allMatchInArray = (target, toMatch) => {
|
|
111
|
+
if (!target || !toMatch)
|
|
112
|
+
return false;
|
|
113
|
+
const found = toMatch.every((item) => {
|
|
184
114
|
return target.includes(item);
|
|
185
115
|
});
|
|
186
116
|
return found;
|
|
187
117
|
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
*
|
|
191
|
-
* @param {any} item
|
|
192
|
-
* @param {Array} array
|
|
193
|
-
* @returns {Array}
|
|
194
|
-
*/
|
|
195
|
-
exports.allMatchInArray = allMatchInArray;
|
|
196
|
-
const removeItem = (item, array) => {
|
|
118
|
+
var removeItem = (item, array) => {
|
|
197
119
|
const index = array.indexOf(item);
|
|
198
120
|
if (index == -1) {
|
|
199
121
|
console.warn("[ArrayExtra.removeItem] Item not found.");
|
|
@@ -202,17 +124,8 @@ const removeItem = (item, array) => {
|
|
|
202
124
|
array.splice(index, 1);
|
|
203
125
|
return array;
|
|
204
126
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*
|
|
208
|
-
* @param {string} key
|
|
209
|
-
* @param {any} value
|
|
210
|
-
* @param {Array} array
|
|
211
|
-
* @returns {Array}
|
|
212
|
-
*/
|
|
213
|
-
exports.removeItem = removeItem;
|
|
214
|
-
const removeItemByKey = (key, value, array) => {
|
|
215
|
-
const foundIndex = array.findIndex(item => {
|
|
127
|
+
var removeItemByKey = (key, value, array) => {
|
|
128
|
+
const foundIndex = array.findIndex((item) => {
|
|
216
129
|
return item[key] == value;
|
|
217
130
|
});
|
|
218
131
|
if (foundIndex < 0) {
|
|
@@ -222,19 +135,10 @@ const removeItemByKey = (key, value, array) => {
|
|
|
222
135
|
array.splice(foundIndex, 1);
|
|
223
136
|
return array;
|
|
224
137
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
* @param {Number} n
|
|
230
|
-
* @returns {Array}
|
|
231
|
-
*/
|
|
232
|
-
exports.removeItemByKey = removeItemByKey;
|
|
233
|
-
const getRandom = (array, n) => {
|
|
234
|
-
var result = new Array(n),
|
|
235
|
-
len = array.length,
|
|
236
|
-
taken = new Array(len);
|
|
237
|
-
if (n > len) throw new RangeError("getRandom: more elements taken than available");
|
|
138
|
+
var getRandom = (array, n) => {
|
|
139
|
+
var result = new Array(n), len = array.length, taken = new Array(len);
|
|
140
|
+
if (n > len)
|
|
141
|
+
throw new RangeError("getRandom: more elements taken than available");
|
|
238
142
|
while (n--) {
|
|
239
143
|
var x = Math.floor(Math.random() * len);
|
|
240
144
|
result[n] = array[x in taken ? taken[x] : x];
|
|
@@ -242,30 +146,14 @@ const getRandom = (array, n) => {
|
|
|
242
146
|
}
|
|
243
147
|
return result;
|
|
244
148
|
};
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Get an array with shuffle element
|
|
248
|
-
* @param {Array} array
|
|
249
|
-
* @param {Number} n
|
|
250
|
-
* @returns {Array}
|
|
251
|
-
*/
|
|
252
|
-
exports.getRandom = getRandom;
|
|
253
|
-
const getHalfRandom = (array, n) => {
|
|
149
|
+
var getHalfRandom = (array, n) => {
|
|
254
150
|
var n = Math.ceil(array.length / 2);
|
|
255
|
-
return
|
|
151
|
+
return getRandom(array, n);
|
|
256
152
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
* @returns {Array}
|
|
262
|
-
*/
|
|
263
|
-
exports.getHalfRandom = getHalfRandom;
|
|
264
|
-
const shuffle = array => {
|
|
265
|
-
var i = array.length,
|
|
266
|
-
j,
|
|
267
|
-
temp;
|
|
268
|
-
if (i == 0) return array;
|
|
153
|
+
var shuffle = (array) => {
|
|
154
|
+
var i = array.length, j, temp;
|
|
155
|
+
if (array.length < 1)
|
|
156
|
+
return array;
|
|
269
157
|
while (--i) {
|
|
270
158
|
j = Math.floor(Math.random() * (i + 1));
|
|
271
159
|
temp = array[i];
|
|
@@ -274,27 +162,17 @@ const shuffle = array => {
|
|
|
274
162
|
}
|
|
275
163
|
return array;
|
|
276
164
|
};
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
*
|
|
280
|
-
* @param {Array} array
|
|
281
|
-
* @param {Number} oldIndex
|
|
282
|
-
* @param {Number} newIndex
|
|
283
|
-
* @returns {Array}
|
|
284
|
-
*/
|
|
285
|
-
exports.shuffle = shuffle;
|
|
286
|
-
const moveIndex = (array, oldIndex, newIndex) => {
|
|
165
|
+
var moveIndex = (array, oldIndex, newIndex) => {
|
|
287
166
|
if (newIndex >= array.length) {
|
|
288
167
|
var k = newIndex - array.length + 1;
|
|
289
168
|
while (k--) {
|
|
290
|
-
array.push(
|
|
169
|
+
array.push(void 0);
|
|
291
170
|
}
|
|
292
171
|
}
|
|
293
172
|
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
294
173
|
return array;
|
|
295
174
|
};
|
|
296
|
-
|
|
297
|
-
const moveArray = (array, oldIndex, newIndex) => {
|
|
175
|
+
var moveArray = (array, oldIndex, newIndex) => {
|
|
298
176
|
while (oldIndex < 0) {
|
|
299
177
|
oldIndex += array.length;
|
|
300
178
|
}
|
|
@@ -310,4 +188,23 @@ const moveArray = (array, oldIndex, newIndex) => {
|
|
|
310
188
|
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
311
189
|
return array;
|
|
312
190
|
};
|
|
313
|
-
|
|
191
|
+
|
|
192
|
+
exports.allMatchInArray = allMatchInArray;
|
|
193
|
+
exports.averageArray = averageArray;
|
|
194
|
+
exports.firstElement = firstElement;
|
|
195
|
+
exports.getHalfRandom = getHalfRandom;
|
|
196
|
+
exports.getRandom = getRandom;
|
|
197
|
+
exports.lastElement = lastElement;
|
|
198
|
+
exports.maxArray = maxArray;
|
|
199
|
+
exports.mergeAndMakeUniqueElement = mergeAndMakeUniqueElement;
|
|
200
|
+
exports.minArray = minArray;
|
|
201
|
+
exports.moveArray = moveArray;
|
|
202
|
+
exports.moveIndex = moveIndex;
|
|
203
|
+
exports.randomElement = randomElement;
|
|
204
|
+
exports.randomIndex = randomIndex;
|
|
205
|
+
exports.removeItem = removeItem;
|
|
206
|
+
exports.removeItemByKey = removeItemByKey;
|
|
207
|
+
exports.shuffle = shuffle;
|
|
208
|
+
exports.sortElementByNumber = sortElementByNumber;
|
|
209
|
+
exports.sortElementByString = sortElementByString;
|
|
210
|
+
exports.sumArray = sumArray;
|
package/dist/array.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { allMatchInArray, averageArray, firstElement, getHalfRandom, getRandom, lastElement, maxArray, mergeAndMakeUniqueElement, minArray, moveArray, moveIndex, randomElement, randomIndex, removeItem, removeItemByKey, shuffle, sortElementByNumber, sortElementByString, sumArray } from './chunk-Q5R25OIS.mjs';
|
|
2
|
+
import './chunk-VFKAZAWF.mjs';
|
|
3
|
+
import './chunk-AKU6F3WT.mjs';
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined")
|
|
7
|
+
return require.apply(this, arguments);
|
|
8
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
5
9
|
});
|
|
6
|
-
exports.default = createDir;
|
|
7
|
-
const fs = require("fs");
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param {string} path
|
|
12
|
-
*/
|
|
11
|
+
// src/backend/file/createDir.ts
|
|
12
|
+
var fs = __require("fs");
|
|
13
13
|
function createDir(path) {
|
|
14
14
|
if (fs.existsSync(path)) {
|
|
15
15
|
console.log("directory already exited !");
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
|
-
fs.mkdirSync(path, {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
fs.mkdirSync(path, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = createDir;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __require } from '../../chunk-AKU6F3WT.mjs';
|
|
2
|
+
|
|
3
|
+
// src/backend/file/createDir.ts
|
|
4
|
+
var fs = __require("fs");
|
|
5
|
+
function createDir(path) {
|
|
6
|
+
if (fs.existsSync(path)) {
|
|
7
|
+
console.log("directory already exited !");
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
fs.mkdirSync(path, { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { createDir as default };
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined")
|
|
7
|
+
return require.apply(this, arguments);
|
|
8
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
5
9
|
});
|
|
6
|
-
exports.default = fileMove;
|
|
7
|
-
const fs = require("fs");
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param {string} oldPath
|
|
12
|
-
* @param {string} newPath
|
|
13
|
-
* @param {Function} callback
|
|
14
|
-
*/
|
|
11
|
+
// src/backend/file/fileMove.ts
|
|
12
|
+
var fs = __require("fs");
|
|
15
13
|
function fileMove(oldPath, newPath, callback) {
|
|
16
|
-
fs.rename(oldPath, newPath, function
|
|
14
|
+
fs.rename(oldPath, newPath, function(err) {
|
|
17
15
|
if (err) {
|
|
18
16
|
if (err.code === "EXDEV") {
|
|
19
17
|
copy();
|
|
@@ -29,9 +27,11 @@ function fileMove(oldPath, newPath, callback) {
|
|
|
29
27
|
var writeStream = fs.createWriteStream(newPath);
|
|
30
28
|
readStream.on("error", callback);
|
|
31
29
|
writeStream.on("error", callback);
|
|
32
|
-
readStream.on("close", function
|
|
30
|
+
readStream.on("close", function() {
|
|
33
31
|
fs.unlink(oldPath, callback);
|
|
34
32
|
});
|
|
35
33
|
readStream.pipe(writeStream);
|
|
36
34
|
}
|
|
37
|
-
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = fileMove;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __require } from '../../chunk-AKU6F3WT.mjs';
|
|
2
|
+
|
|
3
|
+
// src/backend/file/fileMove.ts
|
|
4
|
+
var fs = __require("fs");
|
|
5
|
+
function fileMove(oldPath, newPath, callback) {
|
|
6
|
+
fs.rename(oldPath, newPath, function(err) {
|
|
7
|
+
if (err) {
|
|
8
|
+
if (err.code === "EXDEV") {
|
|
9
|
+
copy();
|
|
10
|
+
} else {
|
|
11
|
+
callback(err);
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
callback();
|
|
16
|
+
});
|
|
17
|
+
function copy() {
|
|
18
|
+
var readStream = fs.createReadStream(oldPath);
|
|
19
|
+
var writeStream = fs.createWriteStream(newPath);
|
|
20
|
+
readStream.on("error", callback);
|
|
21
|
+
writeStream.on("error", callback);
|
|
22
|
+
readStream.on("close", function() {
|
|
23
|
+
fs.unlink(oldPath, callback);
|
|
24
|
+
});
|
|
25
|
+
readStream.pipe(writeStream);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { fileMove as default };
|
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined")
|
|
7
|
+
return require.apply(this, arguments);
|
|
8
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
5
9
|
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var path = require("path");
|
|
8
|
-
var fs = require("fs");
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
const forEachFileByExt = (base, ext, cb) => {
|
|
17
|
-
var walk = function walk(directoryName) {
|
|
11
|
+
// src/backend/file/findFilesByExt.ts
|
|
12
|
+
var path = __require("path");
|
|
13
|
+
var fs = __require("fs");
|
|
14
|
+
var forEachFileByExt = (base, ext, cb) => {
|
|
15
|
+
var walk = function(directoryName) {
|
|
18
16
|
try {
|
|
19
|
-
fs.readdir(directoryName, function
|
|
17
|
+
fs.readdir(directoryName, function(e, files) {
|
|
20
18
|
if (e) {
|
|
21
19
|
console.log("Error: ", e);
|
|
22
20
|
return;
|
|
23
21
|
}
|
|
24
|
-
files.forEach(function
|
|
22
|
+
files.forEach(function(file) {
|
|
25
23
|
var fullPath = path.join(directoryName, file);
|
|
26
|
-
fs.stat(fullPath, function
|
|
27
|
-
if (
|
|
28
|
-
console.log("Error: ",
|
|
24
|
+
fs.stat(fullPath, function(e2, f) {
|
|
25
|
+
if (e2) {
|
|
26
|
+
console.log("Error: ", e2);
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
31
29
|
if (f.isDirectory()) {
|
|
32
30
|
walk(fullPath);
|
|
33
31
|
} else {
|
|
34
32
|
if (fullPath.toLowerCase().indexOf(ext.toLowerCase()) > -1) {
|
|
35
|
-
if (cb)
|
|
33
|
+
if (cb)
|
|
34
|
+
cb(fullPath);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
});
|
|
@@ -44,5 +43,6 @@ const forEachFileByExt = (base, ext, cb) => {
|
|
|
44
43
|
};
|
|
45
44
|
walk(base);
|
|
46
45
|
};
|
|
47
|
-
var
|
|
48
|
-
|
|
46
|
+
var findFilesByExt_default = forEachFileByExt;
|
|
47
|
+
|
|
48
|
+
module.exports = findFilesByExt_default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __require } from '../../chunk-AKU6F3WT.mjs';
|
|
2
|
+
|
|
3
|
+
// src/backend/file/findFilesByExt.ts
|
|
4
|
+
var path = __require("path");
|
|
5
|
+
var fs = __require("fs");
|
|
6
|
+
var forEachFileByExt = (base, ext, cb) => {
|
|
7
|
+
var walk = function(directoryName) {
|
|
8
|
+
try {
|
|
9
|
+
fs.readdir(directoryName, function(e, files) {
|
|
10
|
+
if (e) {
|
|
11
|
+
console.log("Error: ", e);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
files.forEach(function(file) {
|
|
15
|
+
var fullPath = path.join(directoryName, file);
|
|
16
|
+
fs.stat(fullPath, function(e2, f) {
|
|
17
|
+
if (e2) {
|
|
18
|
+
console.log("Error: ", e2);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (f.isDirectory()) {
|
|
22
|
+
walk(fullPath);
|
|
23
|
+
} else {
|
|
24
|
+
if (fullPath.toLowerCase().indexOf(ext.toLowerCase()) > -1) {
|
|
25
|
+
if (cb)
|
|
26
|
+
cb(fullPath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.log("error", error);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
walk(base);
|
|
37
|
+
};
|
|
38
|
+
var findFilesByExt_default = forEachFileByExt;
|
|
39
|
+
|
|
40
|
+
export { findFilesByExt_default as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/object.ts
|
|
2
|
+
var isNull = (object) => {
|
|
3
|
+
if (typeof object == "undefined")
|
|
4
|
+
return true;
|
|
5
|
+
if (object == "")
|
|
6
|
+
return true;
|
|
7
|
+
if (Array.isArray(object))
|
|
8
|
+
return object.length == 0;
|
|
9
|
+
if (JSON.stringify(object) == "{}")
|
|
10
|
+
return true;
|
|
11
|
+
return object == null;
|
|
12
|
+
};
|
|
13
|
+
var toBool = (object) => {
|
|
14
|
+
if (isNull(object))
|
|
15
|
+
return false;
|
|
16
|
+
object = object.toString();
|
|
17
|
+
return object === "true" || object == "1";
|
|
18
|
+
};
|
|
19
|
+
var toInt = (object) => {
|
|
20
|
+
if (isNull(object))
|
|
21
|
+
return 0;
|
|
22
|
+
object = object.toString();
|
|
23
|
+
return parseInt(object, 10);
|
|
24
|
+
};
|
|
25
|
+
var toFloat = (object) => {
|
|
26
|
+
if (isNull(object))
|
|
27
|
+
return 0;
|
|
28
|
+
object = object.toString();
|
|
29
|
+
return parseFloat(object);
|
|
30
|
+
};
|
|
31
|
+
var toArray = (obj) => {
|
|
32
|
+
if (isNull(obj))
|
|
33
|
+
return [];
|
|
34
|
+
if (!Array.isArray(obj)) {
|
|
35
|
+
obj = [obj];
|
|
36
|
+
}
|
|
37
|
+
return obj;
|
|
38
|
+
};
|
|
39
|
+
var objectToArray = (obj) => {
|
|
40
|
+
const array = [];
|
|
41
|
+
for (const key in obj) {
|
|
42
|
+
array.push(obj[key]);
|
|
43
|
+
}
|
|
44
|
+
return array;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { isNull, objectToArray, toArray, toBool, toFloat, toInt };
|