We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 43187b2 commit d58ef32Copy full SHA for d58ef32
src/validation/validators/string.validator.ts
@@ -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