fullstacksjs / toolbox

A zero-dependency 📦 tree-shakable🌲 collection of missing JavaScript utilities.
https://toolbox.fullstacksjs.com/
MIT License
56 stars 15 forks source link

[Proposal]: toDecimal fallback #50

Closed ASafaeirad closed 9 months ago

ASafaeirad commented 1 year ago

Function Signature

export function toDecimal(s: Nullable<string>, fallback: number = NaN): number {}

Motivation

To parse environment variables, we must use the following pattern.

port: toDecimal(process.env.PORT ?? "3000", 3000),

If the toDecimal function supports nullable values as input, we can write the code simply like this.

port: toDecimal(process.env.PORT, 3000),