Skip to content

Commit 008fd7c

Browse files
committed
Add text manipulation options to encrypt and decrypt functions
1 parent 0985d03 commit 008fd7c

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

dist/cjs/functions/decrypt.js

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ function decrypt() {
6161
case 1:
6262
decryptedTexts = _a.sent();
6363
results = decryptedTexts.map(function (text) { return text.result; });
64+
if (options === null || options === void 0 ? void 0 : options.trim) {
65+
results = results.map(function (result) { return result.trim(); });
66+
}
67+
if (options === null || options === void 0 ? void 0 : options.toLowerCase) {
68+
results = results.map(function (result) { return result.toLowerCase(); });
69+
}
70+
if (options === null || options === void 0 ? void 0 : options.toUpperCase) {
71+
results = results.map(function (result) { return result.toUpperCase(); });
72+
}
6473
return [2 /*return*/, (options === null || options === void 0 ? void 0 : options.returnArray) ? results : results.join("\n")];
6574
}
6675
});

dist/cjs/functions/encrypt.js

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ function encrypt() {
4848
case 0:
4949
texts = args.filter(function (arg) { return typeof arg === "string"; });
5050
options = args.find(function (arg) { return typeof arg === "object"; });
51+
if (options === null || options === void 0 ? void 0 : options.trim) {
52+
texts = texts.map(function (text) { return text.trim(); });
53+
}
54+
if (options === null || options === void 0 ? void 0 : options.toLowerCase) {
55+
texts = texts.map(function (text) { return text.toLowerCase(); });
56+
}
57+
if (options === null || options === void 0 ? void 0 : options.toUpperCase) {
58+
texts = texts.map(function (text) { return text.toUpperCase(); });
59+
}
5160
requests = texts.map(function (text) {
5261
return fetch("https://supercryptjs-api-v2.binaryblazer.me/api/encrypt", {
5362
method: "POST",

dist/esm/functions/decrypt.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ async function decrypt(...args) {
1111
},
1212
}).then((res) => res.json()));
1313
const decryptedTexts = await Promise.all(requests);
14-
const results = decryptedTexts.map((text) => text.result);
14+
let results = decryptedTexts.map((text) => text.result);
15+
if (options?.trim) {
16+
results = results.map((result) => result.trim());
17+
}
18+
if (options?.toLowerCase) {
19+
results = results.map((result) => result.toLowerCase());
20+
}
21+
if (options?.toUpperCase) {
22+
results = results.map((result) => result.toUpperCase());
23+
}
1524
return options?.returnArray ? results : results.join("\n");
1625
}
1726
exports.default = decrypt;

dist/esm/functions/encrypt.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
async function encrypt(...args) {
4-
const texts = args.filter((arg) => typeof arg === "string");
4+
let texts = args.filter((arg) => typeof arg === "string");
55
const options = args.find((arg) => typeof arg === "object");
6+
if (options?.trim) {
7+
texts = texts.map((text) => text.trim());
8+
}
9+
if (options?.toLowerCase) {
10+
texts = texts.map((text) => text.toLowerCase());
11+
}
12+
if (options?.toUpperCase) {
13+
texts = texts.map((text) => text.toUpperCase());
14+
}
615
const requests = texts.map((text) => fetch("https://supercryptjs-api-v2.binaryblazer.me/api/encrypt", {
716
method: "POST",
817
body: JSON.stringify({ text }),

src/functions/decrypt.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
interface DecryptOptions {
22
returnArray?: boolean;
3+
trim?: boolean;
4+
toLowerCase?: boolean;
5+
toUpperCase?: boolean;
36
}
47

58
async function decrypt(...args: (string | DecryptOptions)[]) {
@@ -19,7 +22,19 @@ async function decrypt(...args: (string | DecryptOptions)[]) {
1922
);
2023

2124
const decryptedTexts = await Promise.all(requests);
22-
const results = decryptedTexts.map((text) => text.result);
25+
let results = decryptedTexts.map((text) => text.result);
26+
27+
if (options?.trim) {
28+
results = results.map((result) => result.trim());
29+
}
30+
31+
if (options?.toLowerCase) {
32+
results = results.map((result) => result.toLowerCase());
33+
}
34+
35+
if (options?.toUpperCase) {
36+
results = results.map((result) => result.toUpperCase());
37+
}
2338

2439
return options?.returnArray ? results : results.join("\n");
2540
}

src/functions/encrypt.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
interface EncryptOptions {
22
returnArray?: boolean;
3+
trim?: boolean;
4+
toLowerCase?: boolean;
5+
toUpperCase?: boolean;
36
}
47

58
async function encrypt(...args: (string | EncryptOptions)[]) {
6-
const texts = args.filter((arg) => typeof arg === "string") as string[];
9+
let texts = args.filter((arg) => typeof arg === "string") as string[];
710
const options = args.find((arg) => typeof arg === "object") as
811
| EncryptOptions
912
| undefined;
1013

14+
if (options?.trim) {
15+
texts = texts.map((text) => text.trim());
16+
}
17+
18+
if (options?.toLowerCase) {
19+
texts = texts.map((text) => text.toLowerCase());
20+
}
21+
22+
if (options?.toUpperCase) {
23+
texts = texts.map((text) => text.toUpperCase());
24+
}
25+
1126
const requests = texts.map((text) =>
1227
fetch("https://supercryptjs-api-v2.binaryblazer.me/api/encrypt", {
1328
method: "POST",

0 commit comments

Comments
 (0)