TodePond / Airspace

javascript library by the dreamberd foundation
MIT License
26 stars 2 forks source link

Airspace

Airspace is a perfect JavaScript library, brought to you by the DreamBerd Foundation.

Colons

End every line with a colon. You can achieve this by combining two semi-colons to make a full colon.

print("Hello world!");;

Alternatively, you can use half a colon, and a second half will be automatically inserted for you.

print("Hello world!");

Similarly, you can use none, and Airspace will helpfully add both.

print("Hello world!")

Note: Colons can be placed at the start of a line too. It makes no difference.

;;print("Hello world!")

Execute Operator

You can use the execute operator (x=) to execute a function without brackets.

print.x= "Hello world!"

Or use it on an array to flip the function around.

[3, 2].x(add)

Function Literals

You can also call a function by using it as a literal.

print `"Hello world!"`

This allows for fine-grained control over how your code runs. You can easily call by reference, or by value.

score = 2
add `3, score`
add `3, ${score}`

Debug Operator

You might benefit from the debug operator (.d). Use it on any value to print it to the console.

"Hello world!".d // "Hello world!"

You don't need to rearrange your code. Want to log something? Just chuck a 'dot d' on it.

score = 3
if (score.d > 9) { // 3
   print("You win!")
} 

With

By the way, to code with Airspace, simply surround your code with a with block.

with (Airspace) {
   "Hello world!".d
}

All examples in this readme should be placed within the with block.

New for 2023: If you're using a build-step, you can just write "use airspace" at the top of the file.

Rocket Operator

To run your code asynchronously, place it within a rocket operator (x=o=>). This shoots it to the next animation frame.

x=o=> "Hello world!".d

The rocket operator also supports code blocks.

x=o=> {
   print `"Hello"`
   print `"world!"`
}

Functions

To create a function, use the unlit rocket operator (=o=>).

greet =o=> "Hello world!".d

greet() // "Hello world!"

Use the blob operator (o) to access arguments.

add =o=> o.a + o.b

add(3, 2) // 5

Variables

To define a variable, just assign it.

name = "Lu"

name.d // "Lu"

You can control exactly how your variable works. By default, it just gets and sets its value, but you can change this.

name = "Lu"
name.get =o=> o.value.toUpperCase()

name.d // "LU"