Skip to content

Commit d58ef32

Browse files
committed
feat: add string parser and validator
1 parent 43187b2 commit d58ef32

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { TypeValidator } from './interfaces.validator';
2+
import { isString } from '../../helpers';
3+
import { PropertyValidationError } from '../PropertyValidationError';
4+
5+
export const string = Symbol('string');
6+
type StringValidator = TypeValidator<string, typeof string>;
7+
8+
export const StringValidator: StringValidator = {
9+
type: string,
10+
validateAndParse: function(value) {
11+
const result = value;
12+
if (!isString(result)) {
13+
throw new PropertyValidationError({ value, type: this.type });
14+
} else {
15+
return result;
16+
}
17+
}
18+
};

0 commit comments

Comments
 (0)