This repository was archived by the owner on Dec 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
17function boolToNum ( boolean ) {
28 if ( typeof boolean !== "boolean" ) throw new Error ( "No boolean provided" ) ;
39
Original file line number Diff line number Diff line change 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+
17function boolToStr ( boolean ) {
28 if ( typeof boolean !== "boolean" ) throw new Error ( "No boolean provided" ) ;
39
Original file line number Diff line number Diff line change 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+
17function numToBool ( number ) {
28 if ( typeof number !== "number" ) throw new Error ( "No number provided" ) ;
39 if ( number !== 1 && number !== 0 )
Original file line number Diff line number Diff line change 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+
17function numToStr ( number ) {
28 if ( typeof number !== "number" ) throw new Error ( "No number provided" ) ;
39
Original file line number Diff line number Diff line change 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+
17function 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}
Original file line number Diff line number Diff line change 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+
17function strToNum ( string ) {
28 if ( ! string || typeof string !== "string" )
39 throw new Error ( "No string provided" ) ;
You can’t perform that action at this time.
0 commit comments