https://github.com/invrs/industry-pattern
https://github.com/invrs/industry-pattern
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/invrs/industry-pattern
- Owner: invrs
- Created: 2016-04-24T05:27:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-03T19:57:10.000Z (about 10 years ago)
- Last Synced: 2025-02-09T04:04:41.889Z (over 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# IndustryPattern [](https://travis-ci.org/invrs/industry-pattern)
Pattern matching on factory class and instance methods.
## Usage
```js
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 }
```