diff options
Diffstat (limited to 'node_modules/bytes')
-rw-r--r-- | node_modules/bytes/.npmignore | 1 | ||||
-rw-r--r-- | node_modules/bytes/History.md | 25 | ||||
-rw-r--r-- | node_modules/bytes/Makefile | 7 | ||||
-rw-r--r-- | node_modules/bytes/Readme.md | 54 | ||||
-rw-r--r-- | node_modules/bytes/component.json | 7 | ||||
-rw-r--r-- | node_modules/bytes/index.js | 41 | ||||
-rw-r--r-- | node_modules/bytes/package.json | 21 |
7 files changed, 156 insertions, 0 deletions
diff --git a/node_modules/bytes/.npmignore b/node_modules/bytes/.npmignore new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/node_modules/bytes/.npmignore @@ -0,0 +1 @@ +test diff --git a/node_modules/bytes/History.md b/node_modules/bytes/History.md new file mode 100644 index 0000000..5097352 --- /dev/null +++ b/node_modules/bytes/History.md @@ -0,0 +1,25 @@ + +1.0.0 / 2014-05-05 +================== + + * add negative support. fixes #6 + +0.3.0 / 2014-03-19 +================== + + * added terabyte support + +0.2.1 / 2013-04-01 +================== + + * add .component + +0.2.0 / 2012-10-28 +================== + + * bytes(200).should.eql('200b') + +0.1.0 / 2012-07-04 +================== + + * add bytes to string conversion [yields] diff --git a/node_modules/bytes/Makefile b/node_modules/bytes/Makefile new file mode 100644 index 0000000..8e8640f --- /dev/null +++ b/node_modules/bytes/Makefile @@ -0,0 +1,7 @@ + +test: + @./node_modules/.bin/mocha \ + --reporter spec \ + --require should + +.PHONY: test
\ No newline at end of file diff --git a/node_modules/bytes/Readme.md b/node_modules/bytes/Readme.md new file mode 100644 index 0000000..5591b28 --- /dev/null +++ b/node_modules/bytes/Readme.md @@ -0,0 +1,54 @@ +# node-bytes + + Byte string parser / formatter. + +## Example: + +```js +bytes('1kb') +// => 1024 + +bytes('2mb') +// => 2097152 + +bytes('1gb') +// => 1073741824 + +bytes(1073741824) +// => 1gb + +bytes(1099511627776) +// => 1tb +``` + +## Installation + +``` +$ npm install bytes +$ component install visionmedia/bytes.js +``` + +## License + +(The MIT License) + +Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca> + +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, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/bytes/component.json b/node_modules/bytes/component.json new file mode 100644 index 0000000..2929c25 --- /dev/null +++ b/node_modules/bytes/component.json @@ -0,0 +1,7 @@ +{ + "name": "bytes", + "description": "byte size string parser / serializer", + "keywords": ["bytes", "utility"], + "version": "0.2.1", + "scripts": ["index.js"] +} diff --git a/node_modules/bytes/index.js b/node_modules/bytes/index.js new file mode 100644 index 0000000..c1da2fe --- /dev/null +++ b/node_modules/bytes/index.js @@ -0,0 +1,41 @@ + +/** + * Parse byte `size` string. + * + * @param {String} size + * @return {Number} + * @api public + */ + +module.exports = function(size) { + if ('number' == typeof size) return convert(size); + var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb|tb)$/) + , n = parseFloat(parts[1]) + , type = parts[2]; + + var map = { + kb: 1 << 10 + , mb: 1 << 20 + , gb: 1 << 30 + , tb: ((1 << 30) * 1024) + }; + + return map[type] * n; +}; + +/** + * convert bytes into string. + * + * @param {Number} b - bytes to convert + * @return {String} + * @api public + */ + +function convert (b) { + var tb = ((1 << 30) * 1024), gb = 1 << 30, mb = 1 << 20, kb = 1 << 10, abs = Math.abs(b); + if (abs >= tb) return (Math.round(b / tb * 100) / 100) + 'tb'; + if (abs >= gb) return (Math.round(b / gb * 100) / 100) + 'gb'; + if (abs >= mb) return (Math.round(b / mb * 100) / 100) + 'mb'; + if (abs >= kb) return (Math.round(b / kb * 100) / 100) + 'kb'; + return b + 'b'; +} diff --git a/node_modules/bytes/package.json b/node_modules/bytes/package.json new file mode 100644 index 0000000..76e0bff --- /dev/null +++ b/node_modules/bytes/package.json @@ -0,0 +1,21 @@ +{ + "name": "bytes", + "author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)", + "description": "byte size string parser / serializer", + "repository": { + "type": "git", + "url": "https://github.com/visionmedia/bytes.js.git" + }, + "version": "1.0.0", + "main": "index.js", + "dependencies": {}, + "devDependencies": { + "mocha": "*", + "should": "*" + }, + "component": { + "scripts": { + "bytes/index.js": "index.js" + } + } +} |