@therealowenj/jjsw 1.0.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 +34 -0
- package/cli.mjs +34 -0
- package/eslint.config.js +7 -0
- package/jjsw.mjs +76 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# J JavaScript Wrapper (JJSW)
|
|
2
|
+
|
|
3
|
+
JJSW is a JavaScript Wrapper designed to add quality-of-life enhancements to JavaScript.
|
|
4
|
+
It allows you to write scripts using simplified keywords and run them via CLI or process them into standard JS.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Simplified syntax mapped to JavaScript keywords:
|
|
9
|
+
| JJSW Keyword | JavaScript Equivalent |
|
|
10
|
+
|-------------|----------------------|
|
|
11
|
+
| func | function |
|
|
12
|
+
| nch | const |
|
|
13
|
+
| cha | let |
|
|
14
|
+
| cout | console.log |
|
|
15
|
+
| cin | prompt |
|
|
16
|
+
| give | return |
|
|
17
|
+
| check | switch |
|
|
18
|
+
| elif | else if |
|
|
19
|
+
| is | case |
|
|
20
|
+
| standart | default |
|
|
21
|
+
| end | break |
|
|
22
|
+
| resume | continue |
|
|
23
|
+
| keys | Object.keys |
|
|
24
|
+
| values | Object.values |
|
|
25
|
+
| forever | while (true) |
|
|
26
|
+
|
|
27
|
+
- Utility functions included when running scripts:
|
|
28
|
+
- `randomRange(min, max)` → random integer in `[min, max]`
|
|
29
|
+
- `wait(seconds)` → blocks for the specified number of seconds
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install -g jjsw
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import jjsw from "./jjsw.mjs";
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const command = args[0]; // "run" or "process"
|
|
8
|
+
const file = args[1];
|
|
9
|
+
|
|
10
|
+
if (!command || !file) {
|
|
11
|
+
console.error("Usage: jjsw <run|process> <file.jjs>");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Check file exists
|
|
16
|
+
if (!fs.existsSync(file)) {
|
|
17
|
+
console.error("File not found:", file);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (command === "process") {
|
|
23
|
+
const jsFile = jjsw.processFile(file);
|
|
24
|
+
console.log(`Processed ${file} → ${jsFile}`);
|
|
25
|
+
} else if (command === "run") {
|
|
26
|
+
await jjsw.runFile(file);
|
|
27
|
+
} else {
|
|
28
|
+
console.error("Invalid command. Use 'run' or 'process'.");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error("Error:", err);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import globals from "globals";
|
|
3
|
+
import { defineConfig } from "eslint/config";
|
|
4
|
+
|
|
5
|
+
export default defineConfig([
|
|
6
|
+
{ files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.browser } },
|
|
7
|
+
]);
|
package/jjsw.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// jjsw.mjs
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import vm from "vm";
|
|
5
|
+
import promptSync from "prompt-sync";
|
|
6
|
+
|
|
7
|
+
const prompt = promptSync();
|
|
8
|
+
|
|
9
|
+
const KEYWORD_MAP = {
|
|
10
|
+
func: "function",
|
|
11
|
+
nch: "const",
|
|
12
|
+
cha: "let",
|
|
13
|
+
cout: "console.log",
|
|
14
|
+
cin: "prompt",
|
|
15
|
+
give: "return",
|
|
16
|
+
check: "switch",
|
|
17
|
+
elif: "else if",
|
|
18
|
+
is: "case",
|
|
19
|
+
standart: "default",
|
|
20
|
+
end: "break",
|
|
21
|
+
resume: "continue",
|
|
22
|
+
keys: "Object.keys",
|
|
23
|
+
values: "Object.values",
|
|
24
|
+
forever: "while (true)",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function processCode(code) {
|
|
28
|
+
let processed = code;
|
|
29
|
+
for (const [k, v] of Object.entries(KEYWORD_MAP)) {
|
|
30
|
+
const re = new RegExp(`\\b${k}\\b`, "g");
|
|
31
|
+
processed = processed.replace(re, v);
|
|
32
|
+
}
|
|
33
|
+
return processed;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function runCode(code, contextOverrides = {}) {
|
|
37
|
+
const context = {
|
|
38
|
+
cout: (...args) => console.log(...args),
|
|
39
|
+
cin: (msg = "") => prompt(msg),
|
|
40
|
+
randomRange: (min, max) => Math.floor(Math.random() * (max - min + 1)) + min,
|
|
41
|
+
wait: (seconds) => {
|
|
42
|
+
const end = Date.now() + seconds * 1000;
|
|
43
|
+
while (Date.now() < end) {}
|
|
44
|
+
},
|
|
45
|
+
console,
|
|
46
|
+
Math,
|
|
47
|
+
JSON,
|
|
48
|
+
prompt,
|
|
49
|
+
...contextOverrides,
|
|
50
|
+
};
|
|
51
|
+
vm.createContext(context);
|
|
52
|
+
|
|
53
|
+
const wrappedCode = `(async () => { ${processCode(code)} })()`;
|
|
54
|
+
return vm.runInContext(wrappedCode, context);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function processFile(filePath) {
|
|
58
|
+
const code = fs.readFileSync(filePath, "utf8");
|
|
59
|
+
const processedCode = processCode(code);
|
|
60
|
+
const jsFile = path.basename(filePath, path.extname(filePath)) + ".js";
|
|
61
|
+
fs.writeFileSync(jsFile, processedCode, "utf8");
|
|
62
|
+
return jsFile;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function runFile(filePath, contextOverrides = {}) {
|
|
66
|
+
const code = fs.readFileSync(filePath, "utf8");
|
|
67
|
+
return runCode(code, contextOverrides);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default {
|
|
71
|
+
processCode,
|
|
72
|
+
runCode,
|
|
73
|
+
processFile,
|
|
74
|
+
runFile,
|
|
75
|
+
KEYWORD_MAP,
|
|
76
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@therealowenj/jjsw",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A JavaScript wrapper providing enhanced utilities for easier scripting and CLI usage.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"javascript",
|
|
7
|
+
"wrapper",
|
|
8
|
+
"cli",
|
|
9
|
+
"utilities",
|
|
10
|
+
"enhancements"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/TheRealOwenJ/jjsw#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/TheRealOwenJ/jjsw/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/TheRealOwenJ/jjsw.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "GPL-3.0-or-later",
|
|
21
|
+
"author": "TheRealOwenJ",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "jjsw.mjs",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"start": "node ./cli.mjs",
|
|
29
|
+
"test": "echo \"No tests defined yet\" && exit 1",
|
|
30
|
+
"build": "echo \"No build step required\""
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"prompt-sync": "^4.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"globals": "^17.4.0"
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"jjsw": "./cli.mjs"
|
|
40
|
+
}
|
|
41
|
+
}
|