# parseint-loudfail

> If this parseInt() encounters an invalid digit, it fails loudly instead of returning a partially parsed number.

Latest version **1.0.4** (published 2017-08-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install parseint-loudfail
pnpm add parseint-loudfail
yarn add parseint-loudfail
bun add parseint-loudfail
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-08-02 |
| First published | 2017-08-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | M.K. |
| Maintainers | mk-pmb |
| Keywords | parseInt, parse, integer, fail, loud |

## Links

- npm: https://www.npmjs.com/package/parseint-loudfail
- Repository: https://github.com/mk-pmb/parseint-loudfail-js
- Homepage: https://github.com/mk-pmb/parseint-loudfail-js#readme
- Issues: https://github.com/mk-pmb/parseint-loudfail-js/issues
- npm.io page: https://npm.io/package/parseint-loudfail

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2017-08-02
- 1.0.3 — 2017-08-02
- 1.0.2 — 2017-08-02

## README

<!--#echo json="package.json" key="name" underline="=" -->
parseint-loudfail
=================
<!--/#echo -->

<!--#echo json="package.json" key="description" -->
If this parseInt() encounters an invalid digit, it fails loudly instead of
returning a partially parsed number.
<!--/#echo -->


API
---

This module exports one function:

### parseIntLoudFail(digits, radix[, invalid])

* `digits` must me a string that consist of optional whitespace,
  then an optional sign (`+` or `-`), then some obligatory digits.
* `radix` must be an integer in range 2..36.
* If `invalid` is provided and `!== 0` and an error occurs,
  `invalid` is returned instead of throwing the error.
* If successful, returns the integer represented by `digits` as a `Number`.



Usage
-----

from [test/usage.js](test/usage.js):

<!--#include file="test/usage.js" start="  //#u" stop="  //#r"
  outdent="  " code="javascript" -->
<!--#verbatim lncnt="42" -->
```javascript
var pInt = require('parseint-loudfail'), eq = require('assert').strictEqual;

eq(pInt('0',     8),     0);
eq(pInt('644',   8),   420);
eq(pInt('644',  10),   644);
eq(pInt('644',  16),  1604);

eq(pInt('06fF', 16, false),  1791);
eq(pInt('06Zz', 16, false),  false);
eq(pInt('',     16, false),  false);
eq(pInt('644',   1, false),  false);

pInt = err2str(pInt);
eq(pInt('',   16),  'Error: Number needs at least one digit.');
eq(pInt('',   0),   'Error: Radix must be an integer in range 2..36.');
eq(pInt('',   1),   'Error: Radix must be an integer in range 2..36.');
eq(pInt('',   99),  'Error: Radix must be an integer in range 2..36.');
eq(pInt('0779',  8),  'Error: Invalid digit "9" for radix 8');
eq(pInt('06Zz', 16),  'Error: Invalid digit "Z" for radix 16');
eq(pInt(644,    10),  'Error: Digits must be given as a string.');

eq(pInt('+0',    8),     0);
eq(pInt('+644',  8),   420);
eq(pInt('+644', 10),   644);
eq(pInt('+644', 16),  1604);

eq(pInt('-0',    8),     0);
eq(pInt('-644',  8),  -420);
eq(pInt('-644', 10),  -644);
eq(pInt('-644', 16), -1604);

eq((1 / pInt('+0', 8)), Number.POSITIVE_INFINITY);
eq((1 / pInt(' 0', 8)), Number.POSITIVE_INFINITY);
eq((1 / pInt('-0', 8)), Number.NEGATIVE_INFINITY);
eq(pInt('\r \t\f\n 644', 8),   420);
eq(pInt('   ', 4),  'Error: Number needs at least one digit.');
eq(pInt('  +', 4),  'Error: Number needs at least one digit.');
eq(pInt(' + ', 4),  'Error: Invalid digit " " for radix 4');
eq(pInt('  -', 4),  'Error: Number needs at least one digit.');
eq(pInt(' - ', 4),  'Error: Invalid digit " " for radix 4');
```
<!--/include-->



<!--#toc stop="scan" -->



&nbsp;


License
-------
<!--#echo json="package.json" key=".license" -->
ISC
<!--/#echo -->

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