sharpjs1-main
v1.0.0
Published
SharpJs — a tiny, friendly dialect of JavaScript. print() instead of console.log, sharp instead of let, saw instead of break, sun() instead of Number().
Maintainers
Readme
SharpJs
SharpJs is a tiny, friendly dialect of JavaScript. It looks and behaves just like JS, but swaps a few keywords for friendlier ones:
| SharpJs | JavaScript |
| ------------- | --------------- |
| print(...) | console.log(...) |
| sharp | let |
| saw | break |
| sun(...) | Number(...) |
Everything else is plain JavaScript — if, for, function, require,
template literals, arrow functions, and so on all work exactly as you'd expect.
Install
npm install -g sharpjsOr use it locally in a project:
npm install sharpjsQuick start
Create a file hello.sharp:
sharp name = "World";
print("Hello, " + name + "!");
sharp age = sun("25");
print("Next year you will be", age + 1);
for (sharp i = 0; i < 10; i = i + 1) {
if (i > 3) {
saw;
}
print("i =", i);
}Run it:
sharpjs hello.sharpCLI
sharpjs <file.sharp> [args...] Run a SharpJs file
sharpjs run <file.sharp> [args...] Run a SharpJs file (explicit)
sharpjs build <file.sharp> -o out.js Transpile to JavaScript
sharpjs --help Show help
sharpjs --version Show versionThe sharp command is also installed as an alias for sharpjs.
Transpile to JavaScript
sharpjs build hello.sharp -o hello.jsIf you omit -o, SharpJs writes hello.js next to the source file.
Programmatic API
const sharpjs = require('sharpjs');
// Transpile a string of SharpJs source to JavaScript
sharpjs.transpile('print("hi")'); // => 'console.log("hi")'
sharpjs.transpile('sharp x = sun("2")'); // => 'let x = Number("2")'
// Transpile a file to a JavaScript string
const js = sharpjs.transpileFile('./app.sharp');
// Transpile AND run a file (require/module/__dirname all work)
sharpjs.runFile('./app.sharp');How it works
The transpiler scans the source character by character and only rewrites
keywords found in real code. Words inside strings, template-literal text,
regular expressions, and comments are left exactly as written. Member accesses
like obj.print and partial words like printer are never rewritten.
print("sharp and saw stay literal in strings"); // -> console.log("sharp and saw stay literal in strings")
obj.print(); // -> obj.print() (unchanged)
sharpen(); // -> sharpen() (unchanged)License
MIT
