@zuzjs/core 0.1.4 → 0.1.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/index.d.ts +1 -1
- package/dist/index.js +60 -27
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const isHslColor: (color: string) => boolean;
|
|
|
17
17
|
export declare const isColor: (color: string) => boolean;
|
|
18
18
|
export declare const hexToRgba: (hex: string, alpha?: number) => string;
|
|
19
19
|
export declare const removeDuplicates: <T>(array: T[]) => T[];
|
|
20
|
-
export declare const withPost: <T>(uri: string, data: dynamicObject | FormData, timeout?: number, ignoreKind?: boolean, onProgress?: (ev: AxiosProgressEvent) => void) => Promise<T>;
|
|
20
|
+
export declare const withPost: <T>(uri: string, data: dynamicObject | FormData | string, timeout?: number, ignoreKind?: boolean, headers?: dynamicObject, onProgress?: (ev: AxiosProgressEvent) => void) => Promise<T>;
|
|
21
21
|
export declare const withGet: <T>(uri: string, timeout?: number, ignoreKind?: boolean) => Promise<T>;
|
|
22
22
|
export declare const withTime: (fun: (...args: any[]) => any) => {
|
|
23
23
|
result: any;
|
package/dist/index.js
CHANGED
|
@@ -11,9 +11,10 @@ const md5_1 = __importDefault(require("md5"));
|
|
|
11
11
|
const moment_1 = __importDefault(require("moment"));
|
|
12
12
|
const regexps_1 = require("./regexps");
|
|
13
13
|
const types_1 = require("./types");
|
|
14
|
+
const withGlobals_1 = __importDefault(require("./withGlobals"));
|
|
14
15
|
exports.__SALT = `zuzjs-core`;
|
|
15
|
-
var
|
|
16
|
-
Object.defineProperty(exports, "_", { enumerable: true, get: function () { return __importDefault(
|
|
16
|
+
var withGlobals_2 = require("./withGlobals");
|
|
17
|
+
Object.defineProperty(exports, "_", { enumerable: true, get: function () { return __importDefault(withGlobals_2).default; } });
|
|
17
18
|
const numberInRange = (min, max) => {
|
|
18
19
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
19
20
|
};
|
|
@@ -75,7 +76,7 @@ const removeDuplicates = (array) => {
|
|
|
75
76
|
}, []);
|
|
76
77
|
};
|
|
77
78
|
exports.removeDuplicates = removeDuplicates;
|
|
78
|
-
const withPost = async (uri, data, timeout = 60, ignoreKind = false, onProgress) => {
|
|
79
|
+
const withPost = async (uri, data, timeout = 60, ignoreKind = false, headers, onProgress) => {
|
|
79
80
|
const _cookies = js_cookie_1.default.get();
|
|
80
81
|
if (data instanceof FormData) {
|
|
81
82
|
for (const c in _cookies) {
|
|
@@ -89,6 +90,7 @@ const withPost = async (uri, data, timeout = 60, ignoreKind = false, onProgress)
|
|
|
89
90
|
timeout: timeout * 1000,
|
|
90
91
|
headers: {
|
|
91
92
|
'Content-Type': 'multipart/form-data',
|
|
93
|
+
...(headers || {})
|
|
92
94
|
},
|
|
93
95
|
onUploadProgress: ev => onProgress && onProgress(ev)
|
|
94
96
|
})
|
|
@@ -103,31 +105,62 @@ const withPost = async (uri, data, timeout = 60, ignoreKind = false, onProgress)
|
|
|
103
105
|
.catch(err => reject(err));
|
|
104
106
|
});
|
|
105
107
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
reject(err.code && err.code == `ERR_NETWORK` ? { error: err.code, message: navigator.onLine ? `Unable to connect to the server. It may be temporarily down.` : `Network error: Unable to connect. Please check your internet connection and try again.` } : err);
|
|
108
|
+
else if ((0, withGlobals_1.default)(data).isString()) {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
axios_1.default.post(uri, data, {
|
|
111
|
+
timeout: 1000 * timeout,
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
...(headers || {})
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
.then(resp => {
|
|
118
|
+
if (resp.data && (ignoreKind || ("kind" in resp.data))) {
|
|
119
|
+
resolve(resp.data);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
reject(resp.data);
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.catch(err => {
|
|
126
|
+
if (err?.response?.data)
|
|
127
|
+
reject(err.response.data);
|
|
128
|
+
else
|
|
129
|
+
reject(err.code && err.code == `ERR_NETWORK` ? { error: err.code, message: navigator.onLine ? `Unable to connect to the server. It may be temporarily down.` : `Network error: Unable to connect. Please check your internet connection and try again.` } : err);
|
|
130
|
+
});
|
|
130
131
|
});
|
|
132
|
+
}
|
|
133
|
+
else if (typeof data === "object" && !Array.isArray(data) && data !== null) {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
axios_1.default.post(uri, {
|
|
136
|
+
...data,
|
|
137
|
+
..._cookies,
|
|
138
|
+
__stmp: new Date().getTime() / 1000
|
|
139
|
+
}, {
|
|
140
|
+
timeout: 1000 * timeout,
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
...(headers || {})
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
.then(resp => {
|
|
147
|
+
if (resp.data && (ignoreKind || ("kind" in resp.data))) {
|
|
148
|
+
resolve(resp.data);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
reject(resp.data);
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
.catch(err => {
|
|
155
|
+
if (err?.response?.data)
|
|
156
|
+
reject(err.response.data);
|
|
157
|
+
else
|
|
158
|
+
reject(err.code && err.code == `ERR_NETWORK` ? { error: err.code, message: navigator.onLine ? `Unable to connect to the server. It may be temporarily down.` : `Network error: Unable to connect. Please check your internet connection and try again.` } : err);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
reject();
|
|
131
164
|
});
|
|
132
165
|
};
|
|
133
166
|
exports.withPost = withPost;
|