dff-util 1.2.8 → 1.3.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 +47 -19
- package/dist/main/const-type.d.ts +3 -8
- package/dist/main/http.d.ts +2 -2
- package/dist/main/http.js +18 -18
- package/dist/main/util.d.ts +6 -0
- package/dist/main/util.js +35 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -264,17 +264,6 @@ export type SessionUser = {
|
|
|
264
264
|
};
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
-
## ResponseType
|
|
268
|
-
|
|
269
|
-
```
|
|
270
|
-
ResponseType = {
|
|
271
|
-
status?: string | number;
|
|
272
|
-
data?: any;
|
|
273
|
-
error?: any;
|
|
274
|
-
total?: number;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
```
|
|
278
267
|
|
|
279
268
|
## SearchByLimitType
|
|
280
269
|
```
|
|
@@ -354,6 +343,9 @@ export type ResponseType = {
|
|
|
354
343
|
status?: string | number;
|
|
355
344
|
data?: any;
|
|
356
345
|
error?: any;
|
|
346
|
+
total?: number;
|
|
347
|
+
skip?: number;
|
|
348
|
+
limit?: number;
|
|
357
349
|
};
|
|
358
350
|
|
|
359
351
|
export type SearchByType = {
|
|
@@ -363,14 +355,6 @@ export type SearchByType = {
|
|
|
363
355
|
searchTerm?: string;
|
|
364
356
|
};
|
|
365
357
|
|
|
366
|
-
export type PaginationResponseType = {
|
|
367
|
-
status?: string | number;
|
|
368
|
-
data?: any;
|
|
369
|
-
error?: any;
|
|
370
|
-
total?: number;
|
|
371
|
-
skip?: number;
|
|
372
|
-
limit?: number;
|
|
373
|
-
};
|
|
374
358
|
|
|
375
359
|
export type SearchByLimitType = {
|
|
376
360
|
limit: number;
|
|
@@ -591,6 +575,50 @@ const main = async () => {
|
|
|
591
575
|
|
|
592
576
|
main();
|
|
593
577
|
|
|
578
|
+
---------------------------------------------------
|
|
579
|
+
|
|
580
|
+
// Base64
|
|
581
|
+
const text = "Hello World!";
|
|
582
|
+
const encodedBase64 = encodeBase64(text); // "SGVsbG8gV29ybGQh"
|
|
583
|
+
const decodedBase64 = decodeBase64(encodedBase64); // "Hello World!"
|
|
584
|
+
|
|
585
|
+
console.log(encodedBase64, decodedBase64);
|
|
586
|
+
|
|
587
|
+
// URL Encode/Decode
|
|
588
|
+
const url = "https://example.com/query?name=John Doe&city=New York";
|
|
589
|
+
|
|
590
|
+
// First encode
|
|
591
|
+
const encodedURL1 = encodeURL(url);
|
|
592
|
+
console.log(encodedURL1);
|
|
593
|
+
// Output: "https%3A%2F%2Fexample.com%2Fquery%3Fname%3DJohn%20Doe%26city%3DNew%20York"
|
|
594
|
+
|
|
595
|
+
// Encode again (idempotent)
|
|
596
|
+
const encodedURL2 = encodeURL(encodedURL1);
|
|
597
|
+
console.log(encodedURL2 === encodedURL1); // true ✅
|
|
598
|
+
|
|
599
|
+
// Decode
|
|
600
|
+
const decodedURL1 = decodeURL(encodedURL1);
|
|
601
|
+
console.log(decodedURL1); // "https://example.com/query?name=John Doe&city=New York"
|
|
602
|
+
|
|
603
|
+
// Decode again (idempotent)
|
|
604
|
+
const decodedURL2 = decodeURL(decodedURL1);
|
|
605
|
+
console.log(decodedURL2 === decodedURL1); // true ✅
|
|
606
|
+
|
|
607
|
+
const original = "Hello World! @#$% 😊";
|
|
608
|
+
|
|
609
|
+
// Encode
|
|
610
|
+
const safe = safeEncode(original);
|
|
611
|
+
console.log(safe);
|
|
612
|
+
// Output: "U0dWc2JHOGdWMjl5YkdRPQ%3D%3D"
|
|
613
|
+
|
|
614
|
+
// Decode
|
|
615
|
+
const decoded = safeDecode(safe);
|
|
616
|
+
console.log(decoded);
|
|
617
|
+
// Output: "Hello World! @#$% 😊"
|
|
618
|
+
|
|
619
|
+
// Multiple encode/decode calls (idempotent)
|
|
620
|
+
console.log(safeEncode(safeDecode(safe)) === safe); // true
|
|
621
|
+
|
|
594
622
|
|
|
595
623
|
|
|
596
624
|
```
|
|
@@ -23,6 +23,9 @@ export type ResponseType = {
|
|
|
23
23
|
status?: string | number;
|
|
24
24
|
data?: any;
|
|
25
25
|
error?: any;
|
|
26
|
+
total?: number;
|
|
27
|
+
skip?: number;
|
|
28
|
+
limit?: number;
|
|
26
29
|
};
|
|
27
30
|
export type SearchByType = {
|
|
28
31
|
query?: Record<string, any>;
|
|
@@ -30,14 +33,6 @@ export type SearchByType = {
|
|
|
30
33
|
order?: "ASC" | "DESC";
|
|
31
34
|
searchTerm?: string;
|
|
32
35
|
};
|
|
33
|
-
export type PaginationResponseType = {
|
|
34
|
-
status?: string | number;
|
|
35
|
-
data?: any;
|
|
36
|
-
error?: any;
|
|
37
|
-
total?: number;
|
|
38
|
-
skip?: number;
|
|
39
|
-
limit?: number;
|
|
40
|
-
};
|
|
41
36
|
export type SearchByLimitType = {
|
|
42
37
|
limit: number;
|
|
43
38
|
skip: number;
|
package/dist/main/http.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ export declare enum RespType {
|
|
|
8
8
|
export declare const HttpHeaders: {
|
|
9
9
|
'Content-Type': string;
|
|
10
10
|
authorization: null;
|
|
11
|
-
'
|
|
11
|
+
'request-id': null;
|
|
12
12
|
};
|
|
13
13
|
export declare const BaseHeaders: {
|
|
14
14
|
authorization: null;
|
|
15
|
-
'
|
|
15
|
+
'request-id': null;
|
|
16
16
|
};
|
|
17
17
|
export declare const HttpMethods: {
|
|
18
18
|
GET: string;
|
package/dist/main/http.js
CHANGED
|
@@ -22,11 +22,11 @@ var RespType;
|
|
|
22
22
|
exports.HttpHeaders = {
|
|
23
23
|
'Content-Type': 'application/json',
|
|
24
24
|
authorization: null,
|
|
25
|
-
'
|
|
25
|
+
'request-id': null,
|
|
26
26
|
};
|
|
27
27
|
exports.BaseHeaders = {
|
|
28
28
|
authorization: null,
|
|
29
|
-
'
|
|
29
|
+
'request-id': null,
|
|
30
30
|
};
|
|
31
31
|
exports.HttpMethods = {
|
|
32
32
|
GET: "GET",
|
|
@@ -69,14 +69,14 @@ class Http {
|
|
|
69
69
|
url = url.startsWith('http') ? url : Http.API_BASE_URL + url;
|
|
70
70
|
const fullUrl = params ? `${url}?${new URLSearchParams(params).toString()}` : url;
|
|
71
71
|
headers = headers || exports.HttpHeaders;
|
|
72
|
-
headers['
|
|
72
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
73
73
|
try {
|
|
74
74
|
const requestOptions = { method: 'GET', headers: headers };
|
|
75
75
|
const response = yield fetch(fullUrl, requestOptions);
|
|
76
76
|
return yield Http.RespData(response, type);
|
|
77
77
|
}
|
|
78
78
|
catch (error) {
|
|
79
|
-
throw { url: fullUrl, requestId: headers['
|
|
79
|
+
throw { url: fullUrl, requestId: headers['request-id'], error: error };
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -84,14 +84,14 @@ class Http {
|
|
|
84
84
|
return __awaiter(this, arguments, void 0, function* (url, data, headers, type = RespType.JSON) {
|
|
85
85
|
url = url.startsWith('http') ? url : Http.API_BASE_URL + url;
|
|
86
86
|
headers = headers || exports.HttpHeaders;
|
|
87
|
-
headers['
|
|
87
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
88
88
|
try {
|
|
89
89
|
const requestOptions = { method: 'POST', body: JSON.stringify(data), headers: headers };
|
|
90
90
|
const response = yield fetch(url, requestOptions);
|
|
91
91
|
return yield Http.RespData(response, type);
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
|
-
throw { url: url, requestId: headers['
|
|
94
|
+
throw { url: url, requestId: headers['request-id'], body: data, error: error };
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
}
|
|
@@ -99,14 +99,14 @@ class Http {
|
|
|
99
99
|
return __awaiter(this, arguments, void 0, function* (url, data, headers, type = RespType.JSON) {
|
|
100
100
|
url = url.startsWith('http') ? url : Http.API_BASE_URL + url;
|
|
101
101
|
headers = headers || exports.HttpHeaders;
|
|
102
|
-
headers['
|
|
102
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
103
103
|
try {
|
|
104
104
|
const requestOptions = { method: 'PUT', body: JSON.stringify(data), headers: headers };
|
|
105
105
|
const response = yield fetch(url, requestOptions);
|
|
106
106
|
return yield Http.RespData(response, type);
|
|
107
107
|
}
|
|
108
108
|
catch (error) {
|
|
109
|
-
throw { url: url, requestId: headers['
|
|
109
|
+
throw { url: url, requestId: headers['request-id'], body: data, error: error };
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
@@ -115,14 +115,14 @@ class Http {
|
|
|
115
115
|
url = url.startsWith('http') ? url : Http.API_BASE_URL + url;
|
|
116
116
|
const fullUrl = params ? `${url}?${new URLSearchParams(params).toString()}` : url;
|
|
117
117
|
headers = headers || exports.HttpHeaders;
|
|
118
|
-
headers['
|
|
118
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
119
119
|
try {
|
|
120
120
|
const requestOptions = { method: 'DELETE', headers: headers };
|
|
121
121
|
const response = yield fetch(fullUrl, requestOptions);
|
|
122
122
|
return yield Http.RespData(response, type);
|
|
123
123
|
}
|
|
124
124
|
catch (error) {
|
|
125
|
-
throw { url: fullUrl, requestId: headers['
|
|
125
|
+
throw { url: fullUrl, requestId: headers['request-id'], error: error };
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -132,14 +132,14 @@ class Http {
|
|
|
132
132
|
const params = { key: appKey, payload: JSON.stringify(sessionInfo) };
|
|
133
133
|
const fullUrl = `${url}?${new URLSearchParams(params).toString()}`;
|
|
134
134
|
const headers = Object.assign(Object.assign({}, Headers), { 'X-API-KEY': apiKey || '' });
|
|
135
|
-
headers['
|
|
135
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
136
136
|
try {
|
|
137
137
|
const requestOptions = { method: 'GET', headers: headers };
|
|
138
138
|
const response = yield fetch(fullUrl, requestOptions);
|
|
139
139
|
return yield Http.RespData(response, type);
|
|
140
140
|
}
|
|
141
141
|
catch (error) {
|
|
142
|
-
throw { url: fullUrl, requestId: headers['
|
|
142
|
+
throw { url: fullUrl, requestId: headers['request-id'], error: error };
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
}
|
|
@@ -156,7 +156,7 @@ class Http {
|
|
|
156
156
|
if (isHeadersAddMultiForm) {
|
|
157
157
|
headers = Object.assign(Object.assign({}, headers), { 'Content-Type': headers['Content-Type'] || 'multipart/form-data' });
|
|
158
158
|
}
|
|
159
|
-
headers['
|
|
159
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
160
160
|
try {
|
|
161
161
|
const requestOptions = {
|
|
162
162
|
method: method,
|
|
@@ -167,7 +167,7 @@ class Http {
|
|
|
167
167
|
return yield Http.RespData(response, type);
|
|
168
168
|
}
|
|
169
169
|
catch (error) {
|
|
170
|
-
throw { url: url, requestId: headers['
|
|
170
|
+
throw { url: url, requestId: headers['request-id'], error: error };
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
}
|
|
@@ -176,7 +176,7 @@ class Http {
|
|
|
176
176
|
headers = headers || {
|
|
177
177
|
'Content-Type': file.type,
|
|
178
178
|
};
|
|
179
|
-
headers['
|
|
179
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
180
180
|
try {
|
|
181
181
|
const requestOptions = {
|
|
182
182
|
method: method,
|
|
@@ -187,7 +187,7 @@ class Http {
|
|
|
187
187
|
return response;
|
|
188
188
|
}
|
|
189
189
|
catch (error) {
|
|
190
|
-
throw { url: fullUrl, requestId: headers['
|
|
190
|
+
throw { url: fullUrl, requestId: headers['request-id'], error: error };
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
193
|
}
|
|
@@ -195,7 +195,7 @@ class Http {
|
|
|
195
195
|
return __awaiter(this, arguments, void 0, function* (fullUrl, params, headers = exports.HttpHeaders, method = 'GET') {
|
|
196
196
|
fullUrl = params ? `${fullUrl}?${new URLSearchParams(params).toString()}` : fullUrl;
|
|
197
197
|
headers = headers || exports.HttpHeaders;
|
|
198
|
-
headers['
|
|
198
|
+
headers['request-id'] = headers['request-id'] || (0, util_1.AppUUID4)();
|
|
199
199
|
try {
|
|
200
200
|
const requestOptions = { method: method, headers: headers };
|
|
201
201
|
const response = yield fetch(fullUrl, requestOptions);
|
|
@@ -204,7 +204,7 @@ class Http {
|
|
|
204
204
|
return buffer;
|
|
205
205
|
}
|
|
206
206
|
catch (error) {
|
|
207
|
-
throw { url: fullUrl, requestId: headers['
|
|
207
|
+
throw { url: fullUrl, requestId: headers['request-id'], error: error };
|
|
208
208
|
}
|
|
209
209
|
});
|
|
210
210
|
}
|
package/dist/main/util.d.ts
CHANGED
|
@@ -14,3 +14,9 @@ export declare const TimeAgo: (date: Date) => string;
|
|
|
14
14
|
export declare const LangText: (data: string, source: string, target: string) => Promise<any>;
|
|
15
15
|
export declare const LangCountryCode: (lang: string) => LangCountryType;
|
|
16
16
|
export declare const CurrencyConvert: (from: string, to: string) => Promise<number>;
|
|
17
|
+
export declare function EncodeBase64(input: string): string;
|
|
18
|
+
export declare function DecodeBase64(encoded: string): string;
|
|
19
|
+
export declare function EncodeURL(input: string): string;
|
|
20
|
+
export declare function DecodeURL(input: string): string;
|
|
21
|
+
export declare function SafeEncode(input: string): string;
|
|
22
|
+
export declare function SafeDecode(encoded: string): string;
|
package/dist/main/util.js
CHANGED
|
@@ -10,6 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CurrencyConvert = exports.LangCountryCode = exports.LangText = exports.TimeAgo = exports.DateAndTime = exports.DateTime12HrFormat = exports.DateTime24HrFormat = exports.TruncateText = exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppCode = exports.AppCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
|
|
13
|
+
exports.EncodeBase64 = EncodeBase64;
|
|
14
|
+
exports.DecodeBase64 = DecodeBase64;
|
|
15
|
+
exports.EncodeURL = EncodeURL;
|
|
16
|
+
exports.DecodeURL = DecodeURL;
|
|
17
|
+
exports.SafeEncode = SafeEncode;
|
|
18
|
+
exports.SafeDecode = SafeDecode;
|
|
13
19
|
const randomstring_1 = require("randomstring");
|
|
14
20
|
const reg_exr_1 = require("./reg-exr");
|
|
15
21
|
const countries_1 = require("./countries");
|
|
@@ -216,3 +222,32 @@ const CurrencyConvert = (from, to) => __awaiter(void 0, void 0, void 0, function
|
|
|
216
222
|
}
|
|
217
223
|
});
|
|
218
224
|
exports.CurrencyConvert = CurrencyConvert;
|
|
225
|
+
function EncodeBase64(input) {
|
|
226
|
+
return Buffer.from(input, 'utf-8').toString('base64');
|
|
227
|
+
}
|
|
228
|
+
function DecodeBase64(encoded) {
|
|
229
|
+
return Buffer.from(encoded, 'base64').toString('utf-8');
|
|
230
|
+
}
|
|
231
|
+
function EncodeURL(input) {
|
|
232
|
+
try {
|
|
233
|
+
const decoded = decodeURIComponent(input);
|
|
234
|
+
return encodeURIComponent(decoded);
|
|
235
|
+
}
|
|
236
|
+
catch (_a) {
|
|
237
|
+
return encodeURIComponent(input);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function DecodeURL(input) {
|
|
241
|
+
try {
|
|
242
|
+
return decodeURIComponent(input);
|
|
243
|
+
}
|
|
244
|
+
catch (_a) {
|
|
245
|
+
return input;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function SafeEncode(input) {
|
|
249
|
+
return EncodeURL(EncodeBase64(input));
|
|
250
|
+
}
|
|
251
|
+
function SafeDecode(encoded) {
|
|
252
|
+
return DecodeBase64(DecodeURL(encoded));
|
|
253
|
+
}
|
package/package.json
CHANGED