diginext-utils 2.0.5 → 2.0.8
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/Checker.d.ts +0 -1
- package/dist/Checker.js +27 -45
- package/dist/Checker.js.map +1 -0
- package/dist/EventDispatcher.d.ts +1 -3
- package/dist/EventDispatcher.js +47 -70
- package/dist/EventDispatcher.js.map +1 -0
- package/dist/FileUpload.d.ts +0 -1
- package/dist/FileUpload.js +61 -79
- package/dist/FileUpload.js.map +1 -0
- package/dist/Slug.d.ts +0 -1
- package/dist/Slug.js +329 -347
- package/dist/Slug.js.map +1 -0
- package/dist/Timer.d.ts +1 -3
- package/dist/Timer.js +8 -32
- package/dist/Timer.js.map +1 -0
- package/dist/Validation.d.ts +1 -3
- package/dist/Validation.js +38 -55
- package/dist/Validation.js.map +1 -0
- package/dist/array.d.ts +19 -21
- package/dist/array.js +264 -242
- package/dist/array.js.map +1 -0
- package/dist/color.d.ts +7 -9
- package/dist/color.js +78 -87
- package/dist/color.js.map +1 -0
- package/dist/console/enableConsole.d.ts +1 -3
- package/dist/console/enableConsole.js +10 -36
- package/dist/console/enableConsole.js.map +1 -0
- package/dist/console/index.d.ts +3 -5
- package/dist/console/index.js +15 -42
- package/dist/console/index.js.map +1 -0
- package/dist/device/browser.d.ts +5 -7
- package/dist/device/browser.js +33 -60
- package/dist/device/browser.js.map +1 -0
- package/dist/device/camera.d.ts +7 -16
- package/dist/device/camera.js +167 -187
- package/dist/device/camera.js.map +1 -0
- package/dist/device.d.ts +4 -6
- package/dist/device.js +210 -190
- package/dist/device.js.map +1 -0
- package/dist/file/createDir.d.ts +1 -2
- package/dist/file/createDir.js +14 -34
- package/dist/file/createDir.js.map +1 -0
- package/dist/file/fileMove.d.ts +1 -3
- package/dist/file/fileMove.js +30 -49
- package/dist/file/fileMove.js.map +1 -0
- package/dist/file/findFilesByExt.d.ts +0 -1
- package/dist/file/findFilesByExt.js +40 -58
- package/dist/file/findFilesByExt.js.map +1 -0
- package/dist/index.d.ts +16 -12
- package/dist/index.js +33 -906
- package/dist/index.js.map +1 -0
- package/dist/math/diffDate.d.ts +1 -3
- package/dist/math/diffDate.js +11 -31
- package/dist/math/diffDate.js.map +1 -0
- package/dist/math/index.d.ts +8 -10
- package/dist/math/index.js +87 -71
- package/dist/math/index.js.map +1 -0
- package/dist/math/positiveNumber.d.ts +1 -3
- package/dist/math/positiveNumber.js +14 -51
- package/dist/math/positiveNumber.js.map +1 -0
- package/dist/name/en.d.ts +1 -3
- package/dist/name/en.js +18 -34
- package/dist/name/en.js.map +1 -0
- package/dist/name/vi.d.ts +1 -3
- package/dist/name/vi.js +24 -60
- package/dist/name/vi.js.map +1 -0
- package/dist/object.d.ts +9 -11
- package/dist/object.js +57 -82
- package/dist/object.js.map +1 -0
- package/dist/permission/requestCamera.d.ts +2 -3
- package/dist/permission/requestCamera.js +38 -47
- package/dist/permission/requestCamera.js.map +1 -0
- package/dist/permission/requestDeviceOrientationControl.d.ts +0 -1
- package/dist/permission/requestDeviceOrientationControl.js +36 -198
- package/dist/permission/requestDeviceOrientationControl.js.map +1 -0
- package/dist/string/formatNumber.d.ts +1 -3
- package/dist/string/formatNumber.js +12 -51
- package/dist/string/formatNumber.js.map +1 -0
- package/dist/string/generatePassword.d.ts +1 -3
- package/dist/string/generatePassword.js +21 -50
- package/dist/string/generatePassword.js.map +1 -0
- package/dist/string/generateUUID.d.ts +1 -3
- package/dist/string/generateUUID.js +34 -35
- package/dist/string/generateUUID.js.map +1 -0
- package/dist/string/index.d.ts +8 -10
- package/dist/string/index.js +119 -127
- package/dist/string/index.js.map +1 -0
- package/dist/string/random.d.ts +6 -8
- package/dist/string/random.js +21 -50
- package/dist/string/random.js.map +1 -0
- package/dist/string/trimNull.d.ts +1 -3
- package/dist/string/trimNull.js +15 -41
- package/dist/string/trimNull.js.map +1 -0
- package/dist/string/url.d.ts +7 -14
- package/dist/string/url.js +93 -108
- package/dist/string/url.js.map +1 -0
- package/package.json +6 -9
- package/src/Checker.ts +27 -0
- package/src/EventDispatcher.ts +60 -0
- package/src/FileUpload.ts +65 -0
- package/src/Slug.ts +364 -0
- package/src/Timer.ts +5 -0
- package/src/Validation.ts +35 -0
- package/src/array.ts +261 -0
- package/src/color.ts +89 -0
- package/src/console/enableConsole.ts +6 -0
- package/src/console/index.ts +11 -0
- package/src/device/browser.ts +29 -0
- package/src/device/camera.ts +209 -0
- package/src/device.ts +223 -0
- package/src/file/createDir.ts +14 -0
- package/src/file/fileMove.ts +32 -0
- package/src/file/findFilesByExt.ts +39 -0
- package/src/index.ts +17 -0
- package/src/math/diffDate.ts +8 -0
- package/src/math/index.ts +88 -0
- package/src/math/positiveNumber.ts +10 -0
- package/src/name/en.ts +24 -0
- package/src/name/vi.ts +21 -0
- package/src/object.ts +49 -0
- package/src/permission/requestCamera.ts +43 -0
- package/src/permission/requestDeviceOrientationControl.ts +33 -0
- package/src/string/formatNumber.ts +10 -0
- package/src/string/generatePassword.ts +16 -0
- package/src/string/generateUUID.ts +35 -0
- package/src/string/index.ts +145 -0
- package/src/string/random.ts +20 -0
- package/src/string/trimNull.ts +11 -0
- package/src/string/url.ts +109 -0
- package/dist/.DS_Store +0 -0
- package/dist/Checker.mjs +0 -26
- package/dist/EventDispatcher.mjs +0 -52
- package/dist/FileUpload.mjs +0 -60
- package/dist/Slug.mjs +0 -328
- package/dist/Timer.mjs +0 -7
- package/dist/Validation.mjs +0 -34
- package/dist/array.mjs +0 -44
- package/dist/chunk-2R5DRG2S.mjs +0 -28
- package/dist/chunk-3NMJTC44.mjs +0 -146
- package/dist/chunk-5AL36RZR.mjs +0 -54
- package/dist/chunk-7UXN7I4K.mjs +0 -96
- package/dist/chunk-A4YWYLCH.mjs +0 -23
- package/dist/chunk-AHFJBIQJ.mjs +0 -10
- package/dist/chunk-AKU6F3WT.mjs +0 -11
- package/dist/chunk-ALNAD4H7.mjs +0 -10
- package/dist/chunk-FOWYH6LL.mjs +0 -38
- package/dist/chunk-FTE6FZSH.mjs +0 -24
- package/dist/chunk-LXQIKFED.mjs +0 -17
- package/dist/chunk-NLQXFCPR.mjs +0 -30
- package/dist/chunk-QXFH3X2K.mjs +0 -49
- package/dist/chunk-R2BH5I6O.mjs +0 -9
- package/dist/chunk-S2U7F2JJ.mjs +0 -207
- package/dist/chunk-UKRVCU5M.mjs +0 -171
- package/dist/color.mjs +0 -68
- package/dist/console/enableConsole.mjs +0 -11
- package/dist/console/index.mjs +0 -18
- package/dist/device/browser.mjs +0 -39
- package/dist/device/camera.mjs +0 -146
- package/dist/device.mjs +0 -13
- package/dist/file/createDir.mjs +0 -16
- package/dist/file/fileMove.mjs +0 -32
- package/dist/file/findFilesByExt.mjs +0 -42
- package/dist/index.mjs +0 -143
- package/dist/math/diffDate.mjs +0 -11
- package/dist/math/index.mjs +0 -21
- package/dist/math/positiveNumber.mjs +0 -19
- package/dist/name/en.mjs +0 -18
- package/dist/name/vi.mjs +0 -34
- package/dist/object.mjs +0 -17
- package/dist/permission/requestCamera.mjs +0 -7
- package/dist/permission/requestDeviceOrientationControl.mjs +0 -176
- package/dist/string/formatNumber.mjs +0 -13
- package/dist/string/generatePassword.mjs +0 -22
- package/dist/string/generateUUID.mjs +0 -15
- package/dist/string/index.mjs +0 -96
- package/dist/string/random.mjs +0 -17
- package/dist/string/trimNull.mjs +0 -16
- package/dist/string/url.mjs +0 -79
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// import { log } from "../../helper/log";
|
|
2
|
+
// import { startCase, toLower } from "lodash";
|
|
3
|
+
declare var XRegExp: any;
|
|
4
|
+
|
|
5
|
+
import { isNull } from "../object";
|
|
6
|
+
|
|
7
|
+
//prettier-ignore
|
|
8
|
+
const char_map: { [key: string]: any }={À:"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",Ý:"Y",Þ:"TH",ß:"ss",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",æ:"ae",è:"e",é:"e",ê:"e",ë:"e",ì:"i",í:"i",î:"i",ï:"i",ð:"d",ñ:"n",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ő:"o",ø:"o",ù:"u",ú:"u",û:"u",ű:"u",ý:"y",þ:"th",ÿ:"y","©":"(c)",Γ:"G",Δ:"D",Θ:"8",Λ:"L",Ξ:"3",Π:"P",Σ:"S",Φ:"F",Ψ:"PS",Ω:"W",Ά:"A",Έ:"E",Ί:"I",Ό:"O",Ύ:"Y",Ή:"H",Ώ:"W",Ϊ:"I",Ϋ:"Y",β:"b","γ":"y",δ:"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",Ü:"U",Ğ:"G",ş:"s",ı:"i",ç:"c",ü:"u",ğ:"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",Ś:"S",Ź:"Z",Ż:"Z",ą:"a",ć:"c",ę:"e",ł:"l",ń:"n",ś:"s",ź:"z",ż:"z",Ā:"A",Ē:"E",Ģ:"G",Ī:"i",Ķ:"k",Ļ:"L",Ņ:"N",Ū:"u",ā:"a",ē:"e",ģ:"g",ī:"i",ķ:"k",ļ:"l",ņ:"n",ū:"u"};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get string between str1 and str2 from text
|
|
12
|
+
*/
|
|
13
|
+
export const getBetween = (text: string, str1: string, str2 = "") => {
|
|
14
|
+
if (!text) return "";
|
|
15
|
+
if (text.indexOf(str1) <= -1) return "";
|
|
16
|
+
|
|
17
|
+
const firstIndex = text.indexOf(str1) + str1.length;
|
|
18
|
+
const secondIndex = str2 ? text.indexOf(str2, firstIndex) : text.length;
|
|
19
|
+
return text.substring(firstIndex, secondIndex);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Convert object to string
|
|
24
|
+
*/
|
|
25
|
+
export const makeString = (object: any = "") => {
|
|
26
|
+
/// Ensure some object is a coerced to a string
|
|
27
|
+
if (isNull(object)) return "";
|
|
28
|
+
|
|
29
|
+
return "" + object;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* toUpperCase
|
|
34
|
+
*/
|
|
35
|
+
export const toUpperCase = (str = "") => {
|
|
36
|
+
return makeString(str).toUpperCase();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* toLowerCase
|
|
41
|
+
*/
|
|
42
|
+
export const toLowerCase = (str = "") => {
|
|
43
|
+
return makeString(str).toLowerCase();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* toLowerCase
|
|
48
|
+
* @param {*} str
|
|
49
|
+
* @return {string}
|
|
50
|
+
*/
|
|
51
|
+
export const titleize = (str = "") => {
|
|
52
|
+
const regString = new RegExp(/(?:^|\s|-)\S/g);
|
|
53
|
+
return toLowerCase(str).replace(regString, function (c) {
|
|
54
|
+
return c.toUpperCase();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Convert only first charater to UpperCase
|
|
60
|
+
*/
|
|
61
|
+
export const capitalize = (str: string | any, lowercaseRest = 1) => {
|
|
62
|
+
str = makeString(str);
|
|
63
|
+
const remainingChars = !lowercaseRest ? str.slice(1) : str.slice(1).toLowerCase();
|
|
64
|
+
|
|
65
|
+
return str.charAt(0).toUpperCase() + remainingChars;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Convert first character from every single words to UpperCase
|
|
70
|
+
*/
|
|
71
|
+
export const capitalizeName = (str: string) => {
|
|
72
|
+
str = makeString(str);
|
|
73
|
+
|
|
74
|
+
str = str.trim();
|
|
75
|
+
str = str.replace(/^\s+|\s+$/gm, "");
|
|
76
|
+
|
|
77
|
+
str = str.toLowerCase();
|
|
78
|
+
|
|
79
|
+
const arr = str.split(" ");
|
|
80
|
+
|
|
81
|
+
str = arr
|
|
82
|
+
.map((item) => {
|
|
83
|
+
return capitalize(item);
|
|
84
|
+
})
|
|
85
|
+
.filter((x) => x)
|
|
86
|
+
.join(" ");
|
|
87
|
+
|
|
88
|
+
return str;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const clearUnicodeCharacters = (s: string, opt: { [key: string]: any } = {}) => {
|
|
92
|
+
s = makeString(s);
|
|
93
|
+
|
|
94
|
+
var defaults: { [key: string]: any } = {
|
|
95
|
+
delimiter: " ",
|
|
96
|
+
lowercase: true,
|
|
97
|
+
replacements: {},
|
|
98
|
+
transliterate: typeof XRegExp === "undefined" ? true : false,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Merge options
|
|
102
|
+
for (var k in defaults) {
|
|
103
|
+
if (!opt.hasOwnProperty(k)) {
|
|
104
|
+
opt[k] = defaults[k];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Vietnamese
|
|
109
|
+
s = s.replace(/á|à|ả|ạ|ã|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/gi, "a");
|
|
110
|
+
s = s.replace(/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/gi, "e");
|
|
111
|
+
s = s.replace(/i|í|ì|ỉ|ĩ|ị/gi, "i");
|
|
112
|
+
s = s.replace(/ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ/gi, "o");
|
|
113
|
+
s = s.replace(/ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự/gi, "u");
|
|
114
|
+
s = s.replace(/ý|ỳ|ỷ|ỹ|ỵ/gi, "y");
|
|
115
|
+
s = s.replace(/đ/gi, "d");
|
|
116
|
+
s = "@" + s + "@";
|
|
117
|
+
s = s.replace(/\@\-|\-\@|\@/gi, "");
|
|
118
|
+
|
|
119
|
+
// Make custom replacements
|
|
120
|
+
for (var k in opt.replacements) {
|
|
121
|
+
s = s.replace(RegExp(k, "g"), opt.replacements[k]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Transliterate characters to ASCII
|
|
125
|
+
if (opt.transliterate) {
|
|
126
|
+
for (var k in char_map) {
|
|
127
|
+
s = s.replace(RegExp(k, "g"), char_map[k]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Replace non-alphanumeric characters with our delimiter
|
|
132
|
+
var alnum = typeof XRegExp === "undefined" ? RegExp("[^a-z0-9]+", "ig") : XRegExp("[^\\p{L}\\p{N}]+", "ig");
|
|
133
|
+
s = s.replace(alnum, opt.delimiter);
|
|
134
|
+
|
|
135
|
+
// Remove duplicate delimiters
|
|
136
|
+
s = s.replace(RegExp("[" + opt.delimiter + "]{2,}", "g"), opt.delimiter);
|
|
137
|
+
|
|
138
|
+
// Truncate slug to max. characters
|
|
139
|
+
s = s.substring(0, opt.limit);
|
|
140
|
+
|
|
141
|
+
// Remove delimiter from ends
|
|
142
|
+
s = s.replace(RegExp("(^" + opt.delimiter + "|" + opt.delimiter + "$)", "g"), "");
|
|
143
|
+
|
|
144
|
+
return opt.lowercase ? s.toLowerCase() : s;
|
|
145
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const textLowCase = "abcdefghijklmnopqrstuvwxyz";
|
|
2
|
+
export const numeric = "0123456789";
|
|
3
|
+
export const punctuation = "!@#$%^&*()_+~|}{[];?><,./-=";
|
|
4
|
+
export const allCharacter = `đĐaáàảãạăắằẳẵặâấầẩẫậeéèẻẽẹêếềểễệoóòỏõọôốồổỗộơớờởỡợiíìỉĩịuúùủũụưứừửữựyýỳỷỹỵAÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬEÉÈẺẼẸÊẾỀỂỄỆOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢIÍÌỈĨỊUÚÙỦŨỤƯỨỪỬỮỰYÝỲ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}`;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* allCharacter = `đĐaáàảãạăắằẳẵặâấầẩẫậeéèẻẽẹêếềểễệoóòỏõọôốồổỗộơớờởỡợiíìỉĩịuúùủũụưứừửữựyýỳỷỹỵAÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬEÉÈẺẼẸÊẾỀỂỄỆOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢIÍÌỈĨỊUÚÙỦŨỤƯỨỪỬỮỰYÝỲ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}`;
|
|
8
|
+
*/
|
|
9
|
+
export const randAllCharacterByLength = (length = 0) => {
|
|
10
|
+
return randomStringByLength(length, allCharacter);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const randomStringByLength = (length:number, str = textLowCase) => {
|
|
14
|
+
let result = "";
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < length; i++) {
|
|
17
|
+
result += str.charAt(Math.floor(Math.random() * str.length));
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isNull } from "../object";
|
|
2
|
+
|
|
3
|
+
var urlRegex = /(https?:\/\/[^\s]+)/g;
|
|
4
|
+
|
|
5
|
+
export const addQueryParam = (_url: string, key: string, value: any) => {
|
|
6
|
+
_url += (_url.split("?")[1] ? "&" : "?") + `${key}=${value}`;
|
|
7
|
+
|
|
8
|
+
return _url;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getUrlParams = (parameter: string, staticURL?: string, decode: boolean = true) => {
|
|
12
|
+
if (typeof window == "undefined") return "";
|
|
13
|
+
|
|
14
|
+
staticURL = staticURL == undefined ? window.location.host : staticURL;
|
|
15
|
+
var currLocation = staticURL.length > 0 ? staticURL : window.location.search;
|
|
16
|
+
|
|
17
|
+
if (currLocation.split("?").length < 2) return "";
|
|
18
|
+
|
|
19
|
+
var parArr = currLocation.split("?")[1].split("&"),
|
|
20
|
+
returnBool = true;
|
|
21
|
+
|
|
22
|
+
for (var i = 0; i < parArr.length; i++) {
|
|
23
|
+
var parr = parArr[i].split("=");
|
|
24
|
+
if (parr[0] == parameter) {
|
|
25
|
+
return decode ? decodeURIComponent(parr[1]) : parr[1];
|
|
26
|
+
returnBool = true;
|
|
27
|
+
} else {
|
|
28
|
+
returnBool = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!returnBool) return false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @return {boolean}
|
|
38
|
+
*/
|
|
39
|
+
export const isLink = (str: string) => {
|
|
40
|
+
return urlRegex.test(str);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// /**
|
|
44
|
+
// *
|
|
45
|
+
// * @return {JSX.Element}
|
|
46
|
+
// */
|
|
47
|
+
// export const strToJsxLink = (str, altText) => {
|
|
48
|
+
// return isLink(str) ? <a href={src}>{altText || src}</a> : str;
|
|
49
|
+
// };
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {string} url
|
|
54
|
+
* @return {string}
|
|
55
|
+
*/
|
|
56
|
+
export const getFileNameWithoutExtension = (url: string) => {
|
|
57
|
+
url = decodeURIComponent(url);
|
|
58
|
+
if (url) {
|
|
59
|
+
const m = url.toString().match(/.*\/(.+?)\./);
|
|
60
|
+
if (m && m.length > 1) {
|
|
61
|
+
return m[1];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!isNull(url)) {
|
|
65
|
+
return url.split(".").shift();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return "";
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const getFileNameWithExtension = (url: string) => {
|
|
72
|
+
const _url = decodeURIComponent(url);
|
|
73
|
+
|
|
74
|
+
const m = _url.toString().match(/.*\/(.*)$/) || [];
|
|
75
|
+
|
|
76
|
+
if (typeof m != "undefined" && m?.length > 1) {
|
|
77
|
+
const a = m?.[1].split("/")?.pop() || "";
|
|
78
|
+
const b = a.split("?")?.shift();
|
|
79
|
+
return b || m?.[1] || "";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!isNull(_url)) return url;
|
|
83
|
+
|
|
84
|
+
return "";
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
* @param {string} url
|
|
90
|
+
* @return {string}
|
|
91
|
+
*/
|
|
92
|
+
export const getFileExtension = (url: string) => {
|
|
93
|
+
return getFileNameWithExtension(url).split(".").pop();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param {string} url
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export const isImage = (url: string) => {
|
|
102
|
+
const arr = ["png", "jpg", "jpeg", "jpe", "jif", "jfif", "gif", "svg"];
|
|
103
|
+
|
|
104
|
+
const index = arr.findIndex((item) => {
|
|
105
|
+
return getFileExtension(url)?.toLowerCase() == item;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return index >= 0;
|
|
109
|
+
};
|
package/dist/.DS_Store
DELETED
|
Binary file
|
package/dist/Checker.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import "./chunk-AKU6F3WT.mjs";
|
|
2
|
-
|
|
3
|
-
// src/Checker.ts
|
|
4
|
-
var isJSON = (content) => {
|
|
5
|
-
if (typeof content == "object") {
|
|
6
|
-
try {
|
|
7
|
-
content = JSON.stringify(content);
|
|
8
|
-
} catch (err) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
if (typeof content == "string") {
|
|
13
|
-
try {
|
|
14
|
-
content = JSON.parse(content);
|
|
15
|
-
} catch (err) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (typeof content != "object") {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
isJSON
|
|
26
|
-
};
|
package/dist/EventDispatcher.mjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import "./chunk-AKU6F3WT.mjs";
|
|
2
|
-
|
|
3
|
-
// src/EventDispatcher.ts
|
|
4
|
-
var EventDispatcher = class {
|
|
5
|
-
constructor() {
|
|
6
|
-
}
|
|
7
|
-
addEventListener(type, listener) {
|
|
8
|
-
if (this._listeners === void 0)
|
|
9
|
-
this._listeners = {};
|
|
10
|
-
const listeners = this._listeners;
|
|
11
|
-
if (listeners[type] === void 0) {
|
|
12
|
-
listeners[type] = [];
|
|
13
|
-
}
|
|
14
|
-
if (listeners[type].indexOf(listener) === -1) {
|
|
15
|
-
listeners[type].push(listener);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
hasEventListener(type, listener) {
|
|
19
|
-
if (this._listeners === void 0)
|
|
20
|
-
return false;
|
|
21
|
-
const listeners = this._listeners;
|
|
22
|
-
return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1;
|
|
23
|
-
}
|
|
24
|
-
removeEventListener(type, listener) {
|
|
25
|
-
if (this._listeners === void 0)
|
|
26
|
-
return;
|
|
27
|
-
const listeners = this._listeners;
|
|
28
|
-
const listenerArray = listeners[type];
|
|
29
|
-
if (listenerArray !== void 0) {
|
|
30
|
-
const index = listenerArray.indexOf(listener);
|
|
31
|
-
if (index !== -1) {
|
|
32
|
-
listenerArray.splice(index, 1);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
dispatchEvent(event) {
|
|
37
|
-
if (this._listeners === void 0)
|
|
38
|
-
return;
|
|
39
|
-
const listeners = this._listeners;
|
|
40
|
-
const listenerArray = listeners[event.type];
|
|
41
|
-
if (listenerArray !== void 0) {
|
|
42
|
-
event.target = this;
|
|
43
|
-
const array = listenerArray.slice(0);
|
|
44
|
-
for (let i = 0, l = array.length; i < l; i++) {
|
|
45
|
-
array[i].call(this, event);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
export {
|
|
51
|
-
EventDispatcher
|
|
52
|
-
};
|
package/dist/FileUpload.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import "./chunk-AKU6F3WT.mjs";
|
|
2
|
-
|
|
3
|
-
// src/FileUpload.ts
|
|
4
|
-
var logFile = "[FileUpload.js] ";
|
|
5
|
-
var FileUpload = {
|
|
6
|
-
uploadBlob(props) {
|
|
7
|
-
const { blob, url, params, onComplete, onError } = props;
|
|
8
|
-
var formData = new FormData();
|
|
9
|
-
formData.append("upload", blob, "img_" + +new Date() + ".jpg");
|
|
10
|
-
if (params) {
|
|
11
|
-
Object.keys(params).forEach((key) => {
|
|
12
|
-
var val = params[key];
|
|
13
|
-
formData.append(key, val);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
var request = new XMLHttpRequest();
|
|
17
|
-
request.open("POST", url);
|
|
18
|
-
request.send(formData);
|
|
19
|
-
request.onreadystatechange = function() {
|
|
20
|
-
if (this.readyState == 4) {
|
|
21
|
-
if (this.status == 200) {
|
|
22
|
-
var response = {};
|
|
23
|
-
try {
|
|
24
|
-
response = JSON.parse(request.response) || "";
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error(logFile, "Can't part JSON of the response");
|
|
27
|
-
}
|
|
28
|
-
var statusOfSafety = response.status || 0;
|
|
29
|
-
if (statusOfSafety == 1) {
|
|
30
|
-
console.log(logFile, "request: ", request);
|
|
31
|
-
var data = response.data || {};
|
|
32
|
-
console.log(logFile, data);
|
|
33
|
-
var _url = data["url"];
|
|
34
|
-
if (onComplete)
|
|
35
|
-
onComplete(_url);
|
|
36
|
-
} else {
|
|
37
|
-
var errMsg = "\u1EA2nh c\xF3 n\u1ED9i dung kh\xF4ng ph\xF9 h\u1EE3p.";
|
|
38
|
-
console.error(logFile, errMsg);
|
|
39
|
-
if (onError)
|
|
40
|
-
onError(errMsg);
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
var errMsg = "Upload \u1EA3nh kh\xF4ng th\xE0nh c\xF4ng!";
|
|
44
|
-
console.error(logFile, errMsg);
|
|
45
|
-
if (onError)
|
|
46
|
-
onError(errMsg);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
request.onerror = function(res) {
|
|
51
|
-
var errMsg = "Upload \u1EA3nh kh\xF4ng th\xE0nh c\xF4ng!";
|
|
52
|
-
console.error(logFile, errMsg, "=>", res);
|
|
53
|
-
if (onError)
|
|
54
|
-
onError(errMsg);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
export {
|
|
59
|
-
FileUpload
|
|
60
|
-
};
|