diginext-utils 1.2.4 → 2.0.0

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/array.js DELETED
@@ -1,313 +0,0 @@
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
- require("core-js/modules/es.array.reduce.js");
8
- require("core-js/modules/es.array.sort.js");
9
- require("core-js/modules/es.array.includes.js");
10
- require("core-js/modules/es.string.includes.js");
11
- var _math = require("./math");
12
- /**
13
- *
14
- * @param {Array} array
15
- * @param {string} key
16
- * @returns {Number}
17
- */
18
- const sumArray = (array, key) => {
19
- if (!array) {
20
- console.warn("ARRAY NOT EXITED !");
21
- return 0;
22
- }
23
- if (key) return array.reduce((c, v) => c + v[key], 0);else return array.reduce((c, v) => c + v, 0);
24
- };
25
-
26
- /**
27
- *
28
- * @param {Array} array
29
- * @param {string} key
30
- * @returns {Number}
31
- */
32
- exports.sumArray = sumArray;
33
- const averageArray = (array, key) => {
34
- if (!array) {
35
- console.warn("ARRAY NOT EXITED !");
36
- return 0;
37
- }
38
- return sumArray(array, key) / array.length || 0;
39
- };
40
-
41
- /**
42
- *
43
- * @param {Array} array
44
- * @param {string} key
45
- * @returns {Number}
46
- */
47
- exports.averageArray = averageArray;
48
- const minArray = (array, key) => {
49
- if (!array) {
50
- console.warn("ARRAY NOT EXITED !");
51
- return 0;
52
- }
53
- if (array.length > 0) {
54
- if (key) return array.reduce((c, v) => c < v[key] ? c : v[key]);else return array.reduce((c, v) => c < v ? c : v);
55
- }
56
- return 0;
57
- };
58
-
59
- /**
60
- *
61
- * @param {Array} array
62
- * @param {string} key
63
- * @returns {Number}
64
- */
65
- exports.minArray = minArray;
66
- const maxArray = (array, key) => {
67
- if (!array) {
68
- console.warn("ARRAY NOT EXITED !");
69
- return 0;
70
- }
71
- if (array.length > 0) {
72
- if (key) return array.reduce((c, v) => c > v[key] ? c : v[key]);else return array.reduce((c, v) => c > v ? c : v);
73
- }
74
- return 0;
75
- };
76
-
77
- /**
78
- *
79
- * @param {Array} array
80
- * @param {string} key
81
- * @returns {Array}
82
- */
83
- exports.maxArray = maxArray;
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
- });
91
- console.log("NO KEY");
92
- };
93
-
94
- /**
95
- *
96
- * @param {Array} array
97
- * @param {string} key
98
- * @returns {Array}
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
- });
106
- console.log("NO KEY");
107
- };
108
-
109
- /**
110
- *
111
- * @param {Array} array
112
- * @returns {any}
113
- */
114
- exports.sortElementByNumber = sortElementByNumber;
115
- const firstElement = array => {
116
- if (array) if (array.length || array.length > 0) return array[0];
117
- return null;
118
- };
119
-
120
- /**
121
- *
122
- * @param {Array} array
123
- * @returns {any}
124
- */
125
- exports.firstElement = firstElement;
126
- const lastElement = array => {
127
- if (array) if (array.length || array.length > 0) return array[array.length - 1];
128
- return null;
129
- };
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);
139
- return -1;
140
- };
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)];
150
- return null;
151
- };
152
-
153
- /**
154
- * Remove same elements from 2 arrays
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;
163
- if (key) {
164
- return list1.concat(list2).filter((item, index, self) => {
165
- return self.findIndex(x => x[key] == item[key]) === index;
166
- });
167
- } else {
168
- return list1.concat(list2).filter((x, index, self) => {
169
- return self.indexOf(x) === index;
170
- });
171
- }
172
- };
173
-
174
- /**
175
- * check target == toMatch
176
- * @param {Array} target
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 => {
184
- return target.includes(item);
185
- });
186
- return found;
187
- };
188
-
189
- /**
190
- *
191
- * @param {any} item
192
- * @param {Array} array
193
- * @returns {Array}
194
- */
195
- exports.allMatchInArray = allMatchInArray;
196
- const removeItem = (item, array) => {
197
- const index = array.indexOf(item);
198
- if (index == -1) {
199
- console.warn("[ArrayExtra.removeItem] Item not found.");
200
- return array;
201
- }
202
- array.splice(index, 1);
203
- return array;
204
- };
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 => {
216
- return item[key] == value;
217
- });
218
- if (foundIndex < 0) {
219
- console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
220
- return array;
221
- }
222
- array.splice(foundIndex, 1);
223
- return array;
224
- };
225
-
226
- /**
227
- * Get an array with shuffle element
228
- * @param {Array} array
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");
238
- while (n--) {
239
- var x = Math.floor(Math.random() * len);
240
- result[n] = array[x in taken ? taken[x] : x];
241
- taken[x] = --len in taken ? taken[len] : len;
242
- }
243
- return result;
244
- };
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) => {
254
- var n = Math.ceil(array.length / 2);
255
- return array.getRandom(n);
256
- };
257
-
258
- /**
259
- * Make array shuffle itself
260
- * @param {Array} array
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;
269
- while (--i) {
270
- j = Math.floor(Math.random() * (i + 1));
271
- temp = array[i];
272
- array[i] = array[j];
273
- array[j] = temp;
274
- }
275
- return array;
276
- };
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) => {
287
- if (newIndex >= array.length) {
288
- var k = newIndex - array.length + 1;
289
- while (k--) {
290
- array.push(undefined);
291
- }
292
- }
293
- array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
294
- return array;
295
- };
296
- exports.moveIndex = moveIndex;
297
- const moveArray = (array, oldIndex, newIndex) => {
298
- while (oldIndex < 0) {
299
- oldIndex += array.length;
300
- }
301
- while (newIndex < 0) {
302
- newIndex += array.length;
303
- }
304
- if (newIndex >= array.length) {
305
- var k = newIndex - array.length;
306
- while (k-- + 1) {
307
- array.push(999);
308
- }
309
- }
310
- array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
311
- return array;
312
- };
313
- exports.moveArray = moveArray;
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createDir;
7
- const fs = require("fs");
8
-
9
- /**
10
- *
11
- * @param {string} path
12
- */
13
- function createDir(path) {
14
- if (fs.existsSync(path)) {
15
- console.log("directory already exited !");
16
- return true;
17
- }
18
- fs.mkdirSync(path, {
19
- recursive: true
20
- });
21
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = fileMove;
7
- const fs = require("fs");
8
-
9
- /**
10
- *
11
- * @param {string} oldPath
12
- * @param {string} newPath
13
- * @param {Function} callback
14
- */
15
- function fileMove(oldPath, newPath, callback) {
16
- fs.rename(oldPath, newPath, function (err) {
17
- if (err) {
18
- if (err.code === "EXDEV") {
19
- copy();
20
- } else {
21
- callback(err);
22
- }
23
- return;
24
- }
25
- callback();
26
- });
27
- function copy() {
28
- var readStream = fs.createReadStream(oldPath);
29
- var writeStream = fs.createWriteStream(newPath);
30
- readStream.on("error", callback);
31
- writeStream.on("error", callback);
32
- readStream.on("close", function () {
33
- fs.unlink(oldPath, callback);
34
- });
35
- readStream.pipe(writeStream);
36
- }
37
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var path = require("path");
8
- var fs = require("fs");
9
-
10
- /**
11
- *
12
- * @param {string} base
13
- * @param {string} ext
14
- * @param {Function} cb
15
- */
16
- const forEachFileByExt = (base, ext, cb) => {
17
- var walk = function walk(directoryName) {
18
- try {
19
- fs.readdir(directoryName, function (e, files) {
20
- if (e) {
21
- console.log("Error: ", e);
22
- return;
23
- }
24
- files.forEach(function (file) {
25
- var fullPath = path.join(directoryName, file);
26
- fs.stat(fullPath, function (e, f) {
27
- if (e) {
28
- console.log("Error: ", e);
29
- return;
30
- }
31
- if (f.isDirectory()) {
32
- walk(fullPath);
33
- } else {
34
- if (fullPath.toLowerCase().indexOf(ext.toLowerCase()) > -1) {
35
- if (cb) cb(fullPath);
36
- }
37
- }
38
- });
39
- });
40
- });
41
- } catch (error) {
42
- console.log("error", error);
43
- }
44
- };
45
- walk(base);
46
- };
47
- var _default = forEachFileByExt;
48
- exports.default = _default;
@@ -1,59 +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;
59
- "use strict";
package/dist/color.js DELETED
@@ -1,86 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.random = exports.pSBC = exports.hexToRgb = exports.hexLighten = exports.hexDarken = exports.RGBToHex = void 0;
7
- require("core-js/modules/es.regexp.to-string.js");
8
- require("core-js/modules/es.parse-int.js");
9
- require("core-js/modules/web.dom-collections.iterator.js");
10
- require("core-js/modules/es.parse-float.js");
11
- require("core-js/modules/es.regexp.exec.js");
12
- const random = function random() {
13
- let hex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
14
- return (hex ? "#" : "") + Math.floor(Math.random() * 16777215).toString(16);
15
- };
16
-
17
- // This function (pSBC) will take a HEX or RGB web color.
18
- // pSBC can shade it darker or lighter, or blend it with a second color, and can also pass it right thru but convert from Hex to RGB (Hex2RGB) or RGB to Hex (RGB2Hex).
19
- // All without you even knowing what color format you are using.
20
- // Version 4.0 (pref: https://github.com/PimpTrizkit/PJs/wiki/12.-Shade,-Blend-and-Convert-a-Web-Color-(pSBC.js));
21
- exports.random = random;
22
- const pSBC = (p, c0, c1, l) => {
23
- let r,
24
- g,
25
- b,
26
- P,
27
- f,
28
- t,
29
- h,
30
- i = parseInt,
31
- m = Math.round,
32
- a = typeof c1 == "string";
33
- if (typeof p != "number" || p < -1 || p > 1 || typeof c0 != "string" || c0[0] != "r" && c0[0] != "#" || c1 && !a) return null;
34
- const pSBCr = d => {
35
- let n = d.length,
36
- x = {};
37
- if (n > 9) {
38
- [r, g, b, a] = d = d.split(","), n = d.length;
39
- if (n < 3 || n > 4) return null;
40
- x.r = i(r[3] == "a" ? r.slice(5) : r.slice(4)), x.g = i(g), x.b = i(b), x.a = a ? parseFloat(a) : -1;
41
- } else {
42
- if (n == 8 || n == 6 || n < 4) return null;
43
- if (n < 6) d = "#" + d[1] + d[1] + d[2] + d[2] + d[3] + d[3] + (n > 4 ? d[4] + d[4] : "");
44
- d = i(d.slice(1), 16);
45
- if (n == 9 || n == 5) x.r = d >> 24 & 255, x.g = d >> 16 & 255, x.b = d >> 8 & 255, x.a = m((d & 255) / 0.255) / 1000;else x.r = d >> 16, x.g = d >> 8 & 255, x.b = d & 255, x.a = -1;
46
- }
47
- return x;
48
- };
49
- h = c0.length > 9, h = a ? c1.length > 9 ? true : c1 == "c" ? !h : false : h, f = pSBCr(c0), P = p < 0, t = c1 && c1 != "c" ? pSBCr(c1) : P ? {
50
- r: 0,
51
- g: 0,
52
- b: 0,
53
- a: -1
54
- } : {
55
- r: 255,
56
- g: 255,
57
- b: 255,
58
- a: -1
59
- }, p = P ? p * -1 : p, P = 1 - p;
60
- if (!f || !t) return null;
61
- if (l) r = m(P * f.r + p * t.r), g = m(P * f.g + p * t.g), b = m(P * f.b + p * t.b);else r = m((P * f.r ** 2 + p * t.r ** 2) ** 0.5), g = m((P * f.g ** 2 + p * t.g ** 2) ** 0.5), b = m((P * f.b ** 2 + p * t.b ** 2) ** 0.5);
62
- a = f.a, t = t.a, f = a >= 0 || t >= 0, a = f ? a < 0 ? t : t < 0 ? a : a * P + t * p : 0;
63
- if (h) return "rgb" + (f ? "a(" : "(") + r + "," + g + "," + b + (f ? "," + m(a * 1000) / 1000 : "") + ")";else return "#" + (4294967296 + r * 16777216 + g * 65536 + b * 256 + (f ? m(a * 255) : 0)).toString(16).slice(1, f ? undefined : -2);
64
- };
65
- exports.pSBC = pSBC;
66
- const hexToRgb = hex => {
67
- var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
68
- return result ? {
69
- r: parseInt(result[1], 16),
70
- g: parseInt(result[2], 16),
71
- b: parseInt(result[3], 16)
72
- } : null;
73
- };
74
- exports.hexToRgb = hexToRgb;
75
- const hexDarken = (hex, amount) => {
76
- return pSBC(-amount, hex);
77
- };
78
- exports.hexDarken = hexDarken;
79
- const hexLighten = (hex, amount) => {
80
- return pSBC(amount, hex);
81
- };
82
- exports.hexLighten = hexLighten;
83
- const RGBToHex = rgb => {
84
- return pSBC(0, rgb, "c", true);
85
- };
86
- exports.RGBToHex = RGBToHex;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = enableConsole;
7
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const _console = (0, _cloneDeep.default)(console);
10
- function enableConsole(params) {
11
- return _console;
12
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.showCredit = exports.disableConsole = void 0;
7
- const disableConsole = params => {
8
- for (var i in console) {
9
- console[i] = function () {};
10
- }
11
- };
12
- exports.disableConsole = disableConsole;
13
- const showCredit = params => {
14
- console.log("Developed by Digitop | https://www.wearetopgroup.com/?utm_src=console");
15
- };
16
- exports.showCredit = showCredit;
@@ -1,38 +0,0 @@
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
- require("core-js/modules/es.regexp.constructor.js");
8
- require("core-js/modules/es.regexp.exec.js");
9
- require("core-js/modules/es.regexp.to-string.js");
10
- require("core-js/modules/es.string.match.js");
11
- const isPotrait = params => {
12
- if (typeof window == "undefined") return false;
13
- if (!window.orientation) return window.matchMedia("(orientation: portrait)").matches;
14
- return !(window.orientation === 90 || window.orientation === -90);
15
- };
16
- exports.isPotrait = isPotrait;
17
- const isLandscape = params => {
18
- return !isPotrait();
19
- };
20
- exports.isLandscape = isLandscape;
21
- const ua = params => {
22
- if (typeof navigator == "undefined") return null;
23
- if (typeof window == "undefined") return null;
24
- return navigator.userAgent || navigator.vendor || window.opera;
25
- };
26
- exports.ua = ua;
27
- const isFacebookWebview = params => {
28
- var ua = ua();
29
- if (ua) return ua.indexOf("FBAN") > -1 || ua.indexOf("FBAV") > -1;
30
- };
31
- exports.isFacebookWebview = isFacebookWebview;
32
- const isInAppWebview = params => {
33
- const rules = ["WebView", "(iPhone|iPod|iPad)(?!.*Safari/)", "Android.*(wv|.0.0.0)"];
34
- const regex = new RegExp("(".concat(rules.join("|"), ")"), "ig");
35
- if (ua()) return Boolean(ua().match(regex));
36
- return false;
37
- };
38
- exports.isInAppWebview = isInAppWebview;