Skip to content

Commit

Permalink
Added default value field to toNumber function
Browse files Browse the repository at this point in the history
  • Loading branch information
kapil.kumar committed Apr 22, 2024
1 parent a67a085 commit 8c4ead4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/toNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const freeParseInt = parseInt;
* toNumber('3.2')
* // => 3.2
*/
function toNumber(value) {
function toNumber(value, defaultValue = NAN) {
if (typeof value === 'number') {
return value;
}
if (isSymbol(value)) {
return NAN;
return defaultValue;
}
if (isObject(value)) {
const other = typeof value.valueOf === 'function' ? value.valueOf() : value;
Expand All @@ -60,7 +60,7 @@ function toNumber(value) {
return isBinary || reIsOctal.test(value)
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: reIsBadHex.test(value)
? NAN
? defaultValue
: +value;
}

Expand Down

0 comments on commit 8c4ead4

Please sign in to comment.