nope-validator
Version:
Fast and simple JS validator
43 lines (40 loc) • 1.18 kB
JavaScript
import { NopePrimitive } from './NopePrimitive.js';
import { isNil } from './utils.js';
class NopeBoolean extends NopePrimitive {
constructor() {
super(...arguments);
this._type = 'boolean';
}
true(message = 'Input must be true') {
const rule = (entry) => {
if (this.isEmpty(entry)) {
return;
}
if (entry !== true) {
return message;
}
};
return this.test(rule);
}
false(message = 'Input must be false') {
const rule = (entry) => {
if (this.isEmpty(entry)) {
return;
}
if (entry !== false) {
return message;
}
};
return this.test(rule);
}
validate(entry, context) {
const value = isNil(entry) ? entry : !!entry;
return super.validate(value, context);
}
validateAsync(entry, context) {
const value = isNil(entry) ? entry : !!entry;
return super.validateAsync(value, context);
}
}
export { NopeBoolean };
//# sourceMappingURL=NopeBoolean.js.map