Permalink
Browse files

Initial commit

  • Loading branch information...
pvorb committed Feb 26, 2012
0 parents commit de1d63232d8b6cbbeeade60e154e642ed7038e30
Showing with 124 additions and 0 deletions.
  1. +18 −0 LICENSE
  2. +55 −0 README.mkd
  3. +15 −0 numpad.js
  4. +27 −0 package.json
  5. +9 −0 test.js
18 LICENSE
@@ -0,0 +1,18 @@
+Copyright © 2012 Paul Vorbach
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the “Software”), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
+# numpad
+
+pad numbers with leading zeros.
+
+## Installation
+
+`npm install notepad` or `ender add notepad`
+
+## API
+
+```js
+numpad(x, digits);
+```
+
+* `x` Number
+* `digits` Number of digits
+
+## Usage
+
+```js
+var numpad = require('numpad');
+
+numpad(5); // '05'
+numpad(5, 4); // '0005'
+numpad(1.23); // '01.23'
+numpad(1.23, 4); // '0001.23'
+numpad(892, 2); // '892'
+numpad(892.453, 2); // '892.453'
+```
+
+## Bugs and Issues
+
+If you encounter any bugs or issues, feel free to open an issue at
+[github](https://github.com/pvorb/numpad/issues).
+
+## License
+
+Copyright © 2012 Paul Vorbach
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the “Software”), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
+module.exports = function numpad(x, digits) {
+ var result = Math.floor(x).toString();
+
+ if (typeof digits == 'undefined')
+ digits = 2;
+
+ while (result.length < digits)
+ result = '0'+result;
+
+ var dec = x.toString().split('.')[1];
+ if (dec)
+ return result + '.' + dec;
+
+ return result;
+};
@@ -0,0 +1,27 @@
+{
+ "name": "numpad",
+ "description": "numpad",
+ "author": "Paul Vorbach <paul@vorb.de> (http://vorb.de/)",
+ "tags": [ "integer", "padding" ],
+ "version": "0.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/pvorb/numpad.git"
+ },
+ "bugs": {
+ "url": "https://github.com/pvorb/numpad/issues"
+ },
+ "main": "./numpad.js",
+ "engines": {
+ "node": "*"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://vorb.de/license/mit.html"
+ }
+ ],
+ "dependencies": {},
+ "devDependencies": {},
+ "optionalDependencies": {}
+}
@@ -0,0 +1,9 @@
+var assert = require('assert');
+var numpad = require('./numpad.js');
+
+assert.strictEqual(numpad(5, 3), '005');
+assert.strictEqual(numpad(18.1, 5), '00018.1');
+assert.strictEqual(numpad(1534, 2), '1534');
+assert.strictEqual(numpad(1883.953, 3), '1883.953');
+
+console.log('ok');

0 comments on commit de1d632

Please sign in to comment.