Habitat is a collection of opinionatd javascript libraries.
Here are a few of its 'features'.
Properties
Make friends with properties.
Edit property definitions with the underscore (_) proxy.
luke._.fullName.get = (self) => `${self.firstName} ${self.lastName}`
luke.fullname //"Luke Wilson"
Static Typing
You can specify the type of a property.
luke._.name.type = Text
luke.name = 24 //Type Error!
Types
Make friends with types.
Type Checking
"Luke".is(String) (25).is(Number) [6, 8].is(Array)
Type Conversion
"24".as(Number) (24).as(String)
Custom Types
const UpperCase = new Type({
check: (s) => s == s.as(UpperCase),
convert: (s) => s.toUpperCase(),
})
"HELLO".is(UpperCase) //true
Matching
Make friends with everything.
Match
input.match ( 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 Function
const fibonnaci = matcher ( [0], 0, [1], 1, [UInt], n => fibonnaci(n-1) + fibonacci(n-2), )
Bracketless
Ultra shorthand. Bad idea?
Functions
You can call functions without brackets.
print.x= "Hello world!"
friends.o.forEach.x= friend => print(`Hello ${friend}`)
Objects
You can assign multiple properties to an object at once.
luke.o={
name: "Luke",
age: 25,
}
Other Stuff
Make friends with other stuff.
Check out the wiki or something.