-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathrule.js
More file actions
28 lines (24 loc) · 646 Bytes
/
rule.js
File metadata and controls
28 lines (24 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export default class Rule {
constructor (opts) {
opts = Object.assign({
options: {},
defaults: {},
meta: {}
}, opts)
if (!opts.id) {
throw new Error('Rule must have an id')
}
if (typeof opts.validate !== 'function') {
throw new TypeError('Rule must have validate function')
}
this.id = opts.id
this.disabled = opts.disabled === true
this.meta = opts.meta
this.defaults = Object.assign({}, opts.defaults)
this.options = Object.assign({}, opts.defaults, opts.options)
this._validate = opts.validate
}
validate (commit) {
this._validate(commit, this)
}
}