diginext-utils 1.2.3 → 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,377 +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
-
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 sumArray(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;
@@ -1,24 +0,0 @@
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
- }
@@ -1,42 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
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;
@@ -1,55 +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
- // * @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";
package/dist/color.js DELETED
@@ -1,108 +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
-
8
- require("core-js/modules/es.regexp.to-string.js");
9
-
10
- require("core-js/modules/es.parse-int.js");
11
-
12
- require("core-js/modules/web.dom-collections.iterator.js");
13
-
14
- require("core-js/modules/es.regexp.exec.js");
15
-
16
- require("core-js/modules/es.string.split.js");
17
-
18
- require("core-js/modules/es.parse-float.js");
19
-
20
- const random = function random() {
21
- let hex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
22
- return (hex ? "#" : "") + Math.floor(Math.random() * 16777215).toString(16);
23
- }; // This function (pSBC) will take a HEX or RGB web color.
24
- // 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).
25
- // All without you even knowing what color format you are using.
26
- // Version 4.0 (pref: https://github.com/PimpTrizkit/PJs/wiki/12.-Shade,-Blend-and-Convert-a-Web-Color-(pSBC.js));
27
-
28
-
29
- exports.random = random;
30
-
31
- const pSBC = (p, c0, c1, l) => {
32
- let r,
33
- g,
34
- b,
35
- P,
36
- f,
37
- t,
38
- h,
39
- i = parseInt,
40
- m = Math.round,
41
- a = typeof c1 == "string";
42
- if (typeof p != "number" || p < -1 || p > 1 || typeof c0 != "string" || c0[0] != "r" && c0[0] != "#" || c1 && !a) return null;
43
-
44
- const pSBCr = d => {
45
- let n = d.length,
46
- x = {};
47
-
48
- if (n > 9) {
49
- [r, g, b, a] = d = d.split(","), n = d.length;
50
- if (n < 3 || n > 4) return null;
51
- 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;
52
- } else {
53
- if (n == 8 || n == 6 || n < 4) return null;
54
- if (n < 6) d = "#" + d[1] + d[1] + d[2] + d[2] + d[3] + d[3] + (n > 4 ? d[4] + d[4] : "");
55
- d = i(d.slice(1), 16);
56
- 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;
57
- }
58
-
59
- return x;
60
- };
61
-
62
- 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 ? {
63
- r: 0,
64
- g: 0,
65
- b: 0,
66
- a: -1
67
- } : {
68
- r: 255,
69
- g: 255,
70
- b: 255,
71
- a: -1
72
- }, p = P ? p * -1 : p, P = 1 - p;
73
- if (!f || !t) return null;
74
- 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);
75
- a = f.a, t = t.a, f = a >= 0 || t >= 0, a = f ? a < 0 ? t : t < 0 ? a : a * P + t * p : 0;
76
- 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);
77
- };
78
-
79
- exports.pSBC = pSBC;
80
-
81
- const hexToRgb = hex => {
82
- var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
83
- return result ? {
84
- r: parseInt(result[1], 16),
85
- g: parseInt(result[2], 16),
86
- b: parseInt(result[3], 16)
87
- } : null;
88
- };
89
-
90
- exports.hexToRgb = hexToRgb;
91
-
92
- const hexDarken = (hex, amount) => {
93
- return pSBC(-amount, hex);
94
- };
95
-
96
- exports.hexDarken = hexDarken;
97
-
98
- const hexLighten = (hex, amount) => {
99
- return pSBC(amount, hex);
100
- };
101
-
102
- exports.hexLighten = hexLighten;
103
-
104
- const RGBToHex = rgb => {
105
- return pSBC(0, rgb, "c", true);
106
- };
107
-
108
- exports.RGBToHex = RGBToHex;
@@ -1,16 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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;