Skip to content

Commit

Permalink
Merge branch 'feature-v1.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Hurlburt committed May 25, 2017
2 parents 7bae73c + c10374e commit d20309b
Show file tree
Hide file tree
Showing 5 changed files with 554 additions and 228 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "7"
- "6"
- "5"
- "4"
Expand Down
54 changes: 46 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ A simple JavaScript utility to convert various values to a number.

**What it does that `parseFloat` doesn't**

* Allow a default value to be set instead of returning `NaN`.
* Convert `'-0'` to `0` instead of `-0`.
* Allow an input with a valueOf function to supply the convertible value.

**What it does that `new Number` doesn't**

* Won't return a `Number` instance with convert.
* Allow a default value to be set instead of returning `NaN`.
* Convert `'-0'` to `0` instead of `-0`.

**What it does that `Number` doesn't**

* Allow a default value to be set instead of returning `NaN`.
* Convert `'-0'` to `0` instead of `-0`.

Expand All @@ -27,14 +39,40 @@ npm install --save qc-to_num
```js
import { toNum } from 'qc-to_num';

toNum(); // `null`
toNum(''); // `null`
toNum('', { def: 0 }); // `0`
toNum(NaN); // `null`
toNum(null); // `null`
toNum('+3.1459'); // 3.1459
toNum('-2.6'); // -2.6
toNum(-2.6); // -2.6
toNum('+3.1459'); // `3.1459`
toNum('2'); // `2`
toNum(2.6); // `2.6`
toNum(1.2); // `1.2`
toNum(1); // `1`
toNum(-1); // `-1`
toNum(-2.6); // `-2.6`
toNum({ valueOf() { return 42; } }); // `42`
toNum({ valueOf() { return '42'; } }); // `42`

toNum(<non-convertible>); // The non-convertible input
toNum(<non-convertible>, undefined); // The non-convertible input
toNum(<non-convertible>, { def: undefined }); // The non-convertible input

toNum(<non-convertible>, null); // `null`
toNum(<non-convertible>, { def: null }); // `null`
toNumOrNull(<non-convertible>); // `null`

toNum(<non-convertible>, 0); // `0`
toNum(<non-convertible>, { def: 0 }); // `0`

toNum(<non-convertible>, NaN); // `NaN`
toNum(<non-convertible>, { def: NaN }); // `NaN`

toNum(); // `undefined`
toNumOrNull(); // `null`

toNum(NaN); // `NaN`
toNum(NaN, null); // `null`
toNumOrNull(NaN); // `null`

toNum(''); // `''`
toNum('', null); // `null`
toNumOrNull(''); // `null`
```


Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qc-to_num",
"version": "0.0.1",
"version": "1.0.0",
"author": {
"name": "Danny Hurlburt",
"url": "https://github.com/dhurlburtusa"
Expand All @@ -12,8 +12,8 @@
"conversion",
"javascript",
"number",
"to_num",
"toNum",
"toNumOrNull",
"typescript",
"utility"
],
Expand All @@ -34,6 +34,7 @@
},
"scripts": {
"build": "tsc",
"clean": "rimraf coverage dist",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"prepublish": "tsc",
"test": "jest --color --coverage",
Expand Down Expand Up @@ -63,6 +64,7 @@
"@types/jest": "^19.2.2",
"coveralls": "^2.13.1",
"jest": "^19.0.2",
"rimraf": "^2.6.1",
"ts-jest": "^19.0.14",
"typescript": "^2.3.2"
}
Expand Down
Loading

0 comments on commit d20309b

Please sign in to comment.