#BoreJS I was pretty bored, so I decided to build this altJS language using the Canopy parser.
- Annotation syntax
@export
class Lmao { /*body...*/ }
@private var a = 'ayyy' // When exported and is outside of a class (using module.exports), will throw an error. If inside a class, will act like regular private/public inside of classes
@public var a = 'lmao' // @public is the same as @export. If inside a class, will act like regular private/public inside of classes
- Validation helpers for classes
class StringArray extends Array {
@validate p.is(String) || p.toString() // just boolean checking
push (val) {
return val
}
}
class DB extends MongoConnection {
@validate p => Schema.check(p) // or using a custom function
createObject (val) { // val is now a proper Mongo Schema (and not a regular object)
return this.createDoc(val).then(doc => {
console.log(`Created a document with ObjectID ${doc._id}`)
return Promise.resolve(doc)
})
}
}
- Type checking and casting (like in Swift)
let strArr: StringArray = [1, 2, 3, 4, 5] as StringArray // Child of Array, still conforms to that type
let sumArr = (arr: Array) => { // arr can be any object that inherits the Array properties
return arr.is(StringArray): arr.reduce((prev, curr) => prev + curr)
}
console.log(sumArr(strArr)) // throws an error: strArr won't conform to !StringArray needed type
console.log(sumArr(strArr as! Array)) // logs [1,2,3,4,5]
- Operator Overloading
@export
class GeoPoint extends Point {
operator+ (toAdd) {
return toAdd.is(Point)? new GeoPoint(this.x + toAdd.x, this.y + toAdd.y)
}
}