diginext-utils 2.1.20 → 2.1.21
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 +8 -8
- package/dist/Checker.js +31 -31
- package/dist/EventDispatcher.d.ts +13 -13
- package/dist/EventDispatcher.js +51 -51
- package/dist/FileUpload.d.ts +12 -12
- package/dist/FileUpload.js +64 -64
- package/dist/Slug.d.ts +9 -9
- package/dist/Slug.js +333 -333
- package/dist/Timer.d.ts +4 -4
- package/dist/Timer.js +8 -8
- package/dist/Validation.d.ts +5 -5
- package/dist/Validation.js +38 -38
- package/dist/array.d.ts +113 -113
- package/dist/array.js +297 -297
- package/dist/color.d.ts +25 -25
- package/dist/color.js +95 -95
- package/dist/console/enableConsole.d.ts +2 -2
- package/dist/console/enableConsole.js +13 -13
- package/dist/console/index.d.ts +11 -11
- package/dist/console/index.js +17 -17
- package/dist/console/log.d.ts +15 -15
- package/dist/console/log.js +44 -44
- package/dist/device/browser.d.ts +5 -5
- package/dist/device/browser.js +37 -37
- package/dist/device/camera.d.ts +7 -7
- package/dist/device/camera.js +171 -171
- package/dist/device/index.d.ts +5 -5
- package/dist/device/index.js +224 -224
- package/dist/device/os.d.ts +11 -11
- package/dist/device/os.js +37 -37
- package/dist/file/createDir.d.ts +5 -5
- package/dist/file/createDir.js +15 -15
- package/dist/file/fileMove.d.ts +4 -4
- package/dist/file/fileMove.js +32 -32
- package/dist/file/findFilesByExt.d.ts +13 -13
- package/dist/file/findFilesByExt.js +49 -49
- package/dist/file/getAllFiles.d.ts +1 -0
- package/dist/file/getAllFiles.js +27 -0
- package/dist/file/getAllFiles.js.map +1 -0
- package/dist/file/index.d.ts +9 -9
- package/dist/file/index.js +10 -10
- package/dist/gameboi/index.d.ts +10 -10
- package/dist/gameboi/index.js +67 -64
- package/dist/gameboi/index.js.map +1 -1
- package/dist/images/downloadByUrl.d.ts +1 -1
- package/dist/images/downloadByUrl.js +55 -55
- package/dist/images/index.d.ts +2 -2
- package/dist/images/index.js +8 -8
- package/dist/images/loadImage.d.ts +1 -1
- package/dist/images/loadImage.js +17 -17
- package/dist/images/resize.d.ts +2 -2
- package/dist/images/resize.js +37 -37
- package/dist/images/upload.d.ts +10 -10
- package/dist/images/upload.js +26 -26
- package/dist/index.d.ts +37 -37
- package/dist/index.js +62 -62
- package/dist/json.d.ts +8 -8
- package/dist/json.js +31 -31
- package/dist/math/diffDate.d.ts +5 -5
- package/dist/math/diffDate.js +13 -13
- package/dist/math/index.d.ts +30 -30
- package/dist/math/index.js +92 -92
- package/dist/math/positiveNumber.d.ts +2 -2
- package/dist/math/positiveNumber.js +16 -16
- package/dist/name/en.d.ts +5 -5
- package/dist/name/en.js +25 -25
- package/dist/name/index.d.ts +12 -12
- package/dist/name/index.js +12 -12
- package/dist/name/vi.d.ts +5 -5
- package/dist/name/vi.js +27 -27
- package/dist/object.d.ts +59 -59
- package/dist/object.js +79 -79
- package/dist/permission/index.d.ts +8 -8
- package/dist/permission/index.js +6 -6
- package/dist/permission/requestCamera.d.ts +5 -5
- package/dist/permission/requestCamera.js +42 -42
- package/dist/permission/requestDeviceOrientationControl.d.ts +2 -2
- package/dist/permission/requestDeviceOrientationControl.js +38 -38
- package/dist/response/index.d.ts +49 -49
- package/dist/response/index.js +51 -51
- package/dist/string/convertPathnameAndQuery.d.ts +4 -4
- package/dist/string/convertPathnameAndQuery.js +24 -24
- package/dist/string/formatNumber.d.ts +6 -6
- package/dist/string/formatNumber.js +14 -14
- package/dist/string/generatePassword.d.ts +9 -9
- package/dist/string/generatePassword.js +23 -23
- package/dist/string/generateUUID.d.ts +2 -2
- package/dist/string/generateUUID.js +36 -36
- package/dist/string/getTextBetweenCharByIndex.d.ts +1 -1
- package/dist/string/getTextBetweenCharByIndex.js +20 -20
- package/dist/string/index.d.ts +65 -65
- package/dist/string/index.js +161 -161
- package/dist/string/indexesOf.d.ts +1 -1
- package/dist/string/indexesOf.js +14 -14
- package/dist/string/makeDaySlug.d.ts +31 -31
- package/dist/string/makeDaySlug.js +22 -22
- package/dist/string/random.d.ts +18 -18
- package/dist/string/random.js +40 -40
- package/dist/string/trimNull.d.ts +2 -2
- package/dist/string/trimNull.js +20 -20
- package/dist/string/url.d.ts +22 -22
- package/dist/string/url.js +74 -74
- package/esm/Checker.d.ts +8 -8
- package/esm/Checker.js +27 -27
- package/esm/EventDispatcher.d.ts +13 -13
- package/esm/EventDispatcher.js +48 -48
- package/esm/FileUpload.d.ts +12 -12
- package/esm/FileUpload.js +61 -61
- package/esm/Slug.d.ts +9 -9
- package/esm/Slug.js +329 -329
- package/esm/Timer.d.ts +4 -4
- package/esm/Timer.js +6 -6
- package/esm/Validation.d.ts +5 -5
- package/esm/Validation.js +36 -36
- package/esm/array.d.ts +113 -113
- package/esm/array.js +275 -275
- package/esm/color.d.ts +25 -25
- package/esm/color.js +85 -85
- package/esm/console/enableConsole.d.ts +2 -2
- package/esm/console/enableConsole.js +6 -6
- package/esm/console/index.d.ts +11 -11
- package/esm/console/index.js +12 -12
- package/esm/console/log.d.ts +15 -15
- package/esm/console/log.js +32 -32
- package/esm/device/browser.d.ts +5 -5
- package/esm/device/browser.js +29 -29
- package/esm/device/camera.d.ts +7 -7
- package/esm/device/camera.js +167 -167
- package/esm/device/index.d.ts +5 -5
- package/esm/device/index.js +216 -216
- package/esm/device/os.d.ts +11 -11
- package/esm/device/os.js +27 -27
- package/esm/file/createDir.d.ts +5 -5
- package/esm/file/createDir.js +12 -12
- package/esm/file/fileMove.d.ts +4 -4
- package/esm/file/fileMove.js +28 -28
- package/esm/file/findFilesByExt.d.ts +13 -13
- package/esm/file/findFilesByExt.js +45 -45
- package/esm/file/getAllFiles.d.ts +1 -0
- package/esm/file/getAllFiles.js +21 -0
- package/esm/file/getAllFiles.js.map +1 -0
- package/esm/file/index.d.ts +9 -9
- package/esm/file/index.js +5 -5
- package/esm/gameboi/index.d.ts +10 -10
- package/esm/gameboi/index.js +61 -61
- package/esm/gameboi/index.js.map +1 -1
- package/esm/images/downloadByUrl.d.ts +1 -1
- package/esm/images/downloadByUrl.js +52 -52
- package/esm/images/index.d.ts +2 -2
- package/esm/images/index.js +3 -3
- package/esm/images/loadImage.d.ts +1 -1
- package/esm/images/loadImage.js +14 -14
- package/esm/images/resize.d.ts +2 -2
- package/esm/images/resize.js +30 -30
- package/esm/images/upload.d.ts +10 -10
- package/esm/images/upload.js +19 -19
- package/esm/index.d.ts +37 -37
- package/esm/index.js +37 -37
- package/esm/json.d.ts +8 -8
- package/esm/json.js +27 -27
- package/esm/math/diffDate.d.ts +5 -5
- package/esm/math/diffDate.js +9 -9
- package/esm/math/index.d.ts +30 -30
- package/esm/math/index.js +77 -77
- package/esm/math/positiveNumber.d.ts +2 -2
- package/esm/math/positiveNumber.js +12 -12
- package/esm/name/en.d.ts +5 -5
- package/esm/name/en.js +21 -21
- package/esm/name/index.d.ts +12 -12
- package/esm/name/index.js +5 -5
- package/esm/name/vi.d.ts +5 -5
- package/esm/name/vi.js +23 -23
- package/esm/object.d.ts +59 -59
- package/esm/object.js +69 -69
- package/esm/permission/index.d.ts +8 -8
- package/esm/permission/index.js +4 -4
- package/esm/permission/requestCamera.d.ts +5 -5
- package/esm/permission/requestCamera.js +38 -38
- package/esm/permission/requestDeviceOrientationControl.d.ts +2 -2
- package/esm/permission/requestDeviceOrientationControl.js +34 -34
- package/esm/response/index.d.ts +49 -49
- package/esm/response/index.js +45 -45
- package/esm/string/convertPathnameAndQuery.d.ts +4 -4
- package/esm/string/convertPathnameAndQuery.js +21 -21
- package/esm/string/formatNumber.d.ts +6 -6
- package/esm/string/formatNumber.js +10 -10
- package/esm/string/generatePassword.d.ts +9 -9
- package/esm/string/generatePassword.js +19 -19
- package/esm/string/generateUUID.d.ts +2 -2
- package/esm/string/generateUUID.js +32 -32
- package/esm/string/getTextBetweenCharByIndex.d.ts +1 -1
- package/esm/string/getTextBetweenCharByIndex.js +14 -14
- package/esm/string/index.d.ts +65 -65
- package/esm/string/index.js +150 -150
- package/esm/string/indexesOf.d.ts +1 -1
- package/esm/string/indexesOf.js +11 -11
- package/esm/string/makeDaySlug.d.ts +31 -31
- package/esm/string/makeDaySlug.js +15 -15
- package/esm/string/random.d.ts +18 -18
- package/esm/string/random.js +33 -33
- package/esm/string/trimNull.d.ts +2 -2
- package/esm/string/trimNull.js +13 -13
- package/esm/string/url.d.ts +22 -22
- package/esm/string/url.js +64 -64
- package/package.json +4 -4
package/dist/Checker.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if the object or string is in JSON format
|
|
3
|
-
*/
|
|
4
|
-
export declare const isJSON: (content: object | string) => boolean;
|
|
5
|
-
declare const Checker: {
|
|
6
|
-
isJSON: (content: object | string) => boolean;
|
|
7
|
-
};
|
|
8
|
-
export default Checker;
|
|
1
|
+
/**
|
|
2
|
+
* Check if the object or string is in JSON format
|
|
3
|
+
*/
|
|
4
|
+
export declare const isJSON: (content: object | string) => boolean;
|
|
5
|
+
declare const Checker: {
|
|
6
|
+
isJSON: (content: object | string) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export default Checker;
|
package/dist/Checker.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isJSON = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Check if the object or string is in JSON format
|
|
6
|
-
*/
|
|
7
|
-
const isJSON = (content) => {
|
|
8
|
-
if (typeof content == "object") {
|
|
9
|
-
try {
|
|
10
|
-
content = JSON.stringify(content);
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (typeof content == "string") {
|
|
17
|
-
try {
|
|
18
|
-
content = JSON.parse(content);
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (typeof content != "object") {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
};
|
|
29
|
-
exports.isJSON = isJSON;
|
|
30
|
-
const Checker = { isJSON: exports.isJSON };
|
|
31
|
-
exports.default = Checker;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isJSON = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if the object or string is in JSON format
|
|
6
|
+
*/
|
|
7
|
+
const isJSON = (content) => {
|
|
8
|
+
if (typeof content == "object") {
|
|
9
|
+
try {
|
|
10
|
+
content = JSON.stringify(content);
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (typeof content == "string") {
|
|
17
|
+
try {
|
|
18
|
+
content = JSON.parse(content);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (typeof content != "object") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
exports.isJSON = isJSON;
|
|
30
|
+
const Checker = { isJSON: exports.isJSON };
|
|
31
|
+
exports.default = Checker;
|
|
32
32
|
//# sourceMappingURL=Checker.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
declare class EventDispatcher {
|
|
2
|
-
constructor();
|
|
3
|
-
_listeners: any;
|
|
4
|
-
addEventListener(type: string, listener: any): void;
|
|
5
|
-
hasEventListener(type: string, listener: any): boolean;
|
|
6
|
-
removeEventListener(type: string, listener: any): void;
|
|
7
|
-
dispatchEvent(event: {
|
|
8
|
-
type: string;
|
|
9
|
-
target: any;
|
|
10
|
-
}): void;
|
|
11
|
-
}
|
|
12
|
-
export { EventDispatcher };
|
|
13
|
-
export default EventDispatcher;
|
|
1
|
+
declare class EventDispatcher {
|
|
2
|
+
constructor();
|
|
3
|
+
_listeners: any;
|
|
4
|
+
addEventListener(type: string, listener: any): void;
|
|
5
|
+
hasEventListener(type: string, listener: any): boolean;
|
|
6
|
+
removeEventListener(type: string, listener: any): void;
|
|
7
|
+
dispatchEvent(event: {
|
|
8
|
+
type: string;
|
|
9
|
+
target: any;
|
|
10
|
+
}): void;
|
|
11
|
+
}
|
|
12
|
+
export { EventDispatcher };
|
|
13
|
+
export default EventDispatcher;
|
package/dist/EventDispatcher.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventDispatcher = void 0;
|
|
4
|
-
class EventDispatcher {
|
|
5
|
-
constructor() { }
|
|
6
|
-
addEventListener(type, listener) {
|
|
7
|
-
if (this._listeners === undefined)
|
|
8
|
-
this._listeners = {};
|
|
9
|
-
const listeners = this._listeners;
|
|
10
|
-
if (listeners[type] === undefined) {
|
|
11
|
-
listeners[type] = [];
|
|
12
|
-
}
|
|
13
|
-
if (listeners[type].indexOf(listener) === -1) {
|
|
14
|
-
listeners[type].push(listener);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
hasEventListener(type, listener) {
|
|
18
|
-
if (this._listeners === undefined)
|
|
19
|
-
return false;
|
|
20
|
-
const listeners = this._listeners;
|
|
21
|
-
return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
|
|
22
|
-
}
|
|
23
|
-
removeEventListener(type, listener) {
|
|
24
|
-
if (this._listeners === undefined)
|
|
25
|
-
return;
|
|
26
|
-
const listeners = this._listeners;
|
|
27
|
-
const listenerArray = listeners[type];
|
|
28
|
-
if (listenerArray !== undefined) {
|
|
29
|
-
const index = listenerArray.indexOf(listener);
|
|
30
|
-
if (index !== -1) {
|
|
31
|
-
listenerArray.splice(index, 1);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
dispatchEvent(event) {
|
|
36
|
-
if (this._listeners === undefined)
|
|
37
|
-
return;
|
|
38
|
-
const listeners = this._listeners;
|
|
39
|
-
const listenerArray = listeners[event.type];
|
|
40
|
-
if (listenerArray !== undefined) {
|
|
41
|
-
event.target = this;
|
|
42
|
-
// Make a copy, in case listeners are removed while iterating.
|
|
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
|
-
exports.EventDispatcher = EventDispatcher;
|
|
51
|
-
exports.default = EventDispatcher;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventDispatcher = void 0;
|
|
4
|
+
class EventDispatcher {
|
|
5
|
+
constructor() { }
|
|
6
|
+
addEventListener(type, listener) {
|
|
7
|
+
if (this._listeners === undefined)
|
|
8
|
+
this._listeners = {};
|
|
9
|
+
const listeners = this._listeners;
|
|
10
|
+
if (listeners[type] === undefined) {
|
|
11
|
+
listeners[type] = [];
|
|
12
|
+
}
|
|
13
|
+
if (listeners[type].indexOf(listener) === -1) {
|
|
14
|
+
listeners[type].push(listener);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
hasEventListener(type, listener) {
|
|
18
|
+
if (this._listeners === undefined)
|
|
19
|
+
return false;
|
|
20
|
+
const listeners = this._listeners;
|
|
21
|
+
return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
|
|
22
|
+
}
|
|
23
|
+
removeEventListener(type, listener) {
|
|
24
|
+
if (this._listeners === undefined)
|
|
25
|
+
return;
|
|
26
|
+
const listeners = this._listeners;
|
|
27
|
+
const listenerArray = listeners[type];
|
|
28
|
+
if (listenerArray !== undefined) {
|
|
29
|
+
const index = listenerArray.indexOf(listener);
|
|
30
|
+
if (index !== -1) {
|
|
31
|
+
listenerArray.splice(index, 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
dispatchEvent(event) {
|
|
36
|
+
if (this._listeners === undefined)
|
|
37
|
+
return;
|
|
38
|
+
const listeners = this._listeners;
|
|
39
|
+
const listenerArray = listeners[event.type];
|
|
40
|
+
if (listenerArray !== undefined) {
|
|
41
|
+
event.target = this;
|
|
42
|
+
// Make a copy, in case listeners are removed while iterating.
|
|
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
|
+
exports.EventDispatcher = EventDispatcher;
|
|
51
|
+
exports.default = EventDispatcher;
|
|
52
52
|
//# sourceMappingURL=EventDispatcher.js.map
|
package/dist/FileUpload.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
type UploadParams = {
|
|
2
|
-
blob: Blob;
|
|
3
|
-
url: string;
|
|
4
|
-
params: any;
|
|
5
|
-
onComplete: any;
|
|
6
|
-
onError: any;
|
|
7
|
-
};
|
|
8
|
-
declare const FileUpload: {
|
|
9
|
-
uploadBlob(props: UploadParams): void;
|
|
10
|
-
};
|
|
11
|
-
export { FileUpload };
|
|
12
|
-
export default FileUpload;
|
|
1
|
+
type UploadParams = {
|
|
2
|
+
blob: Blob;
|
|
3
|
+
url: string;
|
|
4
|
+
params: any;
|
|
5
|
+
onComplete: any;
|
|
6
|
+
onError: any;
|
|
7
|
+
};
|
|
8
|
+
declare const FileUpload: {
|
|
9
|
+
uploadBlob(props: UploadParams): void;
|
|
10
|
+
};
|
|
11
|
+
export { FileUpload };
|
|
12
|
+
export default FileUpload;
|
package/dist/FileUpload.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileUpload = void 0;
|
|
4
|
-
var logFile = "[FileUpload.js] ";
|
|
5
|
-
const 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
|
-
// Typical action to be performed when the document is ready:
|
|
22
|
-
if (this.status == 200) {
|
|
23
|
-
// var response = JSON.parse(request.response) || "";
|
|
24
|
-
var response = {};
|
|
25
|
-
try {
|
|
26
|
-
response = JSON.parse(request.response) || "";
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error(logFile, "Can't part JSON of the response");
|
|
30
|
-
}
|
|
31
|
-
var statusOfSafety = response.status || 0;
|
|
32
|
-
if (statusOfSafety == 1) {
|
|
33
|
-
console.log(logFile, "request: ", request);
|
|
34
|
-
var data = response.data || {};
|
|
35
|
-
console.log(logFile, data);
|
|
36
|
-
var _url = data["url"];
|
|
37
|
-
if (onComplete)
|
|
38
|
-
onComplete(_url);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
var errMsg = "Ảnh có nội dung không phù hợp.";
|
|
42
|
-
console.error(logFile, errMsg);
|
|
43
|
-
if (onError)
|
|
44
|
-
onError(errMsg);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
var errMsg = "Upload ảnh không thành công!";
|
|
49
|
-
console.error(logFile, errMsg);
|
|
50
|
-
if (onError)
|
|
51
|
-
onError(errMsg);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
request.onerror = function (res) {
|
|
56
|
-
var errMsg = "Upload ảnh không thành công!";
|
|
57
|
-
console.error(logFile, errMsg, "=>", res);
|
|
58
|
-
if (onError)
|
|
59
|
-
onError(errMsg);
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
exports.FileUpload = FileUpload;
|
|
64
|
-
exports.default = FileUpload;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileUpload = void 0;
|
|
4
|
+
var logFile = "[FileUpload.js] ";
|
|
5
|
+
const 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
|
+
// Typical action to be performed when the document is ready:
|
|
22
|
+
if (this.status == 200) {
|
|
23
|
+
// var response = JSON.parse(request.response) || "";
|
|
24
|
+
var response = {};
|
|
25
|
+
try {
|
|
26
|
+
response = JSON.parse(request.response) || "";
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(logFile, "Can't part JSON of the response");
|
|
30
|
+
}
|
|
31
|
+
var statusOfSafety = response.status || 0;
|
|
32
|
+
if (statusOfSafety == 1) {
|
|
33
|
+
console.log(logFile, "request: ", request);
|
|
34
|
+
var data = response.data || {};
|
|
35
|
+
console.log(logFile, data);
|
|
36
|
+
var _url = data["url"];
|
|
37
|
+
if (onComplete)
|
|
38
|
+
onComplete(_url);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
var errMsg = "Ảnh có nội dung không phù hợp.";
|
|
42
|
+
console.error(logFile, errMsg);
|
|
43
|
+
if (onError)
|
|
44
|
+
onError(errMsg);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
var errMsg = "Upload ảnh không thành công!";
|
|
49
|
+
console.error(logFile, errMsg);
|
|
50
|
+
if (onError)
|
|
51
|
+
onError(errMsg);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
request.onerror = function (res) {
|
|
56
|
+
var errMsg = "Upload ảnh không thành công!";
|
|
57
|
+
console.error(logFile, errMsg, "=>", res);
|
|
58
|
+
if (onError)
|
|
59
|
+
onError(errMsg);
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
exports.FileUpload = FileUpload;
|
|
64
|
+
exports.default = FileUpload;
|
|
65
65
|
//# sourceMappingURL=FileUpload.js.map
|
package/dist/Slug.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const makeSlug: (s: string, opt?: {
|
|
2
|
-
[key: string]: any;
|
|
3
|
-
}) => string;
|
|
4
|
-
declare const slug: {
|
|
5
|
-
makeSlug: (s: string, opt?: {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}) => string;
|
|
8
|
-
};
|
|
9
|
-
export default slug;
|
|
1
|
+
export declare const makeSlug: (s: string, opt?: {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}) => string;
|
|
4
|
+
declare const slug: {
|
|
5
|
+
makeSlug: (s: string, opt?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}) => string;
|
|
8
|
+
};
|
|
9
|
+
export default slug;
|