Created
October 25, 2017 10:46
-
-
Save bultas/519d5796a1e438167709493686760c33 to your computer and use it in GitHub Desktop.
Validate data usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { validate, list, dict, required, optional } from 'validators'; | |
pipe( | |
validate( | |
identity, | |
[ | |
required('first', isString), | |
optional('second', list(isString), []), | |
// required(['third', 'subParam', 'deepParam'], isNumber) | |
required('third', dict([ | |
required('subParam', dict([ | |
required('deepParam', isNumber) | |
])) | |
])) | |
], | |
{ | |
first: 'string', | |
second: [ | |
"string", | |
"string" | |
], | |
third: { | |
subParam: { | |
deepParam: 10 | |
} | |
} | |
} | |
), | |
rmap((result) => { | |
dispatch({ | |
type: IS_OK | |
result | |
}); | |
}), | |
errmap((errors) => { | |
dispatch({ | |
type: IS_ERROR | |
errors | |
}) | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment