try-parse-int
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

tryParseInt

tryParseInt parses number string or return null if failed

But why

It is useful so that we can use nullish-coalescing operator to fallback to default value

Example:

const foobar = tryParseInt('foobar') ?? 20

Caveat

This function will parse only decimal number or hex number, for anything else (e.g. empty string, spaces) it will return null.

Readme

Keywords

none

Package Sidebar

Install

npm i try-parse-int

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

1.73 kB

Total Files

4

Last publish

Collaborators

  • normanzb