Skip to content

Commit 3307296

Browse files
committed
init
0 parents  commit 3307296

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
.DS_Store*
3+
*.log
4+
*.gz
5+
6+
node_modules
7+
coverage

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_js:
2+
- "0.10"
3+
- "0.11"
4+
language: node_js
5+
script: "npm run-script test-cov"
6+
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2014 Jonathan Ong [email protected]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# bind-integer
3+
4+
[![NPM version][npm-image]][npm-url]
5+
[![build status][travis-image]][travis-url]
6+
[![Test coverage][coveralls-image]][coveralls-url]
7+
[![Gittip][gittip-image]][gittip-url]
8+
9+
[npm-image]: https://img.shields.io/npm/v/bind-integer.svg?style=flat
10+
[npm-url]: https://npmjs.org/package/bind-integer
11+
[travis-image]: https://img.shields.io/travis/math-utils/bind-integer.svg?style=flat
12+
[travis-url]: https://travis-ci.org/math-utils/bind-integer
13+
[coveralls-image]: https://img.shields.io/coveralls/math-utils/bind-integer.svg?style=flat
14+
[coveralls-url]: https://coveralls.io/r/math-utils/bind-integer?branch=master
15+
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat
16+
[gittip-url]: https://www.gittip.com/jonathanong/

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
module.exports = function bind(val, min, max, def) {
3+
if (val == null || isNaN(val)) val = def || 0
4+
val = Math.round(val)
5+
if (typeof min === 'number') val = Math.max(val, min)
6+
if (typeof max === 'number') val = Math.min(val, max)
7+
return val
8+
}

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "bind-integer",
3+
"description": "bind a value between a min and a max",
4+
"version": "0.0.0",
5+
"author": {
6+
"name": "Jonathan Ong",
7+
"email": "[email protected]",
8+
"url": "http://jongleberry.com",
9+
"twitter": "https://twitter.com/jongleberry"
10+
},
11+
"license": "MIT",
12+
"repository": "math-utils/bind-integer",
13+
"dependencies": {},
14+
"devDependencies": {
15+
"istanbul": "0"
16+
},
17+
"scripts": {
18+
"test": "node test",
19+
"test-cov": "istanbul cover test"
20+
},
21+
"keywords": [
22+
"integer",
23+
"bind",
24+
"math",
25+
"min",
26+
"max"
27+
]
28+
}

test/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
var assert = require('assert')
3+
4+
var bind = require('..')
5+
6+
assert.equal(0, bind(null))
7+
assert.equal(0, bind('asdf'))
8+
assert.equal(1, bind(100, -100, 1))
9+
assert.equal(5, bind('asdf', null, null, 5))
10+
assert.equal(25, bind(null, 1, 100, 25))
11+
assert.equal(1, bind(-100, 1, 100))
12+
assert.equal(100, bind(Infinity, 1, 100))
13+
assert.equal(5, bind(5.123))

0 commit comments

Comments
 (0)