dff-util 1.2.9 → 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 +44 -0
- package/dist/main/util.d.ts +6 -0
- package/dist/main/util.js +35 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -575,6 +575,50 @@ const main = async () => {
|
|
|
575
575
|
|
|
576
576
|
main();
|
|
577
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
|
+
|
|
578
622
|
|
|
579
623
|
|
|
580
624
|
```
|
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