-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Showing
5 changed files
with
51 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { normalizeFields } from './normalize-fields'; | ||
import type { Field } from './types'; | ||
|
||
export function isItemValid< Item >( | ||
item: Item, | ||
fields: Field< Item >[] | ||
): boolean { | ||
const _fields = normalizeFields( fields ); | ||
return _fields.every( ( field ) => { | ||
const value = field.getValue( { item } ); | ||
|
||
// TODO: this implicitely means the value is required. | ||
if ( field.type === 'integer' && value === '' ) { | ||
return false; | ||
} | ||
|
||
if ( | ||
field.type === 'integer' && | ||
! Number.isInteger( Number( value ) ) | ||
) { | ||
return false; | ||
} | ||
|
||
// Nothing to validate. | ||
return true; | ||
} ); | ||
} |
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