Skip to content
Collection of Javascript libraries.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Async.js
Loop.js
Match.js
Project.js
PropertyEditor.js
README.md
array.js
bracketless.js
console.js
document.js
type.js

README.md

Habitat

Habitat is a collection of javascript libraries.
Here are a few of its features.

Properties

Edit property definitions with the underscore (_) proxy.

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

luke.fullname //"Luke Wilson"

You can specify the type of a property.

luke._.name.type = Text

luke.name = 24 //Type Error!

Types

You can do a type check.

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

You can do a type conversion.

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

You can make your own type.

const UpperCase = new Type({
	check: (s) => s == s.as(UpperCase),
	convert: (s) => s.toUpperCase(),
})

"HELLO".is(UpperCase) //true

Matching

You can 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",
)

You can make a function that pattern matches its arguments.

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

Bracketless

You can call functions without brackets.

print.x= "Hello world!"

friends.o.forEach.x= friend => print(`Hello ${friend}`)

You can assign multiple properties to an object at once.

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

Other Stuff

Check out the wiki.

You can’t perform that action at this time.