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