Skip to content

Commit aba3def

Browse files
committed
Refactor encryption and decryption functions and added esm and cjs compiling
1 parent abe59e6 commit aba3def

16 files changed

+138
-28
lines changed

.vscode/settings.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"github-actions.workflows.pinned.workflows": [
3-
".github/workflows/npm-publish.yml"
4-
]
5-
}
2+
"github-actions.workflows.pinned.workflows": [
3+
".github/workflows/npm-publish.yml"
4+
]
5+
}

dist/functions/decrypt.js renamed to dist/cjs/functions/decrypt.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,7 +35,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
3435
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
3536
}
3637
};
37-
export default function decrypt(_a) {
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
function Decrypt(_a) {
3840
return __awaiter(this, arguments, void 0, function (_b) {
3941
var decryptedText;
4042
var encryption = _b.encryption;
@@ -54,3 +56,4 @@ export default function decrypt(_a) {
5456
});
5557
});
5658
}
59+
exports.default = Decrypt;

dist/functions/encrypt.js renamed to dist/cjs/functions/encrypt.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,7 +35,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
3435
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
3536
}
3637
};
37-
export default function encrypt(_a) {
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
function Encrypt(_a) {
3840
return __awaiter(this, arguments, void 0, function (_b) {
3941
var encryptedText;
4042
var text = _b.text;
@@ -54,3 +56,4 @@ export default function encrypt(_a) {
5456
});
5557
});
5658
}
59+
exports.default = Encrypt;

dist/cjs/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var decrypt_1 = require("./functions/decrypt");
4+
var encrypt_1 = require("./functions/encrypt");
5+
var SuperCryptJS = {
6+
Decrypt: decrypt_1.default,
7+
Encrypt: encrypt_1.default,
8+
};
9+
exports.default = SuperCryptJS;

dist/esm/functions/decrypt.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
async function Decrypt({ encryption }) {
4+
const decryptedText = await fetch("https://supercryptjs-api-v2.binaryblazer.me/api/decrypt", {
5+
method: "POST",
6+
body: JSON.stringify({ encryption }),
7+
headers: {
8+
"Content-Type": "application/json",
9+
},
10+
});
11+
return decryptedText;
12+
}
13+
exports.default = Decrypt;

dist/esm/functions/encrypt.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
async function Encrypt({ text }) {
4+
const encryptedText = await fetch("https://supercryptjs-api-v2.binaryblazer.me/api/encrypt", {
5+
method: "POST",
6+
body: JSON.stringify({ text }),
7+
headers: {
8+
"Content-Type": "application/json",
9+
},
10+
});
11+
return encryptedText;
12+
}
13+
exports.default = Encrypt;

dist/esm/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const decrypt_1 = __importDefault(require("./functions/decrypt"));
7+
const encrypt_1 = __importDefault(require("./functions/encrypt"));
8+
const SuperCryptJS = {
9+
Decrypt: decrypt_1.default,
10+
Encrypt: encrypt_1.default,
11+
};
12+
exports.default = SuperCryptJS;

dist/index.js

-3
This file was deleted.

package.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
"name": "supercrypt.js",
33
"version": "1.0.0",
44
"description": "🎉 modern numeric-ascii encryption & decryption package",
5-
"main": "dist/index.js",
6-
"type": "module",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"exports": {
8+
".": {
9+
"import": "./dist/esm/index.js",
10+
"require": "./dist/cjs/index.js"
11+
},
12+
"./index.js": "./dist/cjs/index.js",
13+
"./index.mjs": "./dist/esm/index.js"
14+
},
715
"scripts": {
8-
"build": "tsc",
16+
"build:esm": "tsc -p tsconfig.esm.json",
17+
"build:cjs": "tsc -p tsconfig.cjs.json",
18+
"build": "pnpm run build:esm && pnpm run build:cjs",
919
"format:check": "prettier --check .",
1020
"format": "prettier --write .",
1121
"lint:check": "eslint .",
@@ -19,10 +29,12 @@
1929
},
2030
"license": "Apache-2.0",
2131
"devDependencies": {
32+
"@types/node": "^20.11.28",
2233
"@typescript-eslint/eslint-plugin": "^7.2.0",
2334
"@typescript-eslint/parser": "^7.2.0",
2435
"eslint": "^8.57.0",
2536
"prettier": "3.2.5",
26-
"typescript": "^5.4.2"
37+
"typescript": "^5.4.2",
38+
"undici-types": "^6.9.0"
2739
}
2840
}

pnpm-lock.yaml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/decrypt.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default async function decrypt({ encryption }: { encryption: string }) {
1+
async function Decrypt({ encryption }: { encryption: string }) {
22
const decryptedText = await fetch(
33
"https://supercryptjs-api-v2.binaryblazer.me/api/decrypt",
44
{
@@ -12,3 +12,5 @@ export default async function decrypt({ encryption }: { encryption: string }) {
1212

1313
return decryptedText;
1414
}
15+
16+
export default Decrypt;

src/functions/encrypt.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default async function encrypt({ text }: { text: string }) {
1+
async function Encrypt({ text }: { text: string }) {
22
const encryptedText = await fetch(
33
"https://supercryptjs-api-v2.binaryblazer.me/api/encrypt",
44
{
@@ -12,3 +12,5 @@ export default async function encrypt({ text }: { text: string }) {
1212

1313
return encryptedText;
1414
}
15+
16+
export default Encrypt;

src/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import encrypt from "./functions/encrypt";
2-
import decrypt from "./functions/decrypt";
1+
import Decrypt from "./functions/decrypt";
2+
import Encrypt from "./functions/encrypt";
33

4-
export { encrypt, decrypt };
4+
const SuperCryptJS = {
5+
Decrypt,
6+
Encrypt,
7+
};
8+
9+
export default SuperCryptJS as typeof SuperCryptJS & {
10+
Decrypt: typeof Decrypt;
11+
Encrypt: typeof Encrypt;
12+
};

tsconfig.cjs.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"outDir": "dist/cjs",
6+
"lib": ["dom", "dom.iterable"],
7+
"strict": true
8+
},
9+
"include": ["src"]
10+
}

tsconfig.esm.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"lib": ["dom", "dom.iterable", "esnext"],
7+
"outDir": "dist/esm",
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"allowSyntheticDefaultImports": true,
11+
"paths": {
12+
"undici-types": ["./node_modules/undici-types"]
13+
}
14+
},
15+
"include": ["src"]
16+
}

tsconfig.json

-10
This file was deleted.

0 commit comments

Comments
 (0)