We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d58ef32 commit 7693e92Copy full SHA for 7693e92
src/validation/validators/number.validator.ts
@@ -0,0 +1,18 @@
1
+import { TypeValidator } from './interfaces.validator';
2
+import { PropertyValidationError } from '../PropertyValidationError';
3
+
4
+export const number = Symbol('number');
5
+type NumberValidator = TypeValidator<number, typeof number>;
6
7
+export const NumberValidator: NumberValidator = {
8
+ type: number,
9
+ validateAndParse: function(value) {
10
+ const result = +value;
11
12
+ if (isNaN(result)) {
13
+ throw new PropertyValidationError({ value, type: this.type });
14
+ } else {
15
+ return result;
16
+ }
17
18
+};
0 commit comments