Socket
Book a DemoInstallSign in
Socket

try-parse-int

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

try-parse-int

tryParseInt parses number string or return null if failed

latest
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

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.

FAQs

Package last updated on 27 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts