Skip to main content

toInt

Convert a value to an int if possible.

API

function toInt<T extends number | null = number>(value: any, defaultValue?: T): number | T;

Usage

import { toInt } from '@feedzai/js-utilities';

toInt("0")
// => 0

toInt(null)
// => 0

toInt(null, 3)
// => 3