Comparing version 0.0.1 to 0.1.0
25
index.js
@@ -7,6 +7,7 @@ | ||
* @return {Number} | ||
* @api private | ||
* @api public | ||
*/ | ||
module.exports = function(size) { | ||
if ('number' == typeof size) return convert(size); | ||
var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb)$/) | ||
@@ -17,5 +18,5 @@ , n = parseFloat(parts[1]) | ||
var map = { | ||
kb: 1024 | ||
, mb: 1024 * 1024 | ||
, gb: 1024 * 1024 * 1024 | ||
kb: 1 << 10 | ||
, mb: 1 << 20 | ||
, gb: 1 << 30 | ||
}; | ||
@@ -25,1 +26,17 @@ | ||
}; | ||
/** | ||
* convert bytes into string. | ||
* | ||
* @param {Number} b - bytes to convert | ||
* @return {String}i | ||
* @api public | ||
*/ | ||
function convert (b) { | ||
var gb = 1 << 30, mb = 1 << 20, kb = 1 << 10; | ||
if (b >= gb) return (Math.round(b / gb * 100) / 100) + 'gb'; | ||
if (b >= mb) return (Math.round(b / mb * 100) / 100) + 'mb'; | ||
if (b >= kb) return (Math.round(b / kb * 100) / 100) + 'kb'; | ||
return b; | ||
} |
{ | ||
"name": "bytes", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)", | ||
"description": "byte string parser (5mb etc)", | ||
"version": "0.0.1", | ||
"description": "byte size string parser / serializer", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
@@ -11,3 +11,8 @@ "dependencies": {}, | ||
"should": "*" | ||
}, | ||
"component": { | ||
"scripts": { | ||
"bytes": "index.js" | ||
} | ||
} | ||
} |
@@ -1,5 +0,4 @@ | ||
# node-bytes | ||
Byte string parser. | ||
Byte string parser / formatter. | ||
@@ -17,2 +16,5 @@ ## Example: | ||
// => 1073741824 | ||
bytes(1073741824) | ||
// => 1gb | ||
``` | ||
@@ -24,2 +26,28 @@ | ||
$ 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. |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
2885
7
39
52
1