Skip to content
Luke Wilson edited this page Apr 10, 2019 · 9 revisions

Contents

Array

Array.prototype.last

The last element of the array.

Array.prototype.first

The last element of the array.

Array.prototype.reversed

The array in reverse order.

Async

wait(duration)

Waits.

all(...promises)

Groups promises into one promise.

Bracketless

Function.prototype.x=

Calls a function with one argument.

print.x= "Hello world!"

Function.prototype.o(...args)

Binds some arguments to a function.

const greet = print.o("Hello world!")
greet()

Object.prototype.o

Binds an object to a method.

const friends = ["Joe", "Flora", "Jethro"]
const forEachFriend = friends.o.forEach
forEachFriend(friend => print(`Hello ${friend}!`))

Object.prototype.o=

Assigns properties to an object.

const luke = {}
luke.o={
    name: "Luke",
    age: 25,
}

Console

print(message)

Prints to the console

Object.prototype.d

Print an object to the console. Quick to type.

"Hello world!".d

Document

$(selector)

Select elements.

$1(selector)

Select the first element that matches.

Element.prototype.$(selector)

Select elements in an element.

Element.prototype.$1(selector)

Select the first element that matches in an element.

HTML

Generate elements from HTML.

const heading = HTML `<h1>Luke</h1>`

Loop

repeat(number, func)

Repeats a function.

for (const i of Number)

Repeats a block of code a certain number of times.

// Counting from 0 to 9
for (const i of 10) {
    print(i)
}

for (const i of Object)

Iterates through an object's properties

const names = {
    first: "Luke",
    middle: "Leonard",
    last: "Wilson",
}

for (const name of names) {
    print (name)
}

Match

match(value, ...rules)

Pattern match a value.

match (input,
    String,     "It's a string",
    "Luke",     "It's my name",
    [Int, Int], "It's a list of two integers",
    Any,        "It's something else",
)

matcher(...rules)

Make a function that pattern matches its arguments.

const fibonacci = matcher (
    [0], 0,
    [1], 1,
    [UInt], n => fibonacci(n-1) + fibonacci(n-2),
)

Object.prototype.match(...rules)

Pattern match the object.

age.match (
    25,          "Same as me!",
    n => n > 25, "Older than me!",
    Negative,    n => `${n} years old? How does that work?`
)

Property

Object.prototype._

The underscore (_) property on all objects allows you to access and edit a property's descriptor. You can use it to get info on a property's descriptor:

const luke = {
	age: 24,
}

luke._.age.value //24

Or you can use it to change a property's descriptor:

const luke = {
	firstName: "Luke",
	lastName: "Wilson",
}

luke._.fullName.get = (self) => `${self.firstName} ${self.lastName}`

luke.fullName //Luke Wilson

PropertyDescriptor.type

You can specify the type of a property.

const luke = {
	age: 25,
}

luke._.age.type = Number

luke.age = "26" //TypeError: "age" property failed custom type-check.

PropertyDescriptor.typeCheck

You can specify a custom type-check for a property.

const luke = {
	age: 24,
}

luke._.age.typeCheck = (v) => v % 1 == 0

luke.age = 25.5 //TypeError: "age" property failed custom type-check.

Object.prototype.has(propertyName)

Check if the object has a certain property.

Set

Set.prototype.last

The last element of the set.

Set.prototype.first

The last element of the set.

Set.prototype.reversed

The set in reverse order.

Set.prototype.length

The length of the set.

Type

Object.prototype.is(type)

Checks if the object is that type.

"Luke".is(String)
(25).is(Number)
[6, 8].is(Array)

Object.prototype.as(type)

Converts the object to that type.

"24".as(Number)
(24).as(String)

Type

Types let you specify how to check and convert.

const Int = new Type ({
    convert: (object) => parseInt(object),
    check: (object) => object.is(Number) && object % 1 == 0,
})

(24).is(Int)
(24.5).as(Int)

Object.prototype.and(type)

Make a new type that must check for two types.

(25).is(Int.and(Odd))

Object.prototype.or(type)

Make a new type that can be one of two types.

"25".is(Number.or(String))

Clone this wiki locally
You can’t perform that action at this time.