diginext-utils 0.0.1 → 0.1.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/README.md CHANGED
@@ -0,0 +1,3 @@
1
+ ## Support
2
+
3
+ Liên hệ [TOP GROUP Developers](mailto:dev@wearetopgroup.com) nếu cần hỗ trợ.
package/index.js CHANGED
@@ -1 +1,12 @@
1
+ export * from "./src/array";
2
+ export * from "./src/device";
3
+ export * from "./src/device/browser";
4
+ export * from "./src/device/camera";
5
+ export * from "./src/math";
1
6
  export * from "./src/object";
7
+ export * from "./src/string";
8
+ export * from "./src/string/url";
9
+ import requestCamera from "./src/permission/requestCamera";
10
+ import requestDeviceOrientationControl from "./src/permission/requestDeviceOrientationControl";
11
+
12
+ export { requestCamera, requestDeviceOrientationControl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginext-utils",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "main": "index.js",
5
5
  "author": {
6
6
  "name": "TOP GROUP (a.k.a Digitop)",
@@ -1,7 +1,8 @@
1
1
  export const isNull = (object) => {
2
2
  if (typeof object == "undefined") return true;
3
-
3
+ if (object == "") return true;
4
4
  if (Array.isArray(object)) return object.length == 0;
5
+
5
6
  return object == null;
6
7
  };
7
8
 
@@ -7,6 +7,12 @@ export const numeric = "0123456789";
7
7
  export const punctuation = "!@#$%^&*()_+~|}{[];?><,./-=";
8
8
  export const allCharacter = `đĐaáàảãạăắằẳẵặâấầẩẫậeéèẻẽẹêếềểễệoóòỏõọôốồổỗộơớờởỡợiíìỉĩịuúùủũụưứừửữựyýỳỷỹỵAÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬEÉÈẺẼẸÊẾỀỂỄỆOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢIÍÌỈĨỊUÚÙỦŨỤƯỨỪỬỮỰYÝỲ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}`;
9
9
 
10
+ //prettier-ignore
11
+ const char_map={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",Æ:"AE",Ç:"C",È:"E",É:"E",Ê:"E",Ë:"E",Ì:"I",Í:"I",Î:"I",Ï:"I",Ð:"D",Ñ:"N",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ő:"O",Ø:"O",Ù:"U",Ú:"U",Û:"U",Ü:"U",Ű:"U",Ý:"Y",Þ:"TH",ß:"ss",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",æ:"ae",ç:"c",è:"e",é:"e",ê:"e",ë:"e",ì:"i",í:"i",î:"i",ï:"i",ð:"d",ñ:"n",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ő:"o",ø:"o",ù:"u",ú:"u",û:"u",ü:"u",ű:"u",ý:"y",þ:"th",ÿ:"y","©":"(c)",Α:"A",Β:"B",Γ:"G",Δ:"D",Ε:"E",Ζ:"Z",Η:"H",Θ:"8",Ι:"I",Κ:"K",Λ:"L",Μ:"M",Ν:"N",Ξ:"3",Ο:"O",Π:"P",Ρ:"R",Σ:"S",Τ:"T",Υ:"Y",Φ:"F",Χ:"X",Ψ:"PS",Ω:"W",Ά:"A",Έ:"E",Ί:"I",Ό:"O",Ύ:"Y",Ή:"H",Ώ:"W",Ϊ:"I",Ϋ:"Y",α:"a",β:"b",γ:"g",δ:"d",ε:"e",ζ:"z",η:"h",θ:"8",ι:"i",κ:"k",λ:"l",μ:"m",ν:"n",ξ:"3",ο:"o",π:"p",ρ:"r",σ:"s",τ:"t",υ:"y",φ:"f",χ:"x",ψ:"ps",ω:"w",ά:"a",έ:"e",ί:"i",ό:"o",ύ:"y",ή:"h",ώ:"w",ς:"s",ϊ:"i",ΰ:"y",ϋ:"y",ΐ:"i",Ş:"S",İ:"I",Ç:"C",Ü:"U",Ö:"O",Ğ:"G",ş:"s",ı:"i",ç:"c",ü:"u",ö:"o",ğ:"g",А:"A",Б:"B",В:"V",Г:"G",Д:"D",Е:"E",Ё:"Yo",Ж:"Zh",З:"Z",И:"I",Й:"J",К:"K",Л:"L",М:"M",Н:"N",О:"O",П:"P",Р:"R",С:"S",Т:"T",У:"U",Ф:"F",Х:"H",Ц:"C",Ч:"Ch",Ш:"Sh",Щ:"Sh",Ъ:"",Ы:"Y",Ь:"",Э:"E",Ю:"Yu",Я:"Ya",а:"a",б:"b",в:"v",г:"g",д:"d",е:"e",ё:"yo",ж:"zh",з:"z",и:"i",й:"j",к:"k",л:"l",м:"m",н:"n",о:"o",п:"p",р:"r",с:"s",т:"t",у:"u",ф:"f",х:"h",ц:"c",ч:"ch",ш:"sh",щ:"sh",ъ:"",ы:"y",ь:"",э:"e",ю:"yu",я:"ya",Є:"Ye",І:"I",Ї:"Yi",Ґ:"G",є:"ye",і:"i",ї:"yi",ґ:"g",Č:"C",Ď:"D",Ě:"E",Ň:"N",Ř:"R",Š:"S",Ť:"T",Ů:"U",Ž:"Z",č:"c",ď:"d",ě:"e",ň:"n",ř:"r",š:"s",ť:"t",ů:"u",ž:"z",Ą:"A",Ć:"C",Ę:"e",Ł:"L",Ń:"N",Ó:"o",Ś:"S",Ź:"Z",Ż:"Z",ą:"a",ć:"c",ę:"e",ł:"l",ń:"n",ó:"o",ś:"s",ź:"z",ż:"z",Ā:"A",Č:"C",Ē:"E",Ģ:"G",Ī:"i",Ķ:"k",Ļ:"L",Ņ:"N",Š:"S",Ū:"u",Ž:"Z",ā:"a",č:"c",ē:"e",ģ:"g",ī:"i",ķ:"k",ļ:"l",ņ:"n",š:"s",ū:"u",ž:"z",};
12
+
13
+ //prettier-ignore
14
+ const _lut = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff' ];
15
+
10
16
  /**
11
17
  * allCharacter = `đĐaáàảãạăắằẳẵặâấầẩẫậeéèẻẽẹêếềểễệoóòỏõọôốồổỗộơớờởỡợiíìỉĩịuúùủũụưứừửữựyýỳỷỹỵAÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬEÉÈẺẼẸÊẾỀỂỄỆOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢIÍÌỈĨỊUÚÙỦŨỤƯỨỪỬỮỰYÝỲ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}`;
12
18
  * @param {number} length
@@ -132,9 +138,7 @@ export const capitalizeName = (str) => {
132
138
  * @return {string}
133
139
  */
134
140
  export const clearUnicodeCharacters = (s, opt = {}) => {
135
- // log(`clearUnicodeCharacters >>> `, s);
136
- s = s.toString();
137
- // opt = Object(opt);
141
+ s = makeString(s);
138
142
 
139
143
  var defaults = {
140
144
  delimiter: " ",
@@ -151,9 +155,6 @@ export const clearUnicodeCharacters = (s, opt = {}) => {
151
155
  }
152
156
  }
153
157
 
154
- //prettier-ignore
155
- const char_map={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",Æ:"AE",Ç:"C",È:"E",É:"E",Ê:"E",Ë:"E",Ì:"I",Í:"I",Î:"I",Ï:"I",Ð:"D",Ñ:"N",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ő:"O",Ø:"O",Ù:"U",Ú:"U",Û:"U",Ü:"U",Ű:"U",Ý:"Y",Þ:"TH",ß:"ss",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",æ:"ae",ç:"c",è:"e",é:"e",ê:"e",ë:"e",ì:"i",í:"i",î:"i",ï:"i",ð:"d",ñ:"n",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ő:"o",ø:"o",ù:"u",ú:"u",û:"u",ü:"u",ű:"u",ý:"y",þ:"th",ÿ:"y","©":"(c)",Α:"A",Β:"B",Γ:"G",Δ:"D",Ε:"E",Ζ:"Z",Η:"H",Θ:"8",Ι:"I",Κ:"K",Λ:"L",Μ:"M",Ν:"N",Ξ:"3",Ο:"O",Π:"P",Ρ:"R",Σ:"S",Τ:"T",Υ:"Y",Φ:"F",Χ:"X",Ψ:"PS",Ω:"W",Ά:"A",Έ:"E",Ί:"I",Ό:"O",Ύ:"Y",Ή:"H",Ώ:"W",Ϊ:"I",Ϋ:"Y",α:"a",β:"b",γ:"g",δ:"d",ε:"e",ζ:"z",η:"h",θ:"8",ι:"i",κ:"k",λ:"l",μ:"m",ν:"n",ξ:"3",ο:"o",π:"p",ρ:"r",σ:"s",τ:"t",υ:"y",φ:"f",χ:"x",ψ:"ps",ω:"w",ά:"a",έ:"e",ί:"i",ό:"o",ύ:"y",ή:"h",ώ:"w",ς:"s",ϊ:"i",ΰ:"y",ϋ:"y",ΐ:"i",Ş:"S",İ:"I",Ç:"C",Ü:"U",Ö:"O",Ğ:"G",ş:"s",ı:"i",ç:"c",ü:"u",ö:"o",ğ:"g",А:"A",Б:"B",В:"V",Г:"G",Д:"D",Е:"E",Ё:"Yo",Ж:"Zh",З:"Z",И:"I",Й:"J",К:"K",Л:"L",М:"M",Н:"N",О:"O",П:"P",Р:"R",С:"S",Т:"T",У:"U",Ф:"F",Х:"H",Ц:"C",Ч:"Ch",Ш:"Sh",Щ:"Sh",Ъ:"",Ы:"Y",Ь:"",Э:"E",Ю:"Yu",Я:"Ya",а:"a",б:"b",в:"v",г:"g",д:"d",е:"e",ё:"yo",ж:"zh",з:"z",и:"i",й:"j",к:"k",л:"l",м:"m",н:"n",о:"o",п:"p",р:"r",с:"s",т:"t",у:"u",ф:"f",х:"h",ц:"c",ч:"ch",ш:"sh",щ:"sh",ъ:"",ы:"y",ь:"",э:"e",ю:"yu",я:"ya",Є:"Ye",І:"I",Ї:"Yi",Ґ:"G",є:"ye",і:"i",ї:"yi",ґ:"g",Č:"C",Ď:"D",Ě:"E",Ň:"N",Ř:"R",Š:"S",Ť:"T",Ů:"U",Ž:"Z",č:"c",ď:"d",ě:"e",ň:"n",ř:"r",š:"s",ť:"t",ů:"u",ž:"z",Ą:"A",Ć:"C",Ę:"e",Ł:"L",Ń:"N",Ó:"o",Ś:"S",Ź:"Z",Ż:"Z",ą:"a",ć:"c",ę:"e",ł:"l",ń:"n",ó:"o",ś:"s",ź:"z",ż:"z",Ā:"A",Č:"C",Ē:"E",Ģ:"G",Ī:"i",Ķ:"k",Ļ:"L",Ņ:"N",Š:"S",Ū:"u",Ž:"Z",ā:"a",č:"c",ē:"e",ģ:"g",ī:"i",ķ:"k",ļ:"l",ņ:"n",š:"s",ū:"u",ž:"z",};
156
-
157
158
  // Vietnamese
158
159
  s = s.replace(/á|à|ả|ạ|ã|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/gi, "a");
159
160
  s = s.replace(/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/gi, "e");
@@ -192,3 +193,36 @@ export const clearUnicodeCharacters = (s, opt = {}) => {
192
193
 
193
194
  return opt.lowercase ? s.toLowerCase() : s;
194
195
  };
196
+
197
+ export function generateUUID() {
198
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
199
+
200
+ const d0 = (Math.random() * 0xffffffff) | 0;
201
+ const d1 = (Math.random() * 0xffffffff) | 0;
202
+ const d2 = (Math.random() * 0xffffffff) | 0;
203
+ const d3 = (Math.random() * 0xffffffff) | 0;
204
+ const uuid =
205
+ _lut[d0 & 0xff] +
206
+ _lut[(d0 >> 8) & 0xff] +
207
+ _lut[(d0 >> 16) & 0xff] +
208
+ _lut[(d0 >> 24) & 0xff] +
209
+ "-" +
210
+ _lut[d1 & 0xff] +
211
+ _lut[(d1 >> 8) & 0xff] +
212
+ "-" +
213
+ _lut[((d1 >> 16) & 0x0f) | 0x40] +
214
+ _lut[(d1 >> 24) & 0xff] +
215
+ "-" +
216
+ _lut[(d2 & 0x3f) | 0x80] +
217
+ _lut[(d2 >> 8) & 0xff] +
218
+ "-" +
219
+ _lut[(d2 >> 16) & 0xff] +
220
+ _lut[(d2 >> 24) & 0xff] +
221
+ _lut[d3 & 0xff] +
222
+ _lut[(d3 >> 8) & 0xff] +
223
+ _lut[(d3 >> 16) & 0xff] +
224
+ _lut[(d3 >> 24) & 0xff];
225
+
226
+ // .toLowerCase() here flattens concatenated strings to save heap memory space.
227
+ return uuid.toLowerCase();
228
+ }
@@ -0,0 +1,93 @@
1
+ import { isNull } from "../object";
2
+
3
+ var urlRegex = /(https?:\/\/[^\s]+)/g;
4
+
5
+ export const getUrlParams = (parameter, staticURL, decode) => {
6
+ if (typeof window == "undefined") return "";
7
+
8
+ staticURL = staticURL == undefined ? window.location : staticURL;
9
+ var currLocation = staticURL.length ? staticURL : window.location.search;
10
+
11
+ if (currLocation.split("?").length < 2) return "";
12
+
13
+ var parArr = currLocation.split("?")[1].split("&"),
14
+ returnBool = true;
15
+
16
+ for (var i = 0; i < parArr.length; i++) {
17
+ var parr = parArr[i].split("=");
18
+ if (parr[0] == parameter) {
19
+ return decode ? decodeURIComponent(parr[1]) : parr[1];
20
+ returnBool = true;
21
+ } else {
22
+ returnBool = false;
23
+ }
24
+ }
25
+
26
+ if (!returnBool) return false;
27
+ };
28
+
29
+ /**
30
+ *
31
+ * @return {boolean}
32
+ */
33
+ export const isLink = (str) => {
34
+ return urlRegex.test(str);
35
+ };
36
+
37
+ // /**
38
+ // *
39
+ // * @return {JSX.Element}
40
+ // */
41
+ // export const strToJsxLink = (str, altText) => {
42
+ // return isLink(str) ? <a href={src}>{altText || src}</a> : str;
43
+ // };
44
+
45
+ /**
46
+ *
47
+ * @param {string} url
48
+ * @return {string}
49
+ */
50
+ export const getFileNameWithoutExtension = (url) => {
51
+ url = decodeURIComponent(url);
52
+ if (url) {
53
+ const m = url.toString().match(/.*\/(.+?)\./);
54
+ if (m && m.length > 1) {
55
+ return m[1];
56
+ }
57
+
58
+ if (!isNull(url)) {
59
+ return url.split(".").shift();
60
+ }
61
+ }
62
+ return "";
63
+ };
64
+
65
+ /**
66
+ *
67
+ * @param {string} url
68
+ * @return {string}
69
+ */
70
+ export const getFileNameWithExtension = (url) => {
71
+ url = decodeURIComponent(url);
72
+ if (url) {
73
+ const m = url.toString().match(/.*\/(.*)$/);
74
+
75
+ if (m && m.length > 1) {
76
+ return m[1].split("/").pop().split("?")[0];
77
+ }
78
+
79
+ if (!isNull(url)) {
80
+ return url;
81
+ }
82
+ }
83
+ return "";
84
+ };
85
+
86
+ /**
87
+ *
88
+ * @param {string} url
89
+ * @return {string}
90
+ */
91
+ export const getFileExtension = (url) => {
92
+ return getFileNameWithExtension(url).split(".").pop();
93
+ };
package/src/ArrayExtra.js DELETED
@@ -1,299 +0,0 @@
1
- import MathExtra from "./MathExtra";
2
-
3
- const ArrayExtra = {
4
- /**
5
- *
6
- * @param {Array} array
7
- * @param {string} key
8
- * @returns {Number}
9
- */
10
- sum(array, key) {
11
- if (!array) {
12
- console.warn("ARRAY NOT EXITED !");
13
- return 0;
14
- }
15
- if (key) return array.reduce((c, v) => c + v[key], 0);
16
- else return array.reduce((c, v) => c + v, 0);
17
- },
18
-
19
- /**
20
- *
21
- * @param {Array} array
22
- * @param {string} key
23
- * @returns {Number}
24
- */
25
- average(array, key) {
26
- if (!array) {
27
- console.warn("ARRAY NOT EXITED !");
28
- return 0;
29
- }
30
- return this.sum(array, key) / array.length || 0;
31
- },
32
-
33
- /**
34
- *
35
- * @param {Array} array
36
- * @param {string} key
37
- * @returns {Number}
38
- */
39
- min(array, key) {
40
- if (!array) {
41
- console.warn("ARRAY NOT EXITED !");
42
- return 0;
43
- }
44
- if (array.length > 0) {
45
- if (key) return array.reduce((c, v) => (c < v[key] ? c : v[key]));
46
- else return array.reduce((c, v) => (c < v ? c : v));
47
- }
48
- return 0;
49
- },
50
-
51
- /**
52
- *
53
- * @param {Array} array
54
- * @param {string} key
55
- * @returns {Number}
56
- */
57
- max(array, key) {
58
- if (!array) {
59
- console.warn("ARRAY NOT EXITED !");
60
- return 0;
61
- }
62
- if (array.length > 0) {
63
- if (key) return array.reduce((c, v) => (c > v[key] ? c : v[key]));
64
- else return array.reduce((c, v) => (c > v ? c : v));
65
- }
66
- return 0;
67
- },
68
-
69
- /**
70
- *
71
- * @param {Array} array
72
- * @param {string} key
73
- * @returns {Array}
74
- */
75
- sortElementByString(array, key) {
76
- if (!Array.isArray(array)) return [];
77
- if (key)
78
- return array.sort((x, y) => {
79
- var a = x[key].toUpperCase(),
80
- b = y[key].toUpperCase();
81
- return a == b ? 0 : a > b ? 1 : -1;
82
- });
83
- console.log("NO KEY");
84
- },
85
-
86
- /**
87
- *
88
- * @param {Array} array
89
- * @param {string} key
90
- * @returns {Array}
91
- */
92
- sortElementByNumber(array, key) {
93
- if (!Array.isArray(array)) return [];
94
- return array.sort((a, b) => {
95
- return a[key] - b[key];
96
- });
97
- },
98
-
99
- /**
100
- *
101
- * @param {Array} array
102
- * @returns {any}
103
- */
104
- first(array) {
105
- if (array) if (array.length || array.length > 0) return array[0];
106
- return null;
107
- },
108
-
109
- /**
110
- *
111
- * @param {Array} array
112
- * @returns {any}
113
- */
114
- last(array) {
115
- if (array) if (array.length || array.length > 0) return array[array.length - 1];
116
- return null;
117
- },
118
-
119
- /**
120
- *
121
- * @param {Array} array
122
- * @returns {any}
123
- */
124
- randomIndex(array) {
125
- if (array) return MathExtra.randInt(0, array.length - 1);
126
- return -1;
127
- },
128
-
129
- /**
130
- *
131
- * @param {Array} array
132
- * @returns {any}
133
- */
134
- randomElement(array) {
135
- if (array) return array[this.randomIndex(array)];
136
- return null;
137
- },
138
-
139
- /**
140
- *
141
- * @param {Array} list1
142
- * @param {Array} list2
143
- * @param {string} key
144
- * @returns {Array}
145
- */
146
- filterTwoArrayByKey(list1, list2, key) {
147
- if (key) {
148
- if (list1 && list2) {
149
- return list1.filter((item1) => {
150
- return !list2.find((item2) => {
151
- return item1[key] == item2[key];
152
- });
153
- });
154
- }
155
- } else {
156
- return list1.filter((item1) => {
157
- return !list2.find((item2) => {
158
- return item1 == item2;
159
- });
160
- });
161
- }
162
- return [];
163
- },
164
-
165
- /**
166
- *
167
- * @param {Array} target
168
- * @param {Array} toMatch
169
- * @returns {Boolean}
170
- */
171
- allMatchInArray(target, toMatch) {
172
- const found = toMatch.every((item) => {
173
- return target.includes(item);
174
- });
175
- return found;
176
- },
177
-
178
- /**
179
- *
180
- * @param {any} item
181
- * @param {Array} array
182
- * @returns {Array}
183
- */
184
- removeItem(item, array) {
185
- const index = array.indexOf(item);
186
- if (index == -1) {
187
- console.warn("[ArrayExtra.removeItem] Item not found.");
188
- return array;
189
- }
190
- array.splice(index, 1);
191
- return array;
192
- },
193
-
194
- /**
195
- *
196
- * @param {string} key
197
- * @param {any} value
198
- * @param {Array} array
199
- * @returns {Array}
200
- */
201
- removeItemByKey(key, value, array) {
202
- const foundIndex = array.findIndex((item) => {
203
- return item[key] == value;
204
- });
205
-
206
- if (foundIndex < 0) {
207
- console.warn("[ArrayExtra.removeItemByKey] Item not found.", key, value);
208
- return array;
209
- }
210
- array.splice(foundIndex, 1);
211
- return array;
212
- },
213
-
214
- /**
215
- * Get an array with shuffle element
216
- * @param {Array} array
217
- * @param {Number} n
218
- * @returns {Array}
219
- */
220
- getRandom(array, n) {
221
- var result = new Array(n),
222
- len = array.length,
223
- taken = new Array(len);
224
- if (n > len) throw new RangeError("getRandom: more elements taken than available");
225
- while (n--) {
226
- var x = Math.floor(Math.random() * len);
227
- result[n] = array[x in taken ? taken[x] : x];
228
- taken[x] = --len in taken ? taken[len] : len;
229
- }
230
- return result;
231
- },
232
-
233
- /**
234
- * Get an array with shuffle element
235
- * @param {Array} array
236
- * @param {Number} n
237
- * @returns {Array}
238
- */
239
- getHalfRandom(array, n) {
240
- var n = Math.ceil(array.length / 2);
241
- return array.getRandom(n);
242
- },
243
-
244
- /**
245
- * @param {Array} array
246
- * @returns {Array}
247
- */
248
- shuffle(array) {
249
- var i = array.length,
250
- j,
251
- temp;
252
- if (i == 0) return array;
253
- while (--i) {
254
- j = Math.floor(Math.random() * (i + 1));
255
- temp = array[i];
256
- array[i] = array[j];
257
- array[j] = temp;
258
- }
259
- return array;
260
- },
261
-
262
- /**
263
- *
264
- * @param {Array} array
265
- * @param {Number} oldIndex
266
- * @param {Number} newIndex
267
- * @returns {Array}
268
- */
269
- moveIndex(array, oldIndex, newIndex) {
270
- // return Math.floor(Math.random() * array.length);
271
- if (newIndex >= array.length) {
272
- var k = newIndex - array.length + 1;
273
- while (k--) {
274
- array.push(undefined);
275
- }
276
- }
277
- array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
278
- return array; // for testing
279
- },
280
-
281
- moveArray(array, oldIndex, newIndex) {
282
- while (oldIndex < 0) {
283
- oldIndex += array.length;
284
- }
285
- while (newIndex < 0) {
286
- newIndex += array.length;
287
- }
288
- if (newIndex >= array.length) {
289
- var k = newIndex - array.length;
290
- while (k-- + 1) {
291
- array.push(999);
292
- }
293
- }
294
- array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
295
- return array;
296
- },
297
- };
298
-
299
- export default ArrayExtra;
package/src/MathExtra.js DELETED
@@ -1,172 +0,0 @@
1
- var DEG2RAD = Math.PI / 180;
2
- var RAD2DEG = 180 / Math.PI;
3
-
4
- export default {
5
- isRotateLeft(a, b, c) {
6
- return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) > 0;
7
- },
8
-
9
- deg_between_points_360(cx, cy, ex, ey) {
10
- var theta = this.angleLine(cx, cy, ex, ey); // range (-180, 180]
11
- if (theta < 0) theta = 360 + theta; // range [0, 360)
12
- return theta;
13
- },
14
-
15
- deg_between_points(cx, cy, ex, ey) {
16
- var dy = ey - cy;
17
- var dx = ex - cx;
18
- var theta = Math.atan2(dy, dx); // range (-PI, PI]
19
- theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
20
- return theta;
21
- },
22
-
23
- angle_between_points(cx, cy, ex, ey) {
24
- var dy = ey - cy;
25
- var dx = ex - cx;
26
- var theta = Math.atan2(dy, dx); // range (-PI, PI]
27
- // theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
28
- return theta;
29
- },
30
-
31
- distance2Point(x1, y1, x2, y2) {
32
- var dist = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
33
- return dist;
34
- },
35
-
36
- randRound: function (number) {
37
- return Math.round(Math.random() * number);
38
- },
39
-
40
- rand(number) {
41
- return (Math.random() - Math.random()) * number;
42
- },
43
-
44
- randHalt(number) {
45
- var rand = Math.random() - Math.random();
46
- var res;
47
- if (rand > 0) {
48
- res = rand * (number / 2) + number / 2;
49
- } else {
50
- res = rand * (number / 2) - number / 2;
51
- }
52
- return Math.abs(res);
53
- },
54
-
55
- clamp(value, min, max) {
56
- return Math.max(min, Math.min(max, value));
57
- },
58
-
59
- // compute euclidian modulo of m % n
60
- // https://en.wikipedia.org/wiki/Modulo_operation
61
-
62
- euclideanModulo(n, m) {
63
- return ((n % m) + m) % m;
64
- },
65
-
66
- // Linear mapping from range <a1, a2> to range <b1, b2>
67
-
68
- mapLinear(x, a1, a2, b1, b2) {
69
- return b1 + ((x - a1) * (b2 - b1)) / (a2 - a1);
70
- },
71
-
72
- // https://en.wikipedia.org/wiki/Linear_interpolation
73
-
74
- lerp(x, y, t) {
75
- return (1 - t) * x + t * y;
76
- },
77
-
78
- // http://en.wikipedia.org/wiki/Smoothstep
79
-
80
- smoothstep(x, min, max) {
81
- if (x <= min) return 0;
82
- if (x >= max) return 1;
83
-
84
- x = (x - min) / (max - min);
85
-
86
- return x * x * (3 - 2 * x);
87
- },
88
-
89
- smootherstep(x, min, max) {
90
- if (x <= min) return 0;
91
- if (x >= max) return 1;
92
-
93
- x = (x - min) / (max - min);
94
-
95
- return x * x * x * (x * (x * 6 - 15) + 10);
96
- },
97
-
98
- // Random integer from <low, high> interval
99
-
100
- randInt(low, high) {
101
- return low + Math.floor(Math.random() * (high - low + 1));
102
- },
103
-
104
- // Random float from <low, high> interval
105
-
106
- randFloat(low, high) {
107
- return low + Math.random() * (high - low);
108
- },
109
-
110
- // Random float from <-range/2, range/2> interval
111
-
112
- randFloatSpread(range) {
113
- return range * (0.5 - Math.random());
114
- },
115
-
116
- rotationDegToRad(rotation) {
117
- return {
118
- x: this.degToRad(rotation.x),
119
- y: this.degToRad(rotation.y),
120
- z: this.degToRad(rotation.z),
121
- };
122
- },
123
-
124
- degToRad(degrees) {
125
- return degrees * DEG2RAD;
126
- },
127
-
128
- radToDeg(radians) {
129
- return radians * RAD2DEG;
130
- },
131
-
132
- isPowerOfTwo(value) {
133
- return (value & (value - 1)) === 0 && value !== 0;
134
- },
135
-
136
- nearestPowerOfTwo(value) {
137
- return Math.pow(2, Math.round(Math.log(value) / Math.LN2));
138
- },
139
-
140
- nextPowerOfTwo(value) {
141
- value--;
142
- value |= value >> 1;
143
- value |= value >> 2;
144
- value |= value >> 4;
145
- value |= value >> 8;
146
- value |= value >> 16;
147
- value++;
148
-
149
- return value;
150
- },
151
-
152
- circleByPercentRadius(percent, radius) {
153
- const theta = ((percent * 360 - 90) * Math.PI) / 180;
154
-
155
- const x = radius * Math.cos(theta);
156
- const y = -radius * Math.sin(theta);
157
- return { x, y };
158
- },
159
-
160
- /**
161
- *
162
- * @param {Array} array
163
- */
164
- arrayToVector(array = [0, 0, 0]) {
165
- const keys = ["x", "y", "z", "w"];
166
- const result = {};
167
- array.map((item, index) => {
168
- result[keys[index]] = item;
169
- });
170
- return result;
171
- },
172
- };
package/src/OS.js DELETED
@@ -1,203 +0,0 @@
1
- export default (options) => {
2
- const isIos = () => {
3
- if (typeof window.deviceInfo == "undefined") check();
4
- var os = window.deviceInfo.os.toLowerCase();
5
-
6
- return os.includes("ios");
7
- };
8
-
9
- const isAndroid = () => {
10
- if (typeof window.deviceInfo == "undefined") check();
11
- var os = window.deviceInfo.os.toLowerCase();
12
-
13
- return os.includes("android");
14
- };
15
-
16
- const check = () => {
17
- option = option != undefined ? option : {};
18
-
19
- var callback = option.hasOwnProperty("callback") ? option.callback : null;
20
-
21
- if (typeof window.deviceInfo == "undefined") {
22
- var unknown = "-";
23
-
24
- // screen
25
- var screenSize = "";
26
- if (screen.width) {
27
- var width = screen.width ? screen.width : "";
28
- var height = screen.height ? screen.height : "";
29
- screenSize += "" + width + " x " + height;
30
- }
31
-
32
- // browser
33
- var nVer = navigator.appVersion;
34
- var nAgt = navigator.userAgent;
35
- var browser = navigator.appName;
36
- var version = "" + parseFloat(navigator.appVersion);
37
- var majorVersion = parseInt(navigator.appVersion, 10);
38
- var nameOffset, verOffset, ix;
39
-
40
- // Opera
41
- if ((verOffset = nAgt.indexOf("Opera")) != -1) {
42
- browser = "Opera";
43
- version = nAgt.substring(verOffset + 6);
44
- if ((verOffset = nAgt.indexOf("Version")) != -1) {
45
- version = nAgt.substring(verOffset + 8);
46
- }
47
- }
48
- // Opera Next
49
- if ((verOffset = nAgt.indexOf("OPR")) != -1) {
50
- browser = "Opera";
51
- version = nAgt.substring(verOffset + 4);
52
- }
53
- // Edge
54
- else if ((verOffset = nAgt.indexOf("Edge")) != -1) {
55
- browser = "Microsoft Edge";
56
- version = nAgt.substring(verOffset + 5);
57
- }
58
- // MSIE
59
- else if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
60
- browser = "Microsoft Internet Explorer";
61
- version = nAgt.substring(verOffset + 5);
62
- }
63
- // Chrome
64
- else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
65
- browser = "Chrome";
66
- version = nAgt.substring(verOffset + 7);
67
- }
68
- // Safari
69
- else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
70
- browser = "Safari";
71
- version = nAgt.substring(verOffset + 7);
72
- if ((verOffset = nAgt.indexOf("Version")) != -1) {
73
- version = nAgt.substring(verOffset + 8);
74
- }
75
- }
76
- // Firefox
77
- else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
78
- browser = "Firefox";
79
- version = nAgt.substring(verOffset + 8);
80
- }
81
- // MSIE 11+
82
- else if (nAgt.indexOf("Trident/") != -1) {
83
- browser = "Microsoft Internet Explorer";
84
- version = nAgt.substring(nAgt.indexOf("rv:") + 3);
85
- }
86
- // Other browsers
87
- else if ((nameOffset = nAgt.lastIndexOf(" ") + 1) < (verOffset = nAgt.lastIndexOf("/"))) {
88
- browser = nAgt.substring(nameOffset, verOffset);
89
- version = nAgt.substring(verOffset + 1);
90
- if (browser.toLowerCase() == browser.toUpperCase()) {
91
- browser = navigator.appName;
92
- }
93
- }
94
- // trim the version string
95
- if ((ix = version.indexOf(";")) != -1) version = version.substring(0, ix);
96
- if ((ix = version.indexOf(" ")) != -1) version = version.substring(0, ix);
97
- if ((ix = version.indexOf(")")) != -1) version = version.substring(0, ix);
98
-
99
- majorVersion = parseInt("" + version, 10);
100
- if (isNaN(majorVersion)) {
101
- version = "" + parseFloat(navigator.appVersion);
102
- majorVersion = parseInt(navigator.appVersion, 10);
103
- }
104
-
105
- // mobile version
106
- var mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer);
107
-
108
- // cookie
109
- var cookieEnabled = navigator.cookieEnabled ? true : false;
110
-
111
- if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
112
- document.cookie = "testcookie";
113
- cookieEnabled = document.cookie.indexOf("testcookie") != -1 ? true : false;
114
- }
115
-
116
- // system
117
- var os = unknown;
118
- var clientStrings = [
119
- { s: "Windows 10", r: /(Windows 10.0|Windows NT 10.0)/ },
120
- { s: "Windows 8.1", r: /(Windows 8.1|Windows NT 6.3)/ },
121
- { s: "Windows 8", r: /(Windows 8|Windows NT 6.2)/ },
122
- { s: "Windows 7", r: /(Windows 7|Windows NT 6.1)/ },
123
- { s: "Windows Vista", r: /Windows NT 6.0/ },
124
- { s: "Windows Server 2003", r: /Windows NT 5.2/ },
125
- { s: "Windows XP", r: /(Windows NT 5.1|Windows XP)/ },
126
- { s: "Windows 2000", r: /(Windows NT 5.0|Windows 2000)/ },
127
- { s: "Windows ME", r: /(Win 9x 4.90|Windows ME)/ },
128
- { s: "Windows 98", r: /(Windows 98|Win98)/ },
129
- { s: "Windows 95", r: /(Windows 95|Win95|Windows_95)/ },
130
- { s: "Windows NT 4.0", r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
131
- { s: "Windows CE", r: /Windows CE/ },
132
- { s: "Windows 3.11", r: /Win16/ },
133
- { s: "Android", r: /Android/ },
134
- { s: "Open BSD", r: /OpenBSD/ },
135
- { s: "Sun OS", r: /SunOS/ },
136
- { s: "Linux", r: /(Linux|X11)/ },
137
- { s: "iOS", r: /(iPhone|iPad|iPod)/ },
138
- { s: "Mac OS X", r: /Mac OS X/ },
139
- { s: "Mac OS", r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
140
- { s: "QNX", r: /QNX/ },
141
- { s: "UNIX", r: /UNIX/ },
142
- { s: "BeOS", r: /BeOS/ },
143
- { s: "OS/2", r: /OS\/2/ },
144
- { s: "Search Bot", r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ },
145
- ];
146
- for (var id in clientStrings) {
147
- var cs = clientStrings[id];
148
- if (cs.r.test(nAgt)) {
149
- os = cs.s;
150
- break;
151
- }
152
- }
153
-
154
- var osVersion = unknown;
155
-
156
- if (/Windows/.test(os)) {
157
- osVersion = /Windows (.*)/.exec(os)[1];
158
- os = "Windows";
159
- }
160
-
161
- switch (os) {
162
- case "Mac OS X":
163
- osVersion = /Mac OS X (10[\.\_\d]+)/.exec(nAgt)[1];
164
- break;
165
-
166
- case "Android":
167
- osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1];
168
- break;
169
-
170
- case "iOS":
171
- osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
172
- osVersion = osVersion[1] + "." + osVersion[2] + "." + (osVersion[3] | 0);
173
- break;
174
- }
175
-
176
- // flash (you'll need to include swfobject)
177
- /* script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" */
178
- var flashVersion = "no check";
179
- if (typeof swfobject != "undefined") {
180
- var fv = swfobject.getFlashPlayerVersion();
181
- if (fv.major > 0) {
182
- flashVersion = fv.major + "." + fv.minor + " r" + fv.release;
183
- } else {
184
- flashVersion = unknown;
185
- }
186
- }
187
-
188
- window.deviceInfo = {
189
- screen: screenSize,
190
- browser: browser,
191
- browserVersion: version,
192
- browserMajorVersion: majorVersion,
193
- mobile: mobile,
194
- os: os,
195
- osVersion: osVersion,
196
- cookies: cookieEnabled,
197
- flashVersion: flashVersion,
198
- };
199
- }
200
-
201
- if (callback != null) callback(window.deviceInfo);
202
- };
203
- };
@@ -1,109 +0,0 @@
1
- import ArrayExtra from "./ArrayExtra";
2
-
3
- export default class ObjectExtra {
4
- static getKeyByValue(object, value) {
5
- return Object.keys(object).find((key) => object[key] === value);
6
- }
7
-
8
- static randomValue(obj) {
9
- return obj[this.randomKey(obj)];
10
- }
11
-
12
- static randomKey(obj) {
13
- var keys = Object.keys(obj);
14
- return keys[(keys.length * Math.random()) << 0];
15
- }
16
-
17
- static randomElementIndex(obj) {
18
- var keys = Object.keys(obj);
19
- return (keys.length * Math.random()) << 0;
20
- }
21
-
22
- static getObjectLength(obj) {
23
- var keys = Object.keys(obj);
24
- return keys.length;
25
- }
26
-
27
- /**
28
- *
29
- * @param {Object} obj
30
- * @param {Function} cb
31
- */
32
- static forEach(obj, cb) {
33
- const keys = Object.keys(obj);
34
-
35
- keys.map((key, index) => {
36
- if (cb) cb(key, obj[key], index);
37
- });
38
- }
39
-
40
- /**
41
- *
42
- * @param {Object} object
43
- * @returns {Array} list keys
44
- */
45
- static toArray(obj) {
46
- let array = [];
47
- for (const key in obj) {
48
- array.push(obj[key]);
49
- }
50
- return array;
51
- }
52
-
53
- /**
54
- *
55
- * @param {Object} object
56
- * @returns {Object}
57
- */
58
- static sortObjectByKey(object) {
59
- let array = [];
60
-
61
- for (const key in object) {
62
- array.push({
63
- key: key,
64
- value: object[key],
65
- });
66
- }
67
-
68
- array = ArrayExtra.sortElementByString(array, "key");
69
-
70
- let result = {};
71
-
72
- array.forEach((item) => {
73
- result[item.key] = item.value;
74
- });
75
-
76
- return result;
77
- }
78
-
79
- //
80
-
81
- static isNull(object) {
82
- if (typeof object == "undefined") {
83
- return true;
84
- }
85
- if (Array.isArray(object)) return object.length == 0;
86
- return object == null;
87
- }
88
-
89
- static toBool(object) {
90
- if (this.isNull(object)) return false;
91
- object = object.toString();
92
-
93
- return object === "true" || object == "1";
94
- }
95
-
96
- static toInt(object) {
97
- if (this.isNull(object)) return 0;
98
- object = object.toString();
99
-
100
- return parseInt(object, 10);
101
- }
102
-
103
- static toFloat(object) {
104
- if (this.isNull(object)) return 0;
105
- object = object.toString();
106
-
107
- return parseFloat(object);
108
- }
109
- }
package/src/Url.js DELETED
@@ -1,109 +0,0 @@
1
- import StringExtra from "./string/StringExtra";
2
-
3
- var urlRegex = /(https?:\/\/[^\s]+)/g;
4
-
5
- export default class Url {
6
- static getUrlParams(parameter, staticURL, decode) {
7
- staticURL = staticURL == undefined ? window.location : staticURL;
8
- var currLocation = staticURL.length ? staticURL : window.location.search;
9
-
10
- if (currLocation.split("?").length < 2) return "";
11
-
12
- var parArr = currLocation.split("?")[1].split("&"),
13
- returnBool = true;
14
-
15
- for (var i = 0; i < parArr.length; i++) {
16
- var parr = parArr[i].split("=");
17
- if (parr[0] == parameter) {
18
- return decode ? decodeURIComponent(parr[1]) : parr[1];
19
- returnBool = true;
20
- } else {
21
- returnBool = false;
22
- }
23
- }
24
-
25
- if (!returnBool) return false;
26
- }
27
-
28
- /**
29
- *
30
- * @return {boolean}
31
- */
32
- static isLink(str) {
33
- return urlRegex.test(str);
34
- }
35
-
36
- /**
37
- *
38
- * @return {JSX.Element}
39
- */
40
- static strToJsxLink(str, altText) {
41
- return UrlUtils.isLink(str) ? <a href={src}>{altText || src}</a> : str;
42
- }
43
-
44
- /**
45
- *
46
- * @return {string}
47
- */
48
- static decode(uri) {
49
- return decodeURIComponent(uri);
50
- }
51
-
52
- /**
53
- *
54
- * @return {string}
55
- */
56
- static encode(uri) {
57
- return encodeURIComponent(uri);
58
- }
59
-
60
- /**
61
- *
62
- * @param {string} url
63
- * @return {string}
64
- */
65
- static getFileNameWithoutExtension(url) {
66
- url = this.decode(url);
67
- if (url) {
68
- var m = url.toString().match(/.*\/(.+?)\./);
69
- if (m && m.length > 1) {
70
- return m[1];
71
- }
72
-
73
- if (!StringExtra.isEmpty(url)) {
74
- return url.split(".").shift();
75
- }
76
- }
77
- return "";
78
- }
79
-
80
- /**
81
- *
82
- * @param {string} url
83
- * @return {string}
84
- */
85
- static getFileNameWithExtension(url) {
86
- url = this.decode(url);
87
- if (url) {
88
- var m = url.toString().match(/.*\/(.*)$/);
89
-
90
- if (m && m.length > 1) {
91
- return m[1].split("/").pop().split("?")[0];
92
- }
93
-
94
- if (!StringExtra.isEmpty(url)) {
95
- return url;
96
- }
97
- }
98
- return "";
99
- }
100
-
101
- /**
102
- *
103
- * @param {string} url
104
- * @return {string}
105
- */
106
- static getFileExtension(url) {
107
- return this.getFileNameWithExtension(url).split(".").pop();
108
- }
109
- }
package/src/UrlUtils.js DELETED
@@ -1,109 +0,0 @@
1
- import StringExtra from "./string/StringExtra";
2
-
3
- var urlRegex = /(https?:\/\/[^\s]+)/g;
4
-
5
- export default class UrlUtils {
6
- static getUrlParams(parameter, staticURL, decode) {
7
- staticURL = staticURL == undefined ? window.location : staticURL;
8
- var currLocation = staticURL.length ? staticURL : window.location.search;
9
-
10
- if (currLocation.split("?").length < 2) return "";
11
-
12
- var parArr = currLocation.split("?")[1].split("&"),
13
- returnBool = true;
14
-
15
- for (var i = 0; i < parArr.length; i++) {
16
- var parr = parArr[i].split("=");
17
- if (parr[0] == parameter) {
18
- return decode ? decodeURIComponent(parr[1]) : parr[1];
19
- returnBool = true;
20
- } else {
21
- returnBool = false;
22
- }
23
- }
24
-
25
- if (!returnBool) return false;
26
- }
27
-
28
- /**
29
- *
30
- * @return {boolean}
31
- */
32
- static isLink(str) {
33
- return urlRegex.test(str);
34
- }
35
-
36
- /**
37
- *
38
- * @return {JSX.Element}
39
- */
40
- static strToJsxLink(str, altText) {
41
- return UrlUtils.isLink(str) ? <a href={src}>{altText || src}</a> : str;
42
- }
43
-
44
- /**
45
- *
46
- * @return {string}
47
- */
48
- static decode(uri) {
49
- return decodeURIComponent(uri);
50
- }
51
-
52
- /**
53
- *
54
- * @return {string}
55
- */
56
- static encode(uri) {
57
- return encodeURIComponent(uri);
58
- }
59
-
60
- /**
61
- *
62
- * @param {string} url
63
- * @return {string}
64
- */
65
- static getFileNameWithoutExtension(url) {
66
- url = this.decode(url);
67
- if (url) {
68
- var m = url.toString().match(/.*\/(.+?)\./);
69
- if (m && m.length > 1) {
70
- return m[1];
71
- }
72
-
73
- if (!StringExtra.isEmpty(url)) {
74
- return url.split(".").shift();
75
- }
76
- }
77
- return "";
78
- }
79
-
80
- /**
81
- *
82
- * @param {string} url
83
- * @return {string}
84
- */
85
- static getFileNameWithExtension(url) {
86
- url = this.decode(url);
87
- if (url) {
88
- var m = url.toString().match(/.*\/(.*)$/);
89
-
90
- if (m && m.length > 1) {
91
- return m[1].split("/").pop().split("?")[0];
92
- }
93
-
94
- if (!StringExtra.isEmpty(url)) {
95
- return url;
96
- }
97
- }
98
- return "";
99
- }
100
-
101
- /**
102
- *
103
- * @param {string} url
104
- * @return {string}
105
- */
106
- static getFileExtension(url) {
107
- return this.getFileNameWithExtension(url).split(".").pop();
108
- }
109
- }
package/src/Uuid.js DELETED
@@ -1,66 +0,0 @@
1
- export default function generateUUID() {
2
- // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
3
- var lut = [];
4
- for (var i = 0; i < 256; i++) {
5
- lut[i] = (i < 16 ? "0" : "") + i.toString(16);
6
- }
7
-
8
- function _generateUUID() {
9
- var d0 = (Math.random() * 0xffffffff) | 0;
10
- var d1 = (Math.random() * 0xffffffff) | 0;
11
- var d2 = (Math.random() * 0xffffffff) | 0;
12
- var d3 = (Math.random() * 0xffffffff) | 0;
13
- var uuid =
14
- lut[d0 & 0xff] +
15
- lut[(d0 >> 8) & 0xff] +
16
- lut[(d0 >> 16) & 0xff] +
17
- lut[(d0 >> 24) & 0xff] +
18
- "-" +
19
- lut[d1 & 0xff] +
20
- lut[(d1 >> 8) & 0xff] +
21
- "-" +
22
- lut[((d1 >> 16) & 0x0f) | 0x40] +
23
- lut[(d1 >> 24) & 0xff] +
24
- "-" +
25
- lut[(d2 & 0x3f) | 0x80] +
26
- lut[(d2 >> 8) & 0xff] +
27
- "-" +
28
- lut[(d2 >> 16) & 0xff] +
29
- lut[(d2 >> 24) & 0xff] +
30
- lut[d3 & 0xff] +
31
- lut[(d3 >> 8) & 0xff] +
32
- lut[(d3 >> 16) & 0xff] +
33
- lut[(d3 >> 24) & 0xff];
34
-
35
- // .toUpperCase() here flattens concatenated strings to save heap memory space.
36
- return uuid.toUpperCase();
37
- }
38
-
39
- return _generateUUID();
40
- }
41
-
42
- // export default {
43
- // get generateUUID() {
44
- // // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
45
- // var lut = [];
46
- // for (var i = 0; i < 256; i++) {
47
- // lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
48
- // }
49
-
50
- // function _generateUUID() {
51
- // var d0 = Math.random() * 0xffffffff | 0;
52
- // var d1 = Math.random() * 0xffffffff | 0;
53
- // var d2 = Math.random() * 0xffffffff | 0;
54
- // var d3 = Math.random() * 0xffffffff | 0;
55
- // var uuid = lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff] + '-' +
56
- // lut[d1 & 0xff] + lut[d1 >> 8 & 0xff] + '-' + lut[d1 >> 16 & 0x0f | 0x40] + lut[d1 >> 24 & 0xff] + '-' +
57
- // lut[d2 & 0x3f | 0x80] + lut[d2 >> 8 & 0xff] + '-' + lut[d2 >> 16 & 0xff] + lut[d2 >> 24 & 0xff] +
58
- // lut[d3 & 0xff] + lut[d3 >> 8 & 0xff] + lut[d3 >> 16 & 0xff] + lut[d3 >> 24 & 0xff];
59
-
60
- // // .toUpperCase() here flattens concatenated strings to save heap memory space.
61
- // return uuid.toUpperCase();
62
- // };
63
-
64
- // return _generateUUID()
65
- // },
66
- // }