diginext-utils 1.0.2 → 1.0.3
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/babel.config.json +21 -0
- package/dist/Camera.js +420 -0
- package/dist/Checker.js +34 -0
- package/dist/Color.js +102 -0
- package/dist/Device.js +67 -0
- package/dist/EventDispatcher.js +62 -0
- package/dist/FileUpload.js +73 -0
- package/dist/FileUtils.js +47 -0
- package/dist/Slug.js +384 -0
- package/dist/Timer.js +16 -0
- package/dist/UserLS.js +127 -0
- package/dist/Validation.js +46 -0
- package/dist/array/index.js +377 -0
- package/dist/backend/file/createDir.js +24 -0
- package/dist/backend/file/fileMove.js +42 -0
- package/dist/backend/file/findFilesByExt.js +55 -0
- package/dist/backend/zip/extractZip.js +55 -0
- package/dist/console/enableConsole.js +16 -0
- package/dist/console/index.js +20 -0
- package/dist/device/browser.js +52 -0
- package/dist/device/camera.js +238 -0
- package/dist/device/index.js +304 -0
- package/dist/math/index.js +209 -0
- package/dist/object/index.js +65 -0
- package/dist/permission/requestCamera.js +55 -0
- package/dist/permission/requestDeviceOrientationControl.js +36 -0
- package/dist/string/index.js +531 -0
- package/dist/string/url.js +128 -0
- package/package.json +13 -13
- package/src/backend/zip/extractZip.js +54 -54
- package/dist/main.js +0 -1611
- package/dist/main.js.map +0 -1
- package/dist/module.js +0 -1584
- package/dist/module.js.map +0 -1
- package/index.js +0 -13
- package/src/Browser.js +0 -297
- package/src/ReactUtils.js +0 -25
- package/src/ScrollPos.js +0 -31
- package/src/isMobileOrTablet.js +0 -28
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.randRound = exports.randInt = exports.randHalt = exports.randFloat = exports.rand = exports.radToDeg = exports.degToRad = void 0;
|
|
7
|
+
const DEG2RAD = Math.PI / 180;
|
|
8
|
+
const RAD2DEG = 180 / Math.PI;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {Number} number
|
|
12
|
+
* @return {Number}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const randRound = number => {
|
|
16
|
+
return Math.round(Math.random() * number);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {Number} number
|
|
21
|
+
* @return {Number}
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
exports.randRound = randRound;
|
|
26
|
+
|
|
27
|
+
const rand = number => {
|
|
28
|
+
return (Math.random() - Math.random()) * number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {Number} number
|
|
33
|
+
* @return {Number}
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.rand = rand;
|
|
38
|
+
|
|
39
|
+
const randHalt = number => {
|
|
40
|
+
var rand = Math.random() - Math.random();
|
|
41
|
+
var res;
|
|
42
|
+
|
|
43
|
+
if (rand > 0) {
|
|
44
|
+
res = rand * (number / 2) + number / 2;
|
|
45
|
+
} else {
|
|
46
|
+
res = rand * (number / 2) - number / 2;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return Math.abs(res);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {Number} low
|
|
54
|
+
* @param {Number} high
|
|
55
|
+
* @return {Number}
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.randHalt = randHalt;
|
|
60
|
+
|
|
61
|
+
const randInt = (low, high) => {
|
|
62
|
+
return low + Math.floor(Math.random() * (high - low + 1));
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param {Number} low
|
|
67
|
+
* @param {Number} high
|
|
68
|
+
* @return {Number}
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
exports.randInt = randInt;
|
|
73
|
+
|
|
74
|
+
const randFloat = (low, high) => {
|
|
75
|
+
return low + Math.random() * (high - low);
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
* @param {Number} degrees
|
|
80
|
+
* @return {Number}
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
exports.randFloat = randFloat;
|
|
85
|
+
|
|
86
|
+
const degToRad = degrees => {
|
|
87
|
+
return degrees * DEG2RAD;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {Number} degrees
|
|
92
|
+
* @return {Number}
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
exports.degToRad = degToRad;
|
|
97
|
+
|
|
98
|
+
const radToDeg = radians => {
|
|
99
|
+
return radians * RAD2DEG;
|
|
100
|
+
}; // const MathExtra = {
|
|
101
|
+
// isRotateLeft(a, b, c) {
|
|
102
|
+
// return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) > 0;
|
|
103
|
+
// },
|
|
104
|
+
// deg_between_points_360(cx, cy, ex, ey) {
|
|
105
|
+
// var theta = this.angleLine(cx, cy, ex, ey); // range (-180, 180]
|
|
106
|
+
// if (theta < 0) theta = 360 + theta; // range [0, 360)
|
|
107
|
+
// return theta;
|
|
108
|
+
// },
|
|
109
|
+
// deg_between_points(cx, cy, ex, ey) {
|
|
110
|
+
// var dy = ey - cy;
|
|
111
|
+
// var dx = ex - cx;
|
|
112
|
+
// var theta = Math.atan2(dy, dx); // range (-PI, PI]
|
|
113
|
+
// theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
|
|
114
|
+
// return theta;
|
|
115
|
+
// },
|
|
116
|
+
// angle_between_points(cx, cy, ex, ey) {
|
|
117
|
+
// var dy = ey - cy;
|
|
118
|
+
// var dx = ex - cx;
|
|
119
|
+
// var theta = Math.atan2(dy, dx); // range (-PI, PI]
|
|
120
|
+
// // theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
|
|
121
|
+
// return theta;
|
|
122
|
+
// },
|
|
123
|
+
// distance2Point(x1, y1, x2, y2) {
|
|
124
|
+
// var dist = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
|
|
125
|
+
// return dist;
|
|
126
|
+
// },
|
|
127
|
+
// clamp(value, min, max) {
|
|
128
|
+
// return Math.max(min, Math.min(max, value));
|
|
129
|
+
// },
|
|
130
|
+
// // compute euclidian modulo of m % n
|
|
131
|
+
// // https://en.wikipedia.org/wiki/Modulo_operation
|
|
132
|
+
// euclideanModulo(n, m) {
|
|
133
|
+
// return ((n % m) + m) % m;
|
|
134
|
+
// },
|
|
135
|
+
// // Linear mapping from range <a1, a2> to range <b1, b2>
|
|
136
|
+
// mapLinear(x, a1, a2, b1, b2) {
|
|
137
|
+
// return b1 + ((x - a1) * (b2 - b1)) / (a2 - a1);
|
|
138
|
+
// },
|
|
139
|
+
// // https://en.wikipedia.org/wiki/Linear_interpolation
|
|
140
|
+
// lerp(x, y, t) {
|
|
141
|
+
// return (1 - t) * x + t * y;
|
|
142
|
+
// },
|
|
143
|
+
// // http://en.wikipedia.org/wiki/Smoothstep
|
|
144
|
+
// smoothstep(x, min, max) {
|
|
145
|
+
// if (x <= min) return 0;
|
|
146
|
+
// if (x >= max) return 1;
|
|
147
|
+
// x = (x - min) / (max - min);
|
|
148
|
+
// return x * x * (3 - 2 * x);
|
|
149
|
+
// },
|
|
150
|
+
// smootherstep(x, min, max) {
|
|
151
|
+
// if (x <= min) return 0;
|
|
152
|
+
// if (x >= max) return 1;
|
|
153
|
+
// x = (x - min) / (max - min);
|
|
154
|
+
// return x * x * x * (x * (x * 6 - 15) + 10);
|
|
155
|
+
// },
|
|
156
|
+
// // Random integer from <low, high> interval
|
|
157
|
+
// // Random float from <-range/2, range/2> interval
|
|
158
|
+
// randFloatSpread(range) {
|
|
159
|
+
// return range * (0.5 - Math.random());
|
|
160
|
+
// },
|
|
161
|
+
// rotationDegToRad(rotation) {
|
|
162
|
+
// return {
|
|
163
|
+
// x: this.degToRad(rotation.x),
|
|
164
|
+
// y: this.degToRad(rotation.y),
|
|
165
|
+
// z: this.degToRad(rotation.z),
|
|
166
|
+
// };
|
|
167
|
+
// },
|
|
168
|
+
// radToDeg(radians) {
|
|
169
|
+
// return radians * RAD2DEG;
|
|
170
|
+
// },
|
|
171
|
+
// isPowerOfTwo(value) {
|
|
172
|
+
// return (value & (value - 1)) === 0 && value !== 0;
|
|
173
|
+
// },
|
|
174
|
+
// nearestPowerOfTwo(value) {
|
|
175
|
+
// return Math.pow(2, Math.round(Math.log(value) / Math.LN2));
|
|
176
|
+
// },
|
|
177
|
+
// nextPowerOfTwo(value) {
|
|
178
|
+
// value--;
|
|
179
|
+
// value |= value >> 1;
|
|
180
|
+
// value |= value >> 2;
|
|
181
|
+
// value |= value >> 4;
|
|
182
|
+
// value |= value >> 8;
|
|
183
|
+
// value |= value >> 16;
|
|
184
|
+
// value++;
|
|
185
|
+
// return value;
|
|
186
|
+
// },
|
|
187
|
+
// circleByPercentRadius(percent, radius) {
|
|
188
|
+
// const theta = ((percent * 360 - 90) * Math.PI) / 180;
|
|
189
|
+
// const x = radius * Math.cos(theta);
|
|
190
|
+
// const y = -radius * Math.sin(theta);
|
|
191
|
+
// return { x, y };
|
|
192
|
+
// },
|
|
193
|
+
// /**
|
|
194
|
+
// *
|
|
195
|
+
// * @param {Array} array
|
|
196
|
+
// */
|
|
197
|
+
// arrayToVector(array = [0, 0, 0]) {
|
|
198
|
+
// const keys = ['x', 'y', 'z', 'w'];
|
|
199
|
+
// const result = {};
|
|
200
|
+
// array.map((item, index) => {
|
|
201
|
+
// result[keys[index]] = item;
|
|
202
|
+
// });
|
|
203
|
+
// return result;
|
|
204
|
+
// },
|
|
205
|
+
// };
|
|
206
|
+
// export default MathExtra;
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
exports.radToDeg = radToDeg;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.promise.js");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.toInt = exports.toFloat = exports.toBool = exports.toArray = exports.isNull = void 0;
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.parse-int.js");
|
|
13
|
+
|
|
14
|
+
require("core-js/modules/es.parse-float.js");
|
|
15
|
+
|
|
16
|
+
const isNull = object => {
|
|
17
|
+
if (typeof object == "undefined") return true;
|
|
18
|
+
if (object == "") return true;
|
|
19
|
+
if (Array.isArray(object)) return object.length == 0;
|
|
20
|
+
return object == null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.isNull = isNull;
|
|
24
|
+
|
|
25
|
+
const toBool = object => {
|
|
26
|
+
if (isNull(object)) return false;
|
|
27
|
+
object = object.toString();
|
|
28
|
+
return object === "true" || object == "1";
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.toBool = toBool;
|
|
32
|
+
|
|
33
|
+
const toInt = object => {
|
|
34
|
+
if (isNull(object)) return 0;
|
|
35
|
+
object = object.toString();
|
|
36
|
+
return parseInt(object, 10);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.toInt = toInt;
|
|
40
|
+
|
|
41
|
+
const toFloat = object => {
|
|
42
|
+
if (isNull(object)) return 0;
|
|
43
|
+
object = object.toString();
|
|
44
|
+
return parseFloat(object);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Convert value in object to array
|
|
48
|
+
* @param {object} obj
|
|
49
|
+
* @returns {Array}
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
exports.toFloat = toFloat;
|
|
54
|
+
|
|
55
|
+
const toArray = obj => {
|
|
56
|
+
const array = [];
|
|
57
|
+
|
|
58
|
+
for (const key in obj) {
|
|
59
|
+
array.push(obj[key]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return array;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.toArray = toArray;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.promise.js");
|
|
9
|
+
|
|
10
|
+
const requestCamera = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
audio = true,
|
|
13
|
+
video = true
|
|
14
|
+
} = _ref;
|
|
15
|
+
if (typeof window == "undefined") return false;
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
// Older browsers might not implement mediaDevices at all, so we set an empty object first
|
|
18
|
+
if (navigator.mediaDevices === undefined) {
|
|
19
|
+
navigator.mediaDevices = {};
|
|
20
|
+
} // Some browsers partially implement mediaDevices. We can't just assign an object
|
|
21
|
+
// with getUserMedia as it would overwrite existing properties.
|
|
22
|
+
// Here, we will just add the getUserMedia property if it's missing.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (navigator.mediaDevices.getUserMedia === undefined) {
|
|
26
|
+
navigator.mediaDevices.getUserMedia = function (constraints) {
|
|
27
|
+
// First get ahold of the legacy getUserMedia, if present
|
|
28
|
+
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia; // Some browsers just don't implement it - return a rejected promise with an error
|
|
29
|
+
// to keep a consistent interface
|
|
30
|
+
|
|
31
|
+
if (!getUserMedia) {
|
|
32
|
+
return Promise.reject(new Error("getUserMedia is not implemented in this browser"));
|
|
33
|
+
} // Otherwise, wrap the call to the old navigator.getUserMedia with a Promise
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
return new Promise(function (resolve, reject) {
|
|
37
|
+
getUserMedia.call(navigator, constraints, resolve, reject);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
navigator.mediaDevices.getUserMedia({
|
|
43
|
+
audio,
|
|
44
|
+
video
|
|
45
|
+
}).then(function (stream) {
|
|
46
|
+
resolve(true);
|
|
47
|
+
}).catch(function (err) {
|
|
48
|
+
console.log(err.name + ": " + err.message);
|
|
49
|
+
resolve(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var _default = requestCamera;
|
|
55
|
+
exports.default = _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.promise.js");
|
|
9
|
+
|
|
10
|
+
var _device = require("../device");
|
|
11
|
+
|
|
12
|
+
const requestDeviceOrientationControl = () => {
|
|
13
|
+
if (typeof window == "undefined") return false;
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
if ((0, _device.isAndroid)()) resolve(true);
|
|
16
|
+
|
|
17
|
+
if (typeof DeviceMotionEvent != "undefined" && DeviceMotionEvent.requestPermission) {
|
|
18
|
+
// (optional) Do something before API request prompt.
|
|
19
|
+
DeviceOrientationEvent.requestPermission().then(response => {
|
|
20
|
+
// (optional) Do something after API prompt dismissed.
|
|
21
|
+
if (response == "granted") {
|
|
22
|
+
resolve(true); // resolve({ status: true })
|
|
23
|
+
} else {
|
|
24
|
+
resolve(false); // resolve({ status: false, reason: "DeviceMotionEvent is not support" })
|
|
25
|
+
}
|
|
26
|
+
}).catch(response => {
|
|
27
|
+
resolve(false); // resolve({ status: false, reason: response })
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
resolve(false); // resolve({ status: false, reason: "DeviceMotionEvent is not defined" })
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var _default = requestDeviceOrientationControl;
|
|
36
|
+
exports.default = _default;
|