mirror of https://github.com/kern/filepizza
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
570 B
JavaScript
34 lines
570 B
JavaScript
function statusPredicate(v) {
|
|
if (v.length === 1) {
|
|
return v.toUpperCase();
|
|
} else {
|
|
return 'is' + statusPredicate(v.charAt(0)) + v.substring(1);
|
|
}
|
|
}
|
|
|
|
export default class Status {
|
|
|
|
constructor(values) {
|
|
this.value = values[0];
|
|
this.values = values;
|
|
|
|
for (let v of values) {
|
|
this[statusPredicate(v)] = function () {
|
|
return this.value === v;
|
|
}
|
|
}
|
|
}
|
|
|
|
get() {
|
|
return this.value;
|
|
}
|
|
|
|
set(value) {
|
|
if (this.values.indexOf(value) === -1)
|
|
throw new Error('Unknown value');
|
|
|
|
this.value = value;
|
|
}
|
|
|
|
}
|