fix(android): KeyboardType now respects numbers (#9240)

This commit is contained in:
Nathanael Anderson
2021-02-26 18:23:50 -06:00
committed by GitHub
parent c04e1b59e5
commit f08fcb17b4
4 changed files with 24 additions and 6 deletions

View File

@@ -1546,12 +1546,18 @@ export function makeValidator<T>(...values: T[]): (value: any) => value is T {
return (value: any): value is T => set.has(value);
}
export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T {
export function makeParser<T>(isValid: (value: any) => boolean, allowNumbers = false): (value: any) => T {
return (value) => {
const lower = value && value.toLowerCase();
if (isValid(lower)) {
return lower;
} else {
if (allowNumbers) {
const convNumber = +value;
if (!isNaN(convNumber)) {
return value;
}
}
throw new Error('Invalid value: ' + value);
}
};