Skip to content

Commit

Permalink
feat: add support for nullish inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaaLatifi authored and ASafaeirad committed Feb 1, 2024
1 parent 45a40fa commit c1c17bb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/number/toDecimal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Nullable } from '../types/types.ts';
import { fallbackNumber } from './fallbackNumber.ts';

/**
Expand All @@ -16,6 +17,6 @@ import { fallbackNumber } from './fallbackNumber.ts';
* toInteger('S', 10) // 10
* toInteger('S', undefined) // NaN
*/
export function toDecimal(s: string, fallback: number = NaN): number {
return fallbackNumber(Number.parseInt(s, 10), fallback);
export function toDecimal(s: Nullable<string>, fallback: number = NaN): number {
return fallbackNumber(Number.parseInt(s!, 10), fallback);
}

0 comments on commit c1c17bb

Please sign in to comment.