diginext-utils 1.0.1 → 1.0.5

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 (68) hide show
  1. package/dist/README.md +3 -0
  2. package/dist/babel.config.json +21 -0
  3. package/dist/index.js +148 -0
  4. package/dist/package.json +34 -0
  5. package/dist/src/Camera.js +420 -0
  6. package/dist/src/Checker.js +34 -0
  7. package/dist/src/Color.js +102 -0
  8. package/dist/src/Device.js +67 -0
  9. package/dist/src/EventDispatcher.js +62 -0
  10. package/dist/src/FileUpload.js +73 -0
  11. package/dist/src/FileUtils.js +47 -0
  12. package/dist/src/Slug.js +384 -0
  13. package/dist/src/Timer.js +16 -0
  14. package/dist/src/UserLS.js +127 -0
  15. package/dist/src/Validation.js +46 -0
  16. package/dist/src/array/index.js +377 -0
  17. package/dist/src/backend/file/createDir.js +24 -0
  18. package/dist/src/backend/file/fileMove.js +42 -0
  19. package/dist/src/backend/file/findFilesByExt.js +55 -0
  20. package/dist/src/backend/zip/extractZip.js +55 -0
  21. package/dist/src/console/enableConsole.js +16 -0
  22. package/dist/src/console/index.js +20 -0
  23. package/dist/src/device/browser.js +52 -0
  24. package/dist/src/device/camera.js +238 -0
  25. package/dist/src/device/index.js +304 -0
  26. package/{src → dist/src}/math/index.js +57 -59
  27. package/dist/src/object/index.js +65 -0
  28. package/dist/src/permission/requestCamera.js +55 -0
  29. package/dist/src/permission/requestDeviceOrientationControl.js +36 -0
  30. package/dist/src/string/index.js +531 -0
  31. package/dist/src/string/url.js +128 -0
  32. package/package.json +17 -13
  33. package/.eslintrc.json +0 -21
  34. package/dist/main.js +0 -1611
  35. package/dist/main.js.map +0 -1
  36. package/dist/module.js +0 -1584
  37. package/dist/module.js.map +0 -1
  38. package/index.js +0 -13
  39. package/src/Browser.js +0 -297
  40. package/src/Camera.js +0 -412
  41. package/src/Checker.js +0 -24
  42. package/src/Color.js +0 -81
  43. package/src/Device.js +0 -56
  44. package/src/EventDispatcher.js +0 -58
  45. package/src/FileUpload.js +0 -59
  46. package/src/FileUtils.js +0 -30
  47. package/src/ReactUtils.js +0 -25
  48. package/src/ScrollPos.js +0 -31
  49. package/src/Slug.js +0 -383
  50. package/src/Timer.js +0 -7
  51. package/src/UserLS.js +0 -104
  52. package/src/Validation.js +0 -35
  53. package/src/array/index.js +0 -301
  54. package/src/backend/file/createDir.js +0 -13
  55. package/src/backend/file/fileMove.js +0 -35
  56. package/src/backend/file/findFilesByExt.js +0 -42
  57. package/src/backend/zip/extractZip.js +0 -58
  58. package/src/console/enableConsole.js +0 -6
  59. package/src/console/index.js +0 -10
  60. package/src/device/browser.js +0 -29
  61. package/src/device/camera.js +0 -228
  62. package/src/device/index.js +0 -233
  63. package/src/isMobileOrTablet.js +0 -28
  64. package/src/object/index.js +0 -41
  65. package/src/permission/requestCamera.js +0 -43
  66. package/src/permission/requestDeviceOrientationControl.js +0 -32
  67. package/src/string/index.js +0 -228
  68. package/src/string/url.js +0 -93
