Skip to content

Commit

Permalink
feat: add boolean parser and validator
Browse files Browse the repository at this point in the history
  • Loading branch information
emyann committed Jun 22, 2019
1 parent 7693e92 commit 943af2e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/validation/validators/boolean.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TypeValidator } from './interfaces.validator';
import { PropertyValidationError } from '../PropertyValidationError';

export const boolean = Symbol('boolean');
type BooleanValidator = TypeValidator<boolean, typeof boolean>;

export const BooleanValidator: BooleanValidator = {
type: boolean,
validateAndParse: function(value) {
if (typeof value === 'boolean') {
return value;
} else {
throw new PropertyValidationError({ value, type: this.type });
}
}
};

0 comments on commit 943af2e

Please sign in to comment.