Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 66d719c

Browse files
authored
feat(util): self docs to type converters + add more options for strToBool
1 parent 97b2b31 commit 66d719c

6 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/modules/util/boolToNum.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @function `boolToNum` - Convert a boolean to a number.
3+
* @param { Boolean } boolean - *Required* The boolean to be converted.
4+
* @returns { Number } - The output of the conversion.
5+
*/
6+
17
function boolToNum(boolean) {
28
if (typeof boolean !== "boolean") throw new Error("No boolean provided");
39

src/modules/util/boolToStr.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @function `boolToStr` - Convert a boolean to a string.
3+
* @param { Boolean } boolean - *Required* The boolean to be converted.
4+
* @returns { String } - The output of the conversion.
5+
*/
6+
17
function boolToStr(boolean) {
28
if (typeof boolean !== "boolean") throw new Error("No boolean provided");
39

src/modules/util/numToBool.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @function `numToBool` - Convert a number to a boolean.
3+
* @param { Number } number - *Required* The number to be converted.
4+
* @returns { Boolean } - The output of the conversion.
5+
*/
6+
17
function numToBool(number) {
28
if (typeof number !== "number") throw new Error("No number provided");
39
if (number !== 1 && number !== 0)

src/modules/util/numToStr.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @function `numToStr` - Convert a number to a string.
3+
* @param { Number } number - *Required* The number to be converted.
4+
* @returns { String } - The output of the conversion.
5+
*/
6+
17
function numToStr(number) {
28
if (typeof number !== "number") throw new Error("No number provided");
39

src/modules/util/strToBool.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
/**
2+
* @function `strToBool` - Convert a string to a boolean.
3+
* @param { String } number - *Required* The string to be converted.
4+
* @returns { Boolean } - The output of the conversion.
5+
*/
6+
17
function strToBool(string) {
28
if (!string || typeof string !== "string")
39
throw new Error("No string provided");
410

5-
if (string !== "true" && string !== "false")
11+
if (string !== "true" && string !== "false" && string !== "1" && string !== "0")
612
throw new Error("No valid string provided");
713

814
let res;
915

10-
if (string === "true") res = Boolean(true);
11-
if (string === "false") res = Boolean(false);
16+
if (string === "true" || string === "1") res = Boolean(true);
17+
if (string === "false" || string === "0") res = Boolean(false);
1218

1319
return res;
1420
}

src/modules/util/strToNum.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @function `strToNum` - Convert a string to a number.
3+
* @param { String } number - *Required* The string to be converted.
4+
* @returns { Number } - The output of the conversion.
5+
*/
6+
17
function strToNum(string) {
28
if (!string || typeof string !== "string")
39
throw new Error("No string provided");

0 commit comments

Comments
 (0)