-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 8, add TypeScript definition (#15)
- Loading branch information
1 parent
1427fc0
commit 0c28c8d
Showing
8 changed files
with
113 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '12' | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
declare const roundTo: { | ||
/** | ||
Round the decimals with [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round). | ||
Numbers are rounded to a specific number of fractional digits. Specifying a negative `precision` will round to any number of places to the left of the decimal. | ||
@param number - Number to adjust. | ||
@param precision - (Integer) Number of decimal places. | ||
@example | ||
``` | ||
import roundTo = require('round-to'); | ||
roundTo(1.234, 2); | ||
//=> 1.23 | ||
roundTo(1234.56, -2); | ||
//=> 1200 | ||
``` | ||
*/ | ||
(number: number, precision: number): number; | ||
|
||
/** | ||
Round up the decimals with [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil). | ||
@param number - Number to adjust. | ||
@param precision - (Integer) number of decimal places. | ||
@example | ||
``` | ||
import roundTo = require('round-to'); | ||
roundTo.up(1.234, 2); | ||
//=> 1.24 | ||
``` | ||
*/ | ||
up(number: number, precision: number): number; | ||
|
||
/** | ||
Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor). | ||
@param number - Number to adjust. | ||
@param precision - (Integer) number of decimal places. | ||
@example | ||
``` | ||
import roundTo = require('round-to'); | ||
roundTo.down(1.234, 2); | ||
//=> 1.23 | ||
``` | ||
*/ | ||
down(number: number, precision: number): number; | ||
}; | ||
|
||
export = roundTo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {expectType} from 'tsd'; | ||
import roundTo = require('.'); | ||
|
||
expectType<number>(roundTo(1.234, 2)); | ||
expectType<number>(roundTo.up(1.234, 2)); | ||
expectType<number>(roundTo.down(1.234, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import test from 'ava'; | ||
import m from '.'; | ||
import roundTo from '.'; | ||
|
||
test('roundTo()', t => { | ||
t.is(m(0.129, 3), 0.129); | ||
t.is(m(0.129, 2), 0.13); | ||
t.is(m(0.129, 1), 0.1); | ||
t.is(m(1.005, 2), 1.01); | ||
t.is(m(1.005, 0), 1); | ||
t.is(m(111.1, -2), 100); | ||
t.is(m(-0.375, 2), -0.38); | ||
t.false(Number.isNaN(m(10000000000000, 8))); | ||
t.is(m(0.37542323423423432432432432432, 8), 0.37542323); | ||
t.is(roundTo(0.129, 3), 0.129); | ||
t.is(roundTo(0.129, 2), 0.13); | ||
t.is(roundTo(0.129, 1), 0.1); | ||
t.is(roundTo(1.005, 2), 1.01); | ||
t.is(roundTo(1.005, 0), 1); | ||
t.is(roundTo(111.1, -2), 100); | ||
t.is(roundTo(-0.375, 2), -0.38); | ||
t.false(Number.isNaN(roundTo(10000000000000, 8))); | ||
t.is(roundTo(0.37542323423423432432432432432, 8), 0.37542323); | ||
}); | ||
|
||
test('roundTo.up()', t => { | ||
t.is(m.up(0.111, 3), 0.111); | ||
t.is(m.up(0.111, 2), 0.12); | ||
t.is(m.up(0.111, 1), 0.2); | ||
t.is(m.up(1.004, 2), 1.01); | ||
t.is(m.up(1.111, 0), 2); | ||
t.is(m.up(111.1, -2), 200); | ||
t.is(m.up(-0.375, 2), -0.37); | ||
t.is(roundTo.up(0.111, 3), 0.111); | ||
t.is(roundTo.up(0.111, 2), 0.12); | ||
t.is(roundTo.up(0.111, 1), 0.2); | ||
t.is(roundTo.up(1.004, 2), 1.01); | ||
t.is(roundTo.up(1.111, 0), 2); | ||
t.is(roundTo.up(111.1, -2), 200); | ||
t.is(roundTo.up(-0.375, 2), -0.37); | ||
}); | ||
|
||
test('roundTo.down()', t => { | ||
t.is(m.down(0.666, 3), 0.666); | ||
t.is(m.down(0.666, 2), 0.66); | ||
t.is(m.down(0.666, 1), 0.6); | ||
t.is(m.down(1.006, 2), 1.00); | ||
t.is(m.down(1.006, 0), 1); | ||
t.is(m.down(111.6, -2), 100); | ||
t.is(m.down(-0.375, 2), -0.38); | ||
t.is(roundTo.down(0.666, 3), 0.666); | ||
t.is(roundTo.down(0.666, 2), 0.66); | ||
t.is(roundTo.down(0.666, 1), 0.6); | ||
t.is(roundTo.down(1.006, 2), 1.0); | ||
t.is(roundTo.down(1.006, 0), 1); | ||
t.is(roundTo.down(111.6, -2), 100); | ||
t.is(roundTo.down(-0.375, 2), -0.38); | ||
}); |