industry-pattern
v1.0.0
Published
Pattern matching on factory class and instance methods.
Downloads
2
Readme
IndustryPattern
Pattern matching on factory class and instance methods.
Usage
import { factory } from "industry"
import { functions } from "industry-functions"
import { instance } from "industry-instance"
import { pattern } from "industry-pattern"
import { standard_io } from "industry-standard-io"
class Test {
init() {
this.pattern({
and: { a: Number, b: String, c: "c" },
or: [
{ a: Number },
{ b: 0 },
{ c: c => !!c }
]
})
}
and({ a, b, c }) { return true }
or({ a, b, c }) { return true }
}
let test = factory(Test)
.set("functions", functions)
.set("instance", instance)
.set("pattern", pattern)
.set("standard_io", standard_io)
test().and() // { value: undefined }
test().and({ a: 0, b: "b" }) // { value: undefined }
test().and({ a: 0, b: "b", c: "c" }) // { value: true }
test().or() // { value: undefined }
test().or({ a: 0, b: "b" }) // { value: undefined }
test().or({ a: 0, b: 0 }) // { value: true }
test().and({ c: true }) // { value: true }