Skip to main content

toNumberIfPossible

Stentor API Reference


Stentor API Reference / stentor-utils/src / toNumberIfPossible

Function: toNumberIfPossible()

toNumberIfPossible\<T>(potentialNumber): number | T

Defined in: packages/stentor-utils/src/string/toNumberIfPossible.ts:12

Converts to a number if possible otherwise it passes it through.

This preserves Dates and booleans. If true is passed in, true is passed out. Additionally, if an empty string is passed, it passes it through instead of turning it into a number.

Type Parameters​

T​

T

Parameters​

potentialNumber​

T

Returns​

number | T