# to-int

> Parse a number from a string, defaulting to 0 (or any desired default)

Latest version **0.1.0** (published 2015-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-int
pnpm add to-int
yarn add to-int
bun add to-int
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2015-04-08 |
| First published | 2015-04-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nate Cavanaugh |
| Maintainers | natecavanaugh |

## Links

- npm: https://www.npmjs.com/package/to-int
- Repository: https://github.com/natecavanaugh/to-int
- Issues: https://github.com/natecavanaugh/to-int/issues
- npm.io page: https://npm.io/package/to-int

## Recent versions

- 0.1.0 (latest) — 2015-04-08

## README

# to-int [![Build Status](https://travis-ci.org/natecavanaugh/to-int.svg?branch=master)](https://travis-ci.org/natecavanaugh/to-int)

> Parse a number from a string, defaulting to 0 (or any desired default), as well as the ability to pass a custom radix.
> Also exposes a `toFloat` method which calls `parseFloat` instead of `parseInt`.
> These methods are useful when you wish to convert a string to a number, but default to some value (which is often zero, but can be anything).


## Install

```
$ npm install --save to-int
```


## Usage

```js
var toInt = require('to-int');

toInt('10px');
//=> 10

toInt.toFloat('0.5em');
//=> 0.5
```


## API

### toInt(input, [radix, [defaultValue]])

#### input

*Required*
Type: `string|number`

The value you wish to parse for the number

#### radix

Type: `number`
Default: `10`

The radix you wish to pass to parse with.

#### defaultValue

Type: `number`
Default: `0`

If a number can't be parsed, this is what will be returned.

### toInt.toFloat(input, [defaultValue])

#### input

*Required*
Type: `string|number`

The value you wish to parse for the number

#### defaultValue

Type: `number`
Default: `0`

If a number can't be parsed, this is what will be returned.

## License

MIT © [Nate Cavanaugh](http://alterform.com)

---
_Source: https://npm.io/package/to-int · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
