diginext-utils 1.2.3 → 1.2.4

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 CHANGED
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isJSON = void 0;
7
-
8
7
  require("core-js/modules/es.json.stringify.js");
9
-
10
8
  const isJSON = content => {
11
9
  if (typeof content == "object") {
12
10
  try {
@@ -15,7 +13,6 @@ const isJSON = content => {
15
13
  return false;
16
14
  }
17
15
  }
18
-
19
16
  if (typeof content == "string") {
20
17
  try {
21
18
  content = JSON.parse(content);
@@ -23,12 +20,9 @@ const isJSON = content => {
23
20
  return false;
24
21
  }
25
22
  }
26
-
27
23
  if (typeof content != "object") {
28
24
  return false;
29
25
  }
30
-
31
26
  return true;
32
27
  };
33
-
34
28
  exports.isJSON = isJSON;
@@ -4,59 +4,47 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class EventDispatcher {
9
8
  constructor() {}
10
-
11
9
  addEventListener(type, listener) {
12
10
  if (this._listeners === undefined) this._listeners = {};
13
11
  const listeners = this._listeners;
14
-
15
12
  if (listeners[type] === undefined) {
16
13
  listeners[type] = [];
17
14
  }
18
-
19
15
  if (listeners[type].indexOf(listener) === -1) {
20
16
  listeners[type].push(listener);
21
17
  }
22
18
  }
23
-
24
19
  hasEventListener(type, listener) {
25
20
  if (this._listeners === undefined) return false;
26
21
  const listeners = this._listeners;
27
22
  return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
28
23
  }
29
-
30
24
  removeEventListener(type, listener) {
31
25
  if (this._listeners === undefined) return;
32
26
  const listeners = this._listeners;
33
27
  const listenerArray = listeners[type];
34
-
35
28
  if (listenerArray !== undefined) {
36
29
  const index = listenerArray.indexOf(listener);
37
-
38
30
  if (index !== -1) {
39
31
  listenerArray.splice(index, 1);
40
32
  }
41
33
  }
42
34
  }
43
-
44
35
  dispatchEvent(event) {
45
36
  if (this._listeners === undefined) return;
46
37
  const listeners = this._listeners;
47
38
  const listenerArray = listeners[event.type];
48
-
49
39
  if (listenerArray !== undefined) {
50
- event.target = this; // Make a copy, in case listeners are removed while iterating.
40
+ event.target = this;
51
41
 
42
+ // Make a copy, in case listeners are removed while iterating.
52
43
  const array = listenerArray.slice(0);
53
-
54
44
  for (let i = 0, l = array.length; i < l; i++) {
55
45
  array[i].call(this, event);
56
46
  }
57
47
  }
58
48
  }
59
-
60
49
  }
61
-
62
50
  exports.default = EventDispatcher;
@@ -16,33 +16,27 @@ var _default = {
16
16
  } = _ref;
17
17
  var formData = new FormData();
18
18
  formData.append("upload", blob, "img_" + +new Date() + ".jpg");
19
-
20
19
  if (params) {
21
20
  Object.keys(params).forEach(key => {
22
21
  var val = obj[key];
23
22
  formData.append(key, val);
24
23
  });
25
24
  }
26
-
27
25
  var request = new XMLHttpRequest();
28
26
  request.open("POST", url);
29
27
  request.send(formData);
30
-
31
28
  request.onreadystatechange = function () {
32
29
  if (this.readyState == 4) {
33
30
  // Typical action to be performed when the document is ready:
34
31
  if (this.status == 200) {
35
32
  // var response = JSON.parse(request.response) || "";
36
33
  var response = {};
37
-
38
34
  try {
39
35
  response = JSON.parse(request.response) || "";
40
36
  } catch (error) {
41
37
  console.error(logFile, "Can't part JSON of the response");
42
38
  }
43
-
44
39
  var statusOfSafety = response.status || 0;
45
-
46
40
  if (statusOfSafety == 1) {
47
41
  console.log(logFile, "request: ", request);
48
42
  var data = response.data || {};
@@ -61,13 +55,11 @@ var _default = {
61
55
  }
62
56
  }
63
57
  };
64
-
65
58
  request.onerror = function (res) {
66
59
  var errMsg = "Upload ảnh không thành công!";
67
60
  console.error(logFile, errMsg, "=>", res);
68
61
  if (onError) onError(errMsg);
69
62
  };
70
63
  }
71
-
72
64
  };
73
65
  exports.default = _default;
package/dist/Slug.js CHANGED
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.makeSlug = void 0;
7
-
8
7
  require("core-js/modules/es.regexp.exec.js");
9
-
10
8
  require("core-js/modules/es.string.replace.js");
11
-
12
9
  require("core-js/modules/es.regexp.constructor.js");
13
-
14
10
  require("core-js/modules/es.regexp.to-string.js");
15
-
16
11
  /**
17
12
  * Create a web friendly URL slug from a string.
18
13
  *
@@ -27,7 +22,6 @@ require("core-js/modules/es.regexp.to-string.js");
27
22
  * @license http://creativecommons.org/publicdomain/zero/1.0/
28
23
  *
29
24
  */
30
-
31
25
  /**
32
26
  *
33
27
  * @param {string} s
@@ -38,20 +32,21 @@ const makeSlug = function makeSlug(s) {
38
32
  let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
39
33
  // s = String(s);
40
34
  // opt = Object(opt);
35
+
41
36
  var defaults = {
42
37
  delimiter: "-",
43
38
  limit: undefined,
44
39
  lowercase: true,
45
40
  replacements: {},
46
41
  transliterate: typeof XRegExp === "undefined" ? true : false
47
- }; // Merge options
42
+ };
48
43
 
44
+ // Merge options
49
45
  for (var k in defaults) {
50
46
  if (!opt.hasOwnProperty(k)) {
51
47
  opt[k] = defaults[k];
52
48
  }
53
49
  }
54
-
55
50
  var char_map = {
56
51
  // Latin
57
52
  À: "A",
@@ -342,8 +337,9 @@ const makeSlug = function makeSlug(s) {
342
337
  š: "s",
343
338
  ū: "u",
344
339
  ž: "z"
345
- }; // Vietnamese
340
+ };
346
341
 
342
+ // Vietnamese
347
343
  s = s.replace(/á|à|ả|ạ|ã|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/gi, "a");
348
344
  s = s.replace(/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/gi, "e");
349
345
  s = s.replace(/i|í|ì|ỉ|ĩ|ị/gi, "i");
@@ -356,29 +352,32 @@ const makeSlug = function makeSlug(s) {
356
352
  s = s.replace(/\-\-\-/gi, "-");
357
353
  s = s.replace(/\-\-/gi, "-");
358
354
  s = "@" + s + "@";
359
- s = s.replace(/\@\-|\-\@|\@/gi, ""); // Make custom replacements
355
+ s = s.replace(/\@\-|\-\@|\@/gi, "");
360
356
 
357
+ // Make custom replacements
361
358
  for (var k in opt.replacements) {
362
359
  s = s.replace(RegExp(k, "g"), opt.replacements[k]);
363
- } // Transliterate characters to ASCII
364
-
360
+ }
365
361
 
362
+ // Transliterate characters to ASCII
366
363
  if (opt.transliterate) {
367
364
  for (var k in char_map) {
368
365
  s = s.replace(RegExp(k, "g"), char_map[k]);
369
366
  }
370
- } // Replace non-alphanumeric characters with our delimiter
371
-
367
+ }
372
368
 
369
+ // Replace non-alphanumeric characters with our delimiter
373
370
  var alnum = typeof XRegExp === "undefined" ? RegExp("[^a-z0-9]+", "ig") : XRegExp("[^\\p{L}\\p{N}]+", "ig");
374
- s = s.replace(alnum, opt.delimiter); // Remove duplicate delimiters
371
+ s = s.replace(alnum, opt.delimiter);
375
372
 
376
- s = s.replace(RegExp("[" + opt.delimiter + "]{2,}", "g"), opt.delimiter); // Truncate slug to max. characters
373
+ // Remove duplicate delimiters
374
+ s = s.replace(RegExp("[" + opt.delimiter + "]{2,}", "g"), opt.delimiter);
377
375
 
378
- s = s.substring(0, opt.limit); // Remove delimiter from ends
376
+ // Truncate slug to max. characters
377
+ s = s.substring(0, opt.limit);
379
378
 
379
+ // Remove delimiter from ends
380
380
  s = s.replace(RegExp("(^" + opt.delimiter + "|" + opt.delimiter + "$)", "g"), "");
381
381
  return opt.lowercase ? s.toLowerCase() : s;
382
382
  };
383
-
384
383
  exports.makeSlug = makeSlug;
package/dist/Timer.js CHANGED
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  require("core-js/modules/es.promise.js");
9
-
10
8
  const Timer = {
11
9
  wait: async ms => {
12
10
  return new Promise(resolve => setTimeout(resolve, ms));
@@ -9,9 +9,8 @@ var _default = {
9
9
  // console.log("imageValidate")
10
10
  var maxSize = 10;
11
11
  var fileSize = 1024 * 1024 * maxSize; // 10mb
12
-
13
- var fileTypes = ["image/png", "image/jpeg"]; // var isFileValid = true;
14
-
12
+ var fileTypes = ["image/png", "image/jpeg"];
13
+ // var isFileValid = true;
15
14
  if (!file || fileTypes.indexOf(file.type) < 0) {
16
15
  alert("Vui lòng upload ảnh đúng định dạng jpg hay png");
17
16
  return false;
@@ -19,18 +18,16 @@ var _default = {
19
18
  alert("Vui lòng upload ảnh có dung lượng thấp hơn " + maxSize + "mb");
20
19
  return false;
21
20
  }
22
-
23
21
  return true;
24
22
  },
25
-
26
23
  videoValidate(file) {
27
24
  // console.log("videoValidate")
25
+
28
26
  var maxSize = 15;
29
27
  var fileSize = 1024 * 1024 * maxSize; // 10mb
30
-
31
- var fileTypes = "video"; // console.log(file.type)
28
+ var fileTypes = "video";
29
+ // console.log(file.type)
32
30
  // var isFileValid = true;
33
-
34
31
  if (!file || file.type.indexOf(fileTypes) < 0) {
35
32
  alert("Vui lòng upload video");
36
33
  return false;
@@ -38,9 +35,7 @@ var _default = {
38
35
  alert("Vui lòng upload video có dung lượng thấp hơn " + maxSize + "mb");
39
36
  return false;
40
37
  }
41
-
42
38
  return true;
43
39
  }
44
-
45
40
  };
46
41
  exports.default = _default;
package/dist/array.js CHANGED
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sumArray = exports.sortElementByString = exports.sortElementByNumber = exports.shuffle = exports.removeItemByKey = exports.removeItem = exports.randomIndex = exports.randomElement = exports.moveIndex = exports.moveArray = exports.minArray = exports.mergeAndMakeUniqueElement = exports.maxArray = exports.lastElement = exports.getRandom = exports.getHalfRandom = exports.firstElement = exports.averageArray = exports.allMatchInArray = void 0;
7
-
8
7
  require("core-js/modules/es.array.reduce.js");
9
-
10
8
  require("core-js/modules/es.array.sort.js");
11
-
12
9
  require("core-js/modules/es.array.includes.js");
13
-
14
10
  require("core-js/modules/es.string.includes.js");
15
-
16
11
  var _math = require("./math");
17
-
18
12
  /**
19
13
  *
20
14
  * @param {Array} array
@@ -26,100 +20,84 @@ const sumArray = (array, key) => {
26
20
  console.warn("ARRAY NOT EXITED !");
27
21
  return 0;
28
22
  }
29
-
30
23
  if (key) return array.reduce((c, v) => c + v[key], 0);else return array.reduce((c, v) => c + v, 0);
31
24
  };
25
+
32
26
  /**
33
27
  *
34
28
  * @param {Array} array
35
29
  * @param {string} key
36
30
  * @returns {Number}
37
31
  */
38
-
39
-
40
32
  exports.sumArray = sumArray;
41
-
42
33
  const averageArray = (array, key) => {
43
34
  if (!array) {
44
35
  console.warn("ARRAY NOT EXITED !");
45
36
  return 0;
46
37
  }
47
-
48
38
  return sumArray(array, key) / array.length || 0;
49
39
  };
40
+
50
41
  /**
51
42
  *
52
43
  * @param {Array} array
53
44
  * @param {string} key
54
45
  * @returns {Number}
55
46
  */
56
-
57
-
58
47
  exports.averageArray = averageArray;
59
-
60
48
  const minArray = (array, key) => {
61
49
  if (!array) {
62
50
  console.warn("ARRAY NOT EXITED !");
63
51
  return 0;
64
52
  }
65
-
66
53
  if (array.length > 0) {
67
54
  if (key) return array.reduce((c, v) => c < v[key] ? c : v[key]);else return array.reduce((c, v) => c < v ? c : v);
68
55
  }
69
-
70
56
  return 0;
71
57
  };
58
+
72
59
  /**
73
60
  *
74
61
  * @param {Array} array
75
62
  * @param {string} key
76
63
  * @returns {Number}
77
64
  */
78
-
79
-
80
65
  exports.minArray = minArray;
81
-
82
66
  const maxArray = (array, key) => {
83
67
  if (!array) {
84
68
  console.warn("ARRAY NOT EXITED !");
85
69
  return 0;
86
70
  }
87
-
88
71
  if (array.length > 0) {
89
72
  if (key) return array.reduce((c, v) => c > v[key] ? c : v[key]);else return array.reduce((c, v) => c > v ? c : v);
90
73
  }
91
-
92
74
  return 0;
93
75
  };
76
+
94
77
  /**
95
78
  *
96
79
  * @param {Array} array
97
80
  * @param {string} key
98
81
  * @returns {Array}
99
82
  */
100
-
101
-
102
83
  exports.maxArray = maxArray;
103
-
104
84
  const sortElementByString = (array, key) => {
105
85
  if (!Array.isArray(array)) return [];
106
86
  if (key) return array.sort((x, y) => {
107
87
  var a = x[key].toUpperCase(),
108
- b = y[key].toUpperCase();
88
+ b = y[key].toUpperCase();
109
89
  return a == b ? 0 : a > b ? 1 : -1;
110
90
  });
111
91
  console.log("NO KEY");
112
92
  };
93
+
113
94
  /**
114
95
  *
115
96
  * @param {Array} array
116
97
  * @param {string} key
117
98
  * @returns {Array}
118
99
  */
119
-
120
-
121
100
  exports.sortElementByString = sortElementByString;
122
-
123
101
  const sortElementByNumber = (array, key) => {
124
102
  if (!Array.isArray(array)) return [];
125
103
  if (key) return array.sort((a, b) => {
@@ -127,58 +105,51 @@ const sortElementByNumber = (array, key) => {
127
105
  });
128
106
  console.log("NO KEY");
129
107
  };
108
+
130
109
  /**
131
110
  *
132
111
  * @param {Array} array
133
112
  * @returns {any}
134
113
  */
135
-
136
-
137
114
  exports.sortElementByNumber = sortElementByNumber;
138
-
139
115
  const firstElement = array => {
140
116
  if (array) if (array.length || array.length > 0) return array[0];
141
117
  return null;
142
118
  };
119
+
143
120
  /**
144
121
  *
145
122
  * @param {Array} array
146
123
  * @returns {any}
147
124
  */
148
-
149
-
150
125
  exports.firstElement = firstElement;
151
-
152
126
  const lastElement = array => {
153
127
  if (array) if (array.length || array.length > 0) return array[array.length - 1];
154
128
  return null;
155
129
  };
130
+
156
131
  /**
157
132
  *
158
133
  * @param {Array} array
159
134
  * @returns {any}
160
135
  */
161
-
162
-
163
136
  exports.lastElement = lastElement;
164
-
165
137
  const randomIndex = array => {
166
138
  if (array) return (0, _math.randInt)(0, array.length - 1);
167
139
  return -1;
168
140
  };
141
+
169
142
  /**
170
143
  *
171
144
  * @param {Array} array
172
145
  * @returns {any}
173
146
  */
174
-
175
-
176
147
  exports.randomIndex = randomIndex;
177
-
178
148
  const randomElement = array => {
179
149
  if (array) return array[randomIndex(array)];
180
150
  return null;
181
151
  };
152
+
182
153
  /**
183
154
  * Remove same elements from 2 arrays
184
155
  * @param {Array} list1
@@ -186,13 +157,9 @@ const randomElement = array => {
186
157
  * @param {string} key
187
158
  * @returns {Array}
188
159
  */
189
-
190
-
191
160
  exports.randomElement = randomElement;
192
-
193
161
  const mergeAndMakeUniqueElement = (list1, list2, key) => {
194
162
  if (!list1 || !list2) return;
195
-
196
163
  if (key) {
197
164
  return list1.concat(list2).filter((item, index, self) => {
198
165
  return self.findIndex(x => x[key] == item[key]) === index;
@@ -203,16 +170,14 @@ const mergeAndMakeUniqueElement = (list1, list2, key) => {
203
170
  });
204
171
  }
205
172
  };
173
+
206
174
  /**
207
175
  * check target == toMatch
208
176
  * @param {Array} target
209
177
  * @param {Array} toMatch
210
178
  * @returns {Boolean}
211
179
  */
212
-
213
-
214
180
  exports.mergeAndMakeUniqueElement = mergeAndMakeUniqueElement;
215
-
216
181
  const allMatchInArray = (target, toMatch) => {
217
182
  if (!target || !toMatch) return false;
218
183
  const found = toMatch.every(item => {
@@ -220,27 +185,24 @@ const allMatchInArray = (target, toMatch) => {
220
185
  });
221
186
  return found;
222
187
  };
188
+
223
189
  /**
224
190
  *
225
191
  * @param {any} item
226
192
  * @param {Array} array
227
193
  * @returns {Array}
228
194
  */
229
-
230
-
231
195
  exports.allMatchInArray = allMatchInArray;
232
-
233
196
  const removeItem = (item, array) => {
234
197
  const index = array.indexOf(item);
235
-
236
198
  if (index == -1) {
237
199
  console.warn("[ArrayExtra.removeItem] Item not found.");
238
200
  return array;
239
201
  }
240
-
241
202
  array.splice(index, 1);
242
203
  return array;
243
204
  };
205
+
244
206
  /**
245
207
  *
246
208
  * @param {string} key
@@ -248,85 +210,71 @@ const removeItem = (item, array) => {
248
210
  * @param {Array} array
249
211
  * @returns {Array}
250
212
  */
251
-
252
-
253
213
  exports.removeItem = removeItem;
254
-
255
214
  const removeItemByKey = (key, value, array) => {
256
215
  const foundIndex = array.findIndex(item => {
257
216
  return item[key] == value;
258
217
  });
259
-
260
218
  if (foundIndex < 0) {
261
219
  console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
262
220
  return array;
263
221
  }
264
-
265
222
  array.splice(foundIndex, 1);
266
223
  return array;
267
224
  };
225
+
268
226
  /**
269
227
  * Get an array with shuffle element
270
228
  * @param {Array} array
271
229
  * @param {Number} n
272
230
  * @returns {Array}
273
231
  */
274
-
275
-
276
232
  exports.removeItemByKey = removeItemByKey;
277
-
278
233
  const getRandom = (array, n) => {
279
234
  var result = new Array(n),
280
- len = array.length,
281
- taken = new Array(len);
235
+ len = array.length,
236
+ taken = new Array(len);
282
237
  if (n > len) throw new RangeError("getRandom: more elements taken than available");
283
-
284
238
  while (n--) {
285
239
  var x = Math.floor(Math.random() * len);
286
240
  result[n] = array[x in taken ? taken[x] : x];
287
241
  taken[x] = --len in taken ? taken[len] : len;
288
242
  }
289
-
290
243
  return result;
291
244
  };
245
+
292
246
  /**
293
247
  * Get an array with shuffle element
294
248
  * @param {Array} array
295
249
  * @param {Number} n
296
250
  * @returns {Array}
297
251
  */
298
-
299
-
300
252
  exports.getRandom = getRandom;
301
-
302
253
  const getHalfRandom = (array, n) => {
303
254
  var n = Math.ceil(array.length / 2);
304
255
  return array.getRandom(n);
305
256
  };
257
+
306
258
  /**
307
259
  * Make array shuffle itself
308
260
  * @param {Array} array
309
261
  * @returns {Array}
310
262
  */
311
-
312
-
313
263
  exports.getHalfRandom = getHalfRandom;
314
-
315
264
  const shuffle = array => {
316
265
  var i = array.length,
317
- j,
318
- temp;
266
+ j,
267
+ temp;
319
268
  if (i == 0) return array;
320
-
321
269
  while (--i) {
322
270
  j = Math.floor(Math.random() * (i + 1));
323
271
  temp = array[i];
324
272
  array[i] = array[j];
325
273
  array[j] = temp;
326
274
  }
327
-
328
275
  return array;
329
276
  };
277
+
330
278
  /**
331
279
  *
332
280
  * @param {Array} array
@@ -334,44 +282,32 @@ const shuffle = array => {
334
282
  * @param {Number} newIndex
335
283
  * @returns {Array}
336
284
  */
337
-
338
-
339
285
  exports.shuffle = shuffle;
340
-
341
286
  const moveIndex = (array, oldIndex, newIndex) => {
342
287
  if (newIndex >= array.length) {
343
288
  var k = newIndex - array.length + 1;
344
-
345
289
  while (k--) {
346
290
  array.push(undefined);
347
291
  }
348
292
  }
349
-
350
293
  array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
351
294
  return array;
352
295
  };
353
-
354
296
  exports.moveIndex = moveIndex;
355
-
356
297
  const moveArray = (array, oldIndex, newIndex) => {
357
298
  while (oldIndex < 0) {
358
299
  oldIndex += array.length;
359
300
  }
360
-
361
301
  while (newIndex < 0) {
362
302
  newIndex += array.length;
363
303
  }
364
-
365
304
  if (newIndex >= array.length) {
366
305
  var k = newIndex - array.length;
367
-
368
306
  while (k-- + 1) {
369
307
  array.push(999);
370
308
  }
371
309
  }
372
-
373
310
  array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
374
311
  return array;
375
312
  };
376
-
377
313
  exports.moveArray = moveArray;
@@ -4,20 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = createDir;
7
-
8
7
  const fs = require("fs");
8
+
9
9
  /**
10
10
  *
11
11
  * @param {string} path
12
12
  */
13
-
14
-
15
13
  function createDir(path) {
16
14
  if (fs.existsSync(path)) {
17
15
  console.log("directory already exited !");
18
16
  return true;
19
17
  }
20
-
21
18
  fs.mkdirSync(path, {
22
19
  recursive: true
23
20
  });