Skip to content

Commit

Permalink
fix: improve boolean parse behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
rickstaa committed Sep 17, 2022
1 parent c1324b3 commit 98a9363
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,23 @@ function isValidHexColor(hexColor) {
}

/**
* @param {string} value
* @returns {boolean | string}
* @param {string | boolean} value
* @returns {boolean | undefined }
*/
function parseBoolean(value) {
if (value === "true") {
return true;
} else if (value === "false") {
return false;
} else {
if (typeof value === "boolean") {
return value;
} else if (typeof value === "string") {
if (value.toLowerCase() === "true") {
return true;
} else if (value.toLowerCase() === "false") {
return false;
}
}
console.warn(
`'${value}' is not a valid boolean, expected 'true' or 'false'.`,
);
return undefined;
}

/**
Expand Down

0 comments on commit 98a9363

Please sign in to comment.