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.
- package/dist/README.md +3 -0
- package/{babel.config.json → dist/babel.config.json} +0 -0
- package/dist/index.js +148 -0
- package/dist/package.json +34 -0
- package/dist/{Camera.js → src/Camera.js} +0 -0
- package/dist/{Checker.js → src/Checker.js} +0 -0
- package/dist/{Color.js → src/Color.js} +0 -0
- package/dist/{Device.js → src/Device.js} +0 -0
- package/dist/{EventDispatcher.js → src/EventDispatcher.js} +0 -0
- package/dist/{FileUpload.js → src/FileUpload.js} +0 -0
- package/dist/{FileUtils.js → src/FileUtils.js} +0 -0
- package/dist/{Slug.js → src/Slug.js} +0 -0
- package/dist/{Timer.js → src/Timer.js} +0 -0
- package/dist/{UserLS.js → src/UserLS.js} +0 -0
- package/dist/{Validation.js → src/Validation.js} +0 -0
- package/dist/{array → src/array}/index.js +0 -0
- package/dist/{backend → src/backend}/file/createDir.js +0 -0
- package/dist/{backend → src/backend}/file/fileMove.js +0 -0
- package/dist/{backend → src/backend}/file/findFilesByExt.js +0 -0
- package/dist/{backend → src/backend}/zip/extractZip.js +0 -0
- package/dist/{console → src/console}/enableConsole.js +0 -0
- package/dist/{console → src/console}/index.js +0 -0
- package/dist/{device → src/device}/browser.js +0 -0
- package/dist/{device → src/device}/camera.js +0 -0
- package/dist/{device → src/device}/index.js +0 -0
- package/dist/{math → src/math}/index.js +0 -0
- package/dist/{object → src/object}/index.js +0 -0
- package/dist/{permission → src/permission}/requestCamera.js +0 -0
- package/dist/{permission → src/permission}/requestDeviceOrientationControl.js +0 -0
- package/dist/{string → src/string}/index.js +0 -0
- package/dist/{string → src/string}/url.js +0 -0
- package/package.json +6 -2
- package/.eslintrc.json +0 -21
- package/src/Camera.js +0 -412
- package/src/Checker.js +0 -24
- package/src/Color.js +0 -81
- package/src/Device.js +0 -56
- package/src/EventDispatcher.js +0 -58
- package/src/FileUpload.js +0 -59
- package/src/FileUtils.js +0 -30
- package/src/Slug.js +0 -383
- package/src/Timer.js +0 -7
- package/src/UserLS.js +0 -104
- package/src/Validation.js +0 -35
- package/src/array/index.js +0 -301
- package/src/backend/file/createDir.js +0 -13
- package/src/backend/file/fileMove.js +0 -35
- package/src/backend/file/findFilesByExt.js +0 -42
- package/src/backend/zip/extractZip.js +0 -58
- package/src/console/enableConsole.js +0 -6
- package/src/console/index.js +0 -10
- package/src/device/browser.js +0 -29
- package/src/device/camera.js +0 -228
- package/src/device/index.js +0 -233
- package/src/math/index.js +0 -211
- package/src/object/index.js +0 -41
- package/src/permission/requestCamera.js +0 -43
- package/src/permission/requestDeviceOrientationControl.js +0 -32
- package/src/string/index.js +0 -228
- package/src/string/url.js +0 -93
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const requestCamera = ({ audio = true, video = true }) => {
|
|
2
|
-
if (typeof window == "undefined") return false;
|
|
3
|
-
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
// Older browsers might not implement mediaDevices at all, so we set an empty object first
|
|
6
|
-
if (navigator.mediaDevices === undefined) {
|
|
7
|
-
navigator.mediaDevices = {};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// Some browsers partially implement mediaDevices. We can't just assign an object
|
|
11
|
-
// with getUserMedia as it would overwrite existing properties.
|
|
12
|
-
// Here, we will just add the getUserMedia property if it's missing.
|
|
13
|
-
if (navigator.mediaDevices.getUserMedia === undefined) {
|
|
14
|
-
navigator.mediaDevices.getUserMedia = function (constraints) {
|
|
15
|
-
// First get ahold of the legacy getUserMedia, if present
|
|
16
|
-
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
|
17
|
-
|
|
18
|
-
// Some browsers just don't implement it - return a rejected promise with an error
|
|
19
|
-
// to keep a consistent interface
|
|
20
|
-
if (!getUserMedia) {
|
|
21
|
-
return Promise.reject(new Error("getUserMedia is not implemented in this browser"));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Otherwise, wrap the call to the old navigator.getUserMedia with a Promise
|
|
25
|
-
return new Promise(function (resolve, reject) {
|
|
26
|
-
getUserMedia.call(navigator, constraints, resolve, reject);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
navigator.mediaDevices
|
|
32
|
-
.getUserMedia({ audio, video })
|
|
33
|
-
.then(function (stream) {
|
|
34
|
-
resolve(true);
|
|
35
|
-
})
|
|
36
|
-
.catch(function (err) {
|
|
37
|
-
console.log(err.name + ": " + err.message);
|
|
38
|
-
resolve(false);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default requestCamera;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { isAndroid } from "../device";
|
|
2
|
-
|
|
3
|
-
const requestDeviceOrientationControl = () => {
|
|
4
|
-
if (typeof window == "undefined") return false;
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
if (isAndroid()) resolve(true);
|
|
7
|
-
|
|
8
|
-
if (typeof DeviceMotionEvent != "undefined" && DeviceMotionEvent.requestPermission) {
|
|
9
|
-
// (optional) Do something before API request prompt.
|
|
10
|
-
DeviceOrientationEvent.requestPermission()
|
|
11
|
-
.then((response) => {
|
|
12
|
-
// (optional) Do something after API prompt dismissed.
|
|
13
|
-
if (response == "granted") {
|
|
14
|
-
resolve(true);
|
|
15
|
-
// resolve({ status: true })
|
|
16
|
-
} else {
|
|
17
|
-
resolve(false);
|
|
18
|
-
// resolve({ status: false, reason: "DeviceMotionEvent is not support" })
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
.catch((response) => {
|
|
22
|
-
resolve(false);
|
|
23
|
-
// resolve({ status: false, reason: response })
|
|
24
|
-
});
|
|
25
|
-
} else {
|
|
26
|
-
resolve(false);
|
|
27
|
-
// resolve({ status: false, reason: "DeviceMotionEvent is not defined" })
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default requestDeviceOrientationControl;
|
package/src/string/index.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
// import { log } from "../../helper/log";
|
|
2
|
-
// import { startCase, toLower } from "lodash";
|
|
3
|
-
import { isNull } from "../object";
|
|
4
|
-
|
|
5
|
-
export const textLowCase = "abcdefghijklmnopqrstuvwxyz";
|
|
6
|
-
export const numeric = "0123456789";
|
|
7
|
-
export const punctuation = "!@#$%^&*()_+~|}{[];?><,./-=";
|
|
8
|
-
export const allCharacter = `đĐaáàảãạăắằẳẵặâấầẩẫậeéèẻẽẹêếềểễệoóòỏõọôốồổỗộơớờởỡợiíìỉĩịuúùủũụưứừửữựyýỳỷỹỵAÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬEÉÈẺẼẸÊẾỀỂỄỆOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢIÍÌỈĨỊUÚÙỦŨỤƯỨỪỬỮỰYÝỲ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}`;
|
|
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
|
-
|
|
16
|
-
/**
|
|
17
|
-
* allCharacter = `đĐaáàảãạăắằẳẵặâấầẩẫậeéèẻẽẹêếềểễệoóòỏõọôốồổỗộơớờởỡợiíìỉĩịuúùủũụưứừửữựyýỳỷỹỵAÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬEÉÈẺẼẸÊẾỀỂỄỆOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢIÍÌỈĨỊUÚÙỦŨỤƯỨỪỬỮỰYÝỲ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}`;
|
|
18
|
-
* @param {number} length
|
|
19
|
-
* @returns {string}
|
|
20
|
-
*/
|
|
21
|
-
export const randAllCharacterByLength = (length = 0) => {
|
|
22
|
-
return randomStringByLength(length, allCharacter);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {number} length
|
|
27
|
-
* @param {textLowCase | numeric | punctuation | allCharacter} str
|
|
28
|
-
* @returns {string}
|
|
29
|
-
*/
|
|
30
|
-
export const randomStringByLength = (length, str = textLowCase) => {
|
|
31
|
-
let result = "";
|
|
32
|
-
|
|
33
|
-
for (let i = 0; i < length; i++) {
|
|
34
|
-
result += str.charAt(Math.floor(Math.random() * str.length));
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get string between str1 and str2 from text
|
|
41
|
-
* @param {string} text
|
|
42
|
-
* @param {string} str1
|
|
43
|
-
* @param {string} str2
|
|
44
|
-
* @return {string}
|
|
45
|
-
*/
|
|
46
|
-
export const getBetween = (text, str1, str2 = "") => {
|
|
47
|
-
if (!text) return "";
|
|
48
|
-
if (text.indexOf(str1) <= -1) return "";
|
|
49
|
-
|
|
50
|
-
const firstIndex = text.indexOf(str1) + str1.length;
|
|
51
|
-
const secondIndex = str2 ? text.indexOf(str2, firstIndex) : text.length;
|
|
52
|
-
return text.substring(firstIndex, secondIndex);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Convert object to string
|
|
57
|
-
* @param {*} object
|
|
58
|
-
* @return {string}
|
|
59
|
-
*/
|
|
60
|
-
export const makeString = (object = "") => {
|
|
61
|
-
/// Ensure some object is a coerced to a string
|
|
62
|
-
if (isNull(object)) return "";
|
|
63
|
-
|
|
64
|
-
return "" + object;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* toUpperCase
|
|
69
|
-
* @param {*} str
|
|
70
|
-
* @return {string}
|
|
71
|
-
*/
|
|
72
|
-
export const toUpperCase = (str = "") => {
|
|
73
|
-
return makeString(str).toUpperCase();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* toLowerCase
|
|
78
|
-
* @param {*} str
|
|
79
|
-
* @return {string}
|
|
80
|
-
*/
|
|
81
|
-
export const toLowerCase = (str = "") => {
|
|
82
|
-
return makeString(str).toLowerCase();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* toLowerCase
|
|
87
|
-
* @param {*} str
|
|
88
|
-
* @return {string}
|
|
89
|
-
*/
|
|
90
|
-
export const titleize = (str = "") => {
|
|
91
|
-
const regString = new RegExp(/(?:^|\s|-)\S/g);
|
|
92
|
-
return toLowerCase(str).replace(regString, function (c) {
|
|
93
|
-
return c.toUpperCase();
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Convert only first charater to UpperCase
|
|
99
|
-
* @param {*} str
|
|
100
|
-
* @return {string}
|
|
101
|
-
*/
|
|
102
|
-
export const capitalize = (str, lowercaseRest = 1) => {
|
|
103
|
-
str = makeString(str);
|
|
104
|
-
const remainingChars = !lowercaseRest ? str.slice(1) : str.slice(1).toLowerCase();
|
|
105
|
-
|
|
106
|
-
return str.charAt(0).toUpperCase() + remainingChars;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Convert first character from every single words to UpperCase
|
|
111
|
-
* @param {*} str
|
|
112
|
-
* @return {string}
|
|
113
|
-
*/
|
|
114
|
-
export const capitalizeName = (str) => {
|
|
115
|
-
str = makeString(str);
|
|
116
|
-
|
|
117
|
-
str = str.trim();
|
|
118
|
-
str = str.replace(/^\s+|\s+$/gm, "");
|
|
119
|
-
|
|
120
|
-
str = str.toLowerCase();
|
|
121
|
-
|
|
122
|
-
const arr = str.split(" ");
|
|
123
|
-
|
|
124
|
-
str = arr
|
|
125
|
-
.map((item) => {
|
|
126
|
-
return capitalize(item);
|
|
127
|
-
})
|
|
128
|
-
.filter((x) => x)
|
|
129
|
-
.join(" ");
|
|
130
|
-
|
|
131
|
-
return str;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
* @param {string} s - Input string
|
|
137
|
-
* @param {{delimiter,limit,lowercase,replacements,transliterate}} opt - Option
|
|
138
|
-
* @return {string}
|
|
139
|
-
*/
|
|
140
|
-
export const clearUnicodeCharacters = (s, opt = {}) => {
|
|
141
|
-
s = makeString(s);
|
|
142
|
-
|
|
143
|
-
var defaults = {
|
|
144
|
-
delimiter: " ",
|
|
145
|
-
limit: undefined,
|
|
146
|
-
lowercase: true,
|
|
147
|
-
replacements: {},
|
|
148
|
-
transliterate: typeof XRegExp === "undefined" ? true : false,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
// Merge options
|
|
152
|
-
for (var k in defaults) {
|
|
153
|
-
if (!opt.hasOwnProperty(k)) {
|
|
154
|
-
opt[k] = defaults[k];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Vietnamese
|
|
159
|
-
s = s.replace(/á|à|ả|ạ|ã|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/gi, "a");
|
|
160
|
-
s = s.replace(/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/gi, "e");
|
|
161
|
-
s = s.replace(/i|í|ì|ỉ|ĩ|ị/gi, "i");
|
|
162
|
-
s = s.replace(/ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ/gi, "o");
|
|
163
|
-
s = s.replace(/ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự/gi, "u");
|
|
164
|
-
s = s.replace(/ý|ỳ|ỷ|ỹ|ỵ/gi, "y");
|
|
165
|
-
s = s.replace(/đ/gi, "d");
|
|
166
|
-
s = "@" + s + "@";
|
|
167
|
-
s = s.replace(/\@\-|\-\@|\@/gi, "");
|
|
168
|
-
|
|
169
|
-
// Make custom replacements
|
|
170
|
-
for (var k in opt.replacements) {
|
|
171
|
-
s = s.replace(RegExp(k, "g"), opt.replacements[k]);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Transliterate characters to ASCII
|
|
175
|
-
if (opt.transliterate) {
|
|
176
|
-
for (var k in char_map) {
|
|
177
|
-
s = s.replace(RegExp(k, "g"), char_map[k]);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Replace non-alphanumeric characters with our delimiter
|
|
182
|
-
var alnum = typeof XRegExp === "undefined" ? RegExp("[^a-z0-9]+", "ig") : XRegExp("[^\\p{L}\\p{N}]+", "ig");
|
|
183
|
-
s = s.replace(alnum, opt.delimiter);
|
|
184
|
-
|
|
185
|
-
// Remove duplicate delimiters
|
|
186
|
-
s = s.replace(RegExp("[" + opt.delimiter + "]{2,}", "g"), opt.delimiter);
|
|
187
|
-
|
|
188
|
-
// Truncate slug to max. characters
|
|
189
|
-
s = s.substring(0, opt.limit);
|
|
190
|
-
|
|
191
|
-
// Remove delimiter from ends
|
|
192
|
-
s = s.replace(RegExp("(^" + opt.delimiter + "|" + opt.delimiter + "$)", "g"), "");
|
|
193
|
-
|
|
194
|
-
return opt.lowercase ? s.toLowerCase() : s;
|
|
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
|
-
}
|
package/src/string/url.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
};
|