diff --git a/index.js b/index.js index 6f2d0f8..62e2681 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ var map = { pb: Math.pow(1024, 5), }; -var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i; +var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(b|kb|mb|gb|tb|pb)$/i; /** * Convert the given value in bytes into a string or parse to string to an integer in bytes. diff --git a/test/byte-parse.js b/test/byte-parse.js index cebfab2..13fc091 100644 --- a/test/byte-parse.js +++ b/test/byte-parse.js @@ -103,6 +103,9 @@ describe('Test byte parse function', function(){ it('Should drop partial bytes', function(){ assert.equal(bytes.parse('1.1b'), 1); assert.equal(bytes.parse('1.0001kb'), 1024); + // the `b` unit must floor like every other unit (not truncate toward zero) + assert.equal(bytes.parse('-1.9b'), -2); + assert.equal(bytes.parse('-1.9kb'), Math.floor(-1.9 * 1024)); }); it('Should allow whitespace', function(){