1.0.3 • Published 6 years ago
simp.compiler v1.0.3
Simp
Simp is a JavaScript compiler that aims to simplify the language and add a few utilities.
Installation
npm install simp.compiler
Compiling Simp code
const simp = require('simp');
// To compile Simp code, use the compile() function.
console.log(simp.compile(`
let test = 0
func increment(int) {
def int: 0
ret int++;
}
test = increment(test);
`));
Compiled output:
var test = 0
function increment(int) {
if (!int) int = 0
return int++;
}
test = increment(test);
Features
Those are the features of the Simp compiler.
Aliases
Simp adds a few aliases to your usual JS code, to make coding faster.
Before | After | Description |
---|---|---|
let | var | backported from ES6 |
func | function | - |
ret | return | for non-void returns |
ret. | return | for void returns |
Loop shortcuts
If you want to quickly create a loop without all of those pesky semicolons, Simp is gonna help you out.
Before | After | Description |
---|---|---|
index: min..max | var index = min; index < max; index++ | Forward loop |
index: min..<max | var index = max - 1; index >= min; index-- | Backwards loop |
Arrow functions
A backport of the ES6 feature, but with a Java style arrow.
Before | After |
---|---|
(args) -> { /* function */ } | function(args) { /* function */ } |
Random shorthands
When you want to generate a random number, or execute something with a specific chance, Simp has shorthands that can help out.
Before | After |
---|---|
? min-max | min + Math.random() * (max - min) |
? chance% | Math.random() * 100 < chance |
Function utilities
Just some function utilities, to make your code more beautiful.
Before | After | Description |
---|---|---|
def var: val | if (!var) var = val | Default value, a less complex backport of an ES6 feature |
object::getter | object.get('getter') | Useful when embedding JS into apps |