@@ -0,0 +1,377 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
+ require("core-js/modules/es.array.reduce.js");
9
+
10
+ require("core-js/modules/es.array.sort.js");
11
+
12
+ require("core-js/modules/es.array.includes.js");
13
+
14
+ require("core-js/modules/es.string.includes.js");
15
+
16
+ var _math = require("../math");
17
+
18
+ /**
19
+ *
20
+ * @param {Array} array
21
+ * @param {string} key
22
+ * @returns {Number}
23
+ */
24
+ const sumArray = (array, key) => {
25
+ if (!array) {
26
+ console.warn("ARRAY NOT EXITED !");
27
+ return 0;
28
+ }
29
+
30
+ if (key) return array.reduce((c, v) => c + v[key], 0);else return array.reduce((c, v) => c + v, 0);
31
+ };
32
+ /**
33
+ *
34
+ * @param {Array} array
35
+ * @param {string} key
36
+ * @returns {Number}
37
+ */
38
+
39
+
40
+ exports.sumArray = sumArray;
41
+
42
+ const averageArray = (array, key) => {
43
+ if (!array) {
44
+ console.warn("ARRAY NOT EXITED !");
45
+ return 0;
46
+ }
47
+
48
+ return (void 0).sum(array, key) / array.length || 0;
49
+ };
50
+ /**
51
+ *
52
+ * @param {Array} array
53
+ * @param {string} key
54
+ * @returns {Number}
55
+ */
56
+
57
+
58
+ exports.averageArray = averageArray;
59
+
60
+ const minArray = (array, key) => {
61
+ if (!array) {
62
+ console.warn("ARRAY NOT EXITED !");
63
+ return 0;
64
+ }
65
+
66
+ if (array.length > 0) {
67
+ if (key) return array.reduce((c, v) => c < v[key] ? c : v[key]);else return array.reduce((c, v) => c < v ? c : v);
68
+ }
69
+
70
+ return 0;
71
+ };
72
+ /**
73
+ *
74
+ * @param {Array} array
75
+ * @param {string} key
76
+ * @returns {Number}
77
+ */
78
+
79
+
80
+ exports.minArray = minArray;
81
+
82
+ const maxArray = (array, key) => {
83
+ if (!array) {
84
+ console.warn("ARRAY NOT EXITED !");
85
+ return 0;
86
+ }
87
+
88
+ if (array.length > 0) {
89
+ if (key) return array.reduce((c, v) => c > v[key] ? c : v[key]);else return array.reduce((c, v) => c > v ? c : v);
90
+ }
91
+
92
+ return 0;
93
+ };
94
+ /**
95
+ *
96
+ * @param {Array} array
97
+ * @param {string} key
98
+ * @returns {Array}
99
+ */
100
+
101
+
102
+ exports.maxArray = maxArray;
103
+
104
+ const sortElementByString = (array, key) => {
105
+ if (!Array.isArray(array)) return [];
106
+ if (key) return array.sort((x, y) => {
107
+ var a = x[key].toUpperCase(),
108
+ b = y[key].toUpperCase();
109
+ return a == b ? 0 : a > b ? 1 : -1;
110
+ });
111
+ console.log("NO KEY");
112
+ };
113
+ /**
114
+ *
115
+ * @param {Array} array
116
+ * @param {string} key
117
+ * @returns {Array}
118
+ */
119
+
120
+
121
+ exports.sortElementByString = sortElementByString;
122
+
123
+ const sortElementByNumber = (array, key) => {
124
+ if (!Array.isArray(array)) return [];
125
+ if (key) return array.sort((a, b) => {
126
+ return a[key] - b[key];
127
+ });
128
+ console.log("NO KEY");
129
+ };
130
+ /**
131
+ *
132
+ * @param {Array} array
133
+ * @returns {any}
134
+ */
135
+
136
+
137
+ exports.sortElementByNumber = sortElementByNumber;
138
+
139
+ const firstElement = array => {
140
+ if (array) if (array.length || array.length > 0) return array[0];
141
+ return null;
142
+ };
143
+ /**
144
+ *
145
+ * @param {Array} array
146
+ * @returns {any}
147
+ */
148
+
149
+
150
+ exports.firstElement = firstElement;
151
+
152
+ const lastElement = array => {
153
+ if (array) if (array.length || array.length > 0) return array[array.length - 1];
154
+ return null;
155
+ };
156
+ /**
157
+ *
158
+ * @param {Array} array
159
+ * @returns {any}
160
+ */
161
+
162
+
163
+ exports.lastElement = lastElement;
164
+
165
+ const randomIndex = array => {
166
+ if (array) return (0, _math.randInt)(0, array.length - 1);
167
+ return -1;
168
+ };
169
+ /**
170
+ *
171
+ * @param {Array} array
172
+ * @returns {any}
173
+ */
174
+
175
+
176
+ exports.randomIndex = randomIndex;
177
+
178
+ const randomElement = array => {
179
+ if (array) return array[randomIndex(array)];
180
+ return null;
181
+ };
182
+ /**
183
+ * Remove same elements from 2 arrays
184
+ * @param {Array} list1
185
+ * @param {Array} list2
186
+ * @param {string} key
187
+ * @returns {Array}
188
+ */
189
+
190
+
191
+ exports.randomElement = randomElement;
192
+
193
+ const mergeAndMakeUniqueElement = (list1, list2, key) => {
194
+ if (!list1 || !list2) return;
195
+
196
+ if (key) {
197
+ return list1.concat(list2).filter((item, index, self) => {
198
+ return self.findIndex(x => x[key] == item[key]) === index;
199
+ });
200
+ } else {
201
+ return list1.concat(list2).filter((x, index, self) => {
202
+ return self.indexOf(x) === index;
203
+ });
204
+ }
205
+ };
206
+ /**
207
+ * check target == toMatch
208
+ * @param {Array} target
209
+ * @param {Array} toMatch
210
+ * @returns {Boolean}
211
+ */
212
+
213
+
214
+ exports.mergeAndMakeUniqueElement = mergeAndMakeUniqueElement;
215
+
216
+ const allMatchInArray = (target, toMatch) => {
217
+ if (!target || !toMatch) return false;
218
+ const found = toMatch.every(item => {
219
+ return target.includes(item);
220
+ });
221
+ return found;
222
+ };
223
+ /**
224
+ *
225
+ * @param {any} item
226
+ * @param {Array} array
227
+ * @returns {Array}
228
+ */
229
+
230
+
231
+ exports.allMatchInArray = allMatchInArray;
232
+
233
+ const removeItem = (item, array) => {
234
+ const index = array.indexOf(item);
235
+
236
+ if (index == -1) {
237
+ console.warn("[ArrayExtra.removeItem] Item not found.");
238
+ return array;
239
+ }
240
+
241
+ array.splice(index, 1);
242
+ return array;
243
+ };
244
+ /**
245
+ *
246
+ * @param {string} key
247
+ * @param {any} value
248
+ * @param {Array} array
249
+ * @returns {Array}
250
+ */
251
+
252
+
253
+ exports.removeItem = removeItem;
254
+
255
+ const removeItemByKey = (key, value, array) => {
256
+ const foundIndex = array.findIndex(item => {
257
+ return item[key] == value;
258
+ });
259
+
260
+ if (foundIndex < 0) {
261
+ console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
262
+ return array;
263
+ }
264
+
265
+ array.splice(foundIndex, 1);
266
+ return array;
267
+ };
268
+ /**
269
+ * Get an array with shuffle element
270
+ * @param {Array} array
271
+ * @param {Number} n
272
+ * @returns {Array}
273
+ */
274
+
275
+
276
+ exports.removeItemByKey = removeItemByKey;
277
+
278
+ const getRandom = (array, n) => {
279
+ var result = new Array(n),
280
+ len = array.length,
281
+ taken = new Array(len);
282
+ if (n > len) throw new RangeError("getRandom: more elements taken than available");
283
+
284
+ while (n--) {
285
+ var x = Math.floor(Math.random() * len);
286
+ result[n] = array[x in taken ? taken[x] : x];
287
+ taken[x] = --len in taken ? taken[len] : len;
288
+ }
289
+
290
+ return result;
291
+ };
292
+ /**
293
+ * Get an array with shuffle element
294
+ * @param {Array} array
295
+ * @param {Number} n
296
+ * @returns {Array}
297
+ */
298
+
299
+
300
+ exports.getRandom = getRandom;
301
+
302
+ const getHalfRandom = (array, n) => {
303
+ var n = Math.ceil(array.length / 2);
304
+ return array.getRandom(n);
305
+ };
306
+ /**
307
+ * Make array shuffle itself
308
+ * @param {Array} array
309
+ * @returns {Array}
310
+ */
311
+
312
+
313
+ exports.getHalfRandom = getHalfRandom;
314
+
315
+ const shuffle = array => {
316
+ var i = array.length,
317
+ j,
318
+ temp;
319
+ if (i == 0) return array;
320
+
321
+ while (--i) {
322
+ j = Math.floor(Math.random() * (i + 1));
323
+ temp = array[i];
324
+ array[i] = array[j];
325
+ array[j] = temp;
326
+ }
327
+
328
+ return array;
329
+ };
330
+ /**
331
+ *
332
+ * @param {Array} array
333
+ * @param {Number} oldIndex
334
+ * @param {Number} newIndex
335
+ * @returns {Array}
336
+ */
337
+
338
+
339
+ exports.shuffle = shuffle;
340
+
341
+ const moveIndex = (array, oldIndex, newIndex) => {
342
+ if (newIndex >= array.length) {
343
+ var k = newIndex - array.length + 1;
344
+
345
+ while (k--) {
346
+ array.push(undefined);
347
+ }
348
+ }
349
+
350
+ array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
351
+ return array;
352
+ };
353
+
354
+ exports.moveIndex = moveIndex;
355
+
356
+ const moveArray = (array, oldIndex, newIndex) => {
357
+ while (oldIndex < 0) {
358
+ oldIndex += array.length;
359
+ }
360
+
361
+ while (newIndex < 0) {
362
+ newIndex += array.length;
363
+ }
364
+
365
+ if (newIndex >= array.length) {
366
+ var k = newIndex - array.length;
367
+
368
+ while (k-- + 1) {
369
+ array.push(999);
370
+ }
371
+ }
372
+
373
+ array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
374
+ return array;
375
+ };
376
+
377
+ exports.moveArray = moveArray;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = createDir;
7
+
8
+ const fs = require("fs");
9
+ /**
10
+ *
11
+ * @param {string} path
12
+ */
13
+
14
+
15
+ function createDir(path) {
16
+ if (fs.existsSync(path)) {
17
+ console.log("directory already exited !");
18
+ return true;
19
+ }
20
+
21
+ fs.mkdirSync(path, {
22
+ recursive: true
23
+ });
24
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = fileMove;
7
+
8
+ const fs = require("fs");
9
+ /**
10
+ *
11
+ * @param {string} oldPath
12
+ * @param {string} newPath
13
+ * @param {Function} callback
14
+ */
15
+
16
+
17
+ function fileMove(oldPath, newPath, callback) {
18
+ fs.rename(oldPath, newPath, function (err) {
19
+ if (err) {
20
+ if (err.code === "EXDEV") {
21
+ copy();
22
+ } else {
23
+ callback(err);
24
+ }
25
+
26
+ return;
27
+ }
28
+
29
+ callback();
30
+ });
31
+
32
+ function copy() {
33
+ var readStream = fs.createReadStream(oldPath);
34
+ var writeStream = fs.createWriteStream(newPath);
35
+ readStream.on("error", callback);
36
+ writeStream.on("error", callback);
37
+ readStream.on("close", function () {
38
+ fs.unlink(oldPath, callback);
39
+ });
40
+ readStream.pipe(writeStream);
41
+ }
42
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var path = require("path");
9
+
10
+ var fs = require("fs");
11
+ /**
12
+ *
13
+ * @param {string} base
14
+ * @param {string} ext
15
+ * @param {Function} cb
16
+ */
17
+
18
+
19
+ const forEachFileByExt = (base, ext, cb) => {
20
+ var walk = function walk(directoryName) {
21
+ try {
22
+ fs.readdir(directoryName, function (e, files) {
23
+ if (e) {
24
+ console.log("Error: ", e);
25
+ return;
26
+ }
27
+
28
+ files.forEach(function (file) {
29
+ var fullPath = path.join(directoryName, file);
30
+ fs.stat(fullPath, function (e, f) {
31
+ if (e) {
32
+ console.log("Error: ", e);
33
+ return;
34
+ }
35
+
36
+ if (f.isDirectory()) {
37
+ walk(fullPath);
38
+ } else {
39
+ if (fullPath.toLowerCase().indexOf(ext.toLowerCase()) > -1) {
40
+ if (cb) cb(fullPath);
41
+ }
42
+ }
43
+ });
44
+ });
45
+ });
46
+ } catch (error) {
47
+ console.log("error", error);
48
+ }
49
+ };
50
+
51
+ walk(base);
52
+ };
53
+
54
+ var _default = forEachFileByExt;
55
+ exports.default = _default;
@@ -0,0 +1,55 @@
1
+ // import JSZip from "jszip";
2
+ // import ObjectExtra from "plugins/utils/ObjectExtra";
3
+ // import createDir from "../file/createDir";
4
+ // const fs = require("fs");
5
+ // const path = require("path");
6
+ // /**
7
+ // *
8
+ // * @param {string} zipPath
9
+ // * @param {string} directory
10
+ // * @param {Function} forEach
11
+ // */
12
+ // const extractZip = async (zipPath, directory, forEach) => {
13
+ // // let id = -1;
14
+ // // let isCallcb = false;
15
+ // fs.readFile(zipPath, async function (err, data) {
16
+ // if (err) throw err;
17
+ // JSZip.loadAsync(data)
18
+ // .then(async function (zip) {
19
+ // const _length = ObjectExtra.toArray(zip).length;
20
+ // zip.forEach((filePath, fileObj) => {
21
+ // console.log(filePath);
22
+ // var fileName = path.resolve(directory, filePath);
23
+ // if (fileName.indexOf(".DS_Store") >= 0) {
24
+ // return;
25
+ // }
26
+ // if (fileName.indexOf("__MACOSX/") >= 0) {
27
+ // return;
28
+ // }
29
+ // // console.log(fileName)
30
+ // if (fileObj.dir) {
31
+ // createDir(fileName);
32
+ // if (forEach) forEach(fileName, false);
33
+ // } else {
34
+ // try {
35
+ // fileObj.async("nodebuffer").then((buff) => {
36
+ // fs.writeFileSync(fileName, buff);
37
+ // if (forEach) forEach(fileName, true);
38
+ // // id++;
39
+ // // if (id >= _length) if (callback && !isCallcb) {
40
+ // // console.log("4")
41
+ // // isCallcb = true;
42
+ // // if (callback) callback();
43
+ // // }
44
+ // });
45
+ // } catch (error) {
46
+ // cosole.log("extractZip ERROR", error);
47
+ // }
48
+ // }
49
+ // });
50
+ // })
51
+ // .then(function () {});
52
+ // });
53
+ // };
54
+ // export default extractZip;
55
+ "use strict";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = enableConsole;
7
+
8
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const _console = (0, _cloneDeep.default)(console);
13
+
14
+ function enableConsole(params) {
15
+ return _console;
16
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.showCredit = exports.disableConsole = void 0;
7
+
8
+ const disableConsole = params => {
9
+ for (var i in console) {
10
+ console[i] = function () {};
11
+ }
12
+ };
13
+
14
+ exports.disableConsole = disableConsole;
15
+
16
+ const showCredit = params => {
17
+ console.log("Developed by Digitop | https://www.wearetopgroup.com/?utm_src=console");
18
+ };
19
+
20
+ exports.showCredit = showCredit;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ua = exports.isPotrait = exports.isLandscape = exports.isInAppWebview = exports.isFacebookWebview = void 0;
7
+
8
+ require("core-js/modules/es.regexp.constructor.js");
9
+
10
+ require("core-js/modules/es.regexp.exec.js");
11
+
12
+ require("core-js/modules/es.regexp.to-string.js");
13
+
14
+ require("core-js/modules/es.string.match.js");
15
+
16
+ const isPotrait = params => {
17
+ if (typeof window == "undefined") return false;
18
+ if (!window.orientation) return window.matchMedia("(orientation: portrait)").matches;
19
+ return !(window.orientation === 90 || window.orientation === -90);
20
+ };
21
+
22
+ exports.isPotrait = isPotrait;
23
+
24
+ const isLandscape = params => {
25
+ return !isPotrait();
26
+ };
27
+
28
+ exports.isLandscape = isLandscape;
29
+
30
+ const ua = params => {
31
+ if (typeof navigator == "undefined") return null;
32
+ if (typeof window == "undefined") return null;
33
+ return navigator.userAgent || navigator.vendor || window.opera;
34
+ };
35
+
36
+ exports.ua = ua;
37
+
38
+ const isFacebookWebview = params => {
39
+ var ua = ua();
40
+ if (ua) return ua.indexOf("FBAN") > -1 || ua.indexOf("FBAV") > -1;
41
+ };
42
+
43
+ exports.isFacebookWebview = isFacebookWebview;
44
+
45
+ const isInAppWebview = params => {
46
+ const rules = ["WebView", "(iPhone|iPod|iPad)(?!.*Safari/)", "Android.*(wv|.0.0.0)"];
47
+ const regex = new RegExp("(".concat(rules.join("|"), ")"), "ig");
48
+ if (ua()) return Boolean(ua().match(regex));
49
+ return false;
50
+ };
51
+
52
+ exports.isInAppWebview = isInAppWebview;