-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Augustin Le Fèvre
committed
Aug 14, 2017
1 parent
578ab9e
commit b369ba4
Showing
7 changed files
with
220 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,13 @@ | |
"url": "git+https://github.com/kilix/functional-validation.git" | ||
}, | ||
"keywords": [], | ||
"files": ["lib"], | ||
"files": [ | ||
"lib" | ||
], | ||
"jest": { | ||
"testPathIgnorePatterns": ["<rootDir>/src/__tests__/typingTests.js"] | ||
"testPathIgnorePatterns": [ | ||
"<rootDir>/src/__tests__/typingTests.js" | ||
] | ||
}, | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
|
@@ -33,7 +37,7 @@ | |
"babel-cli-flow": "^1.0.0", | ||
"babel-core": "^6.23.1", | ||
"babel-eslint": "^7.2.0", | ||
"babel-loader": "^6.3.2", | ||
"babel-loader": "^7.1.1", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-preset-env": "^1.1.8", | ||
|
@@ -44,17 +48,17 @@ | |
"eslint-plugin-flowtype": "^2.35.0", | ||
"eslint-plugin-import": "2.7", | ||
"eslint-plugin-jsx-a11y": "5.1.1", | ||
"eslint-plugin-react": "7.2", | ||
"flow-bin": "^0.52.0", | ||
"husky": "^0.14.3", | ||
"jest": "^20.0.4", | ||
"lint-staged": "^4.0.3", | ||
"npm-run-all": "^4.0.2", | ||
"prettier": "^1.5.3", | ||
"rimraf": "^2.6.1", | ||
"webpack": "^2.2.1" | ||
"webpack": "^3.5.4" | ||
}, | ||
"dependencies": { | ||
"eslint-plugin-react": "7.2", | ||
"ramda": "^0.23.0" | ||
}, | ||
"peerDependencies": {}, | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
// @flow | ||
import Ramda from 'ramda'; | ||
import pipe from 'ramda/src/pipe'; | ||
import whenR from 'ramda/src/when'; | ||
|
||
import type { ErrorT } from './validateModel'; | ||
|
||
// ramda flow-typed typings are not always correct, and use Array, while this library uses | ||
// $ReadOnlyArray | ||
const R: any = Ramda; | ||
const when: any = whenR; | ||
|
||
function createValidation<M, T>( | ||
field: string, | ||
getField: (model: M) => T, | ||
validateField: (field: T) => string | null, | ||
): M => ErrorT | null { | ||
return R.pipe(getField, validateField, R.when(Boolean, error => ({ field, error }))); | ||
return pipe(getField, validateField, when(Boolean, error => ({ field, error }))); | ||
} | ||
|
||
export default createValidation; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
// @flow | ||
import R from 'ramda'; | ||
|
||
import validateModel from './validateModel'; | ||
import type { ModelValidatorT, ValidationsT } from './validateModel'; | ||
|
||
function runConditionalValidation<T>( | ||
condition: (model: T) => boolean, | ||
validations: ValidationsT<T>, | ||
): ModelValidatorT<T> { | ||
return R.ifElse(condition, validateModel(validations), () => []); | ||
return (model: T) => (condition(model) ? validateModel(validations)(model) : []); | ||
} | ||
|
||
export default runConditionalValidation; |
This file contains 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
Oops, something went wrong.