Perform case-insensitive checking when converting booleans from strings

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-05-01 12:10:58 +01:00
parent 558424ecee
commit 8424fb44f6
2 changed files with 4 additions and 1 deletions

View File

@ -19,8 +19,8 @@ export const PermissiveBoolean = new t.Type<boolean, t.TypeOf<PermissiveType>>(
(m, c) =>
permissiveValue.validate(m, c).chain(v => {
switch (typeof v) {
case 'boolean':
case 'string':
case 'boolean':
case 'number':
const val = checkTruthy(v);
if (val == null) {

View File

@ -61,6 +61,9 @@ export function checkString(s: NullableLiteral): string | void {
* which represents if the input was truthy
*/
export function checkTruthy(v: string | boolean | number): boolean | void {
if (_.isString(v)) {
v = v.toLowerCase();
}
switch (v) {
case '1':
case 'true':