Skip to content

Instantly share code, notes, and snippets.

@bultas
Created October 25, 2017 10:46
Show Gist options
  • Save bultas/519d5796a1e438167709493686760c33 to your computer and use it in GitHub Desktop.
Save bultas/519d5796a1e438167709493686760c33 to your computer and use it in GitHub Desktop.
Validate data usage
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