[Pkg-javascript-commits] [node-bytes] 01/03: New upstream version 3.0.0

Paolo Greppi paolog-guest at moszumanska.debian.org
Tue Oct 31 14:08:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

paolog-guest pushed a commit to branch master
in repository node-bytes.

commit bd004c9c5024061cd90564d42605e0dcb7cf528f
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue Oct 31 14:27:56 2017 +0100

    New upstream version 3.0.0
---
 .gitignore          | 191 ++--------------------------------------------------
 .travis.yml         |  20 ++++--
 History.md          |  12 ++++
 Readme.md           |  71 ++++++++++---------
 component.json      |  12 ----
 index.js            |  30 +++++----
 package.json        |  17 ++---
 test/byte-format.js |  21 ++++--
 test/byte-parse.js  |   2 +-
 test/bytes.js       |  14 +++-
 10 files changed, 127 insertions(+), 263 deletions(-)

diff --git a/.gitignore b/.gitignore
index 57473c4..138b0e7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,186 +1,5 @@
-# Created by https://www.gitignore.io
-
-### Node ###
-# Logs
-logs
-*.log
-
-# Runtime data
-pids
-*.pid
-*.seed
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (http://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directory
-# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
-node_modules
-
-### Linux ###
-*~
-
-# KDE directory preferences
-.directory
-
-# Linux trash folder which might appear on any partition or disk
-.Trash-*
-
-### OSX ###
-.DS_Store
-.AppleDouble
-.LSOverride
-
-# Icon must end with two \r
-Icon
-
-
-# Thumbnails
-._*
-
-# Files that might appear in the root of a volume
-.DocumentRevisions-V100
-.fseventsd
-.Spotlight-V100
-.TemporaryItems
-.Trashes
-.VolumeIcon.icns
-
-# Directories potentially created on remote AFP share
-.AppleDB
-.AppleDesktop
-Network Trash Folder
-Temporary Items
-.apdisk
-
-### Intellij ###
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
-
-*.iml
-
-## Directory-based project format:
-.idea/
-# if you remove the above rule, at least ignore the following:
-
-# User-specific stuff:
-# .idea/workspace.xml
-# .idea/tasks.xml
-# .idea/dictionaries
-
-# Sensitive or high-churn files:
-# .idea/dataSources.ids
-# .idea/dataSources.xml
-# .idea/sqlDataSources.xml
-# .idea/dynamic.xml
-# .idea/uiDesigner.xml
-
-# Gradle:
-# .idea/gradle.xml
-# .idea/libraries
-
-# Mongo Explorer plugin:
-# .idea/mongoSettings.xml
-
-## File-based project format:
-*.ipr
-*.iws
-
-## Plugin-specific files:
-
-# IntelliJ
-out/
-
-# mpeltonen/sbt-idea plugin
-.idea_modules/
-
-# JIRA plugin
-atlassian-ide-plugin.xml
-
-# Crashlytics plugin (for Android Studio and IntelliJ)
-com_crashlytics_export_strings.xml
-crashlytics.properties
-crashlytics-build.properties
-
-
-### NetBeans ###
-nbproject/private/
-build/
-nbbuild/
-dist/
-nbdist/
-nbactions.xml
-nb-configuration.xml
-.nb-gradle/
-
-
-### Eclipse ###
-*.pydevproject
-.metadata
-.gradle
-bin/
-tmp/
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.settings/
-.loadpath
-
-# Eclipse Core
-.project
-
-# External tool builders
-.externalToolBuilders/
-
-# Locally stored "Eclipse launch configurations"
-*.launch
-
-# CDT-specific
-.cproject
-
-# JDT-specific (Eclipse Java Development Tools)
-.classpath
-
-# PDT-specific
-.buildpath
-
-# sbteclipse plugin
-.target
-
-# TeXlipse plugin
-.texlipse
-
-
-### Windows ###
-# Windows image file caches
-Thumbs.db
-ehthumbs.db
-
-# Folder config file
-Desktop.ini
-
-# Recycle Bin used on file shares
-$RECYCLE.BIN/
-
-# Windows Installer files
-*.cab
-*.msi
-*.msm
-*.msp
-
-# Windows shortcuts
-*.lnk
-
+.nyc_output/
+coverage/
+node_modules/
+npm-debug.log
+package-log.json
diff --git a/.travis.yml b/.travis.yml
index 064f369..1b7ca05 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,20 +1,32 @@
 language: node_js
 node_js:
-  - "0.6"
   - "0.8"
   - "0.10"
   - "0.12"
   - "1.8"
   - "2.4"
   - "3.3"
-  - "4.4"
-  - "5.10"
+  - "4.8"
+  - "5.12"
+  - "6.11"
+  - "7.10"
+  - "8.4"
 sudo: false
 cache:
   directories:
     - node_modules
 before_install:
+  # Skip updating shrinkwrap / lock
+  - "npm config set shrinkwrap false"
+  # Setup Node.js version-specific dependencies
+  - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev nyc"
   # Update Node.js modules
   - "test ! -d node_modules || npm prune"
   - "test ! -d node_modules || npm rebuild"
-script: "npm test"
+script:
+  # Run test script, depending on nyc install
+  - "test ! -z $(npm -ps ls nyc) || npm test"
+  - "test   -z $(npm -ps ls nyc) || npm run-script test-ci"
+after_script:
+  # Report coverage
+  - "test -d .nyc_output && npm install coveralls at 2 && nyc report --reporter=text-lcov | coveralls"
diff --git a/History.md b/History.md
index 56932a4..13d463a 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,15 @@
+3.0.0 / 2017-08-31
+==================
+
+  * Change "kB" to "KB" in format output
+  * Remove support for Node.js 0.6
+  * Remove support for ComponentJS
+
+2.5.0 / 2017-03-24
+==================
+
+  * Add option "unit"
+
 2.4.0 / 2016-06-01
 ==================
 
diff --git a/Readme.md b/Readme.md
index 7465fde..9b53745 100644
--- a/Readme.md
+++ b/Readme.md
@@ -3,24 +3,35 @@
 [![NPM Version][npm-image]][npm-url]
 [![NPM Downloads][downloads-image]][downloads-url]
 [![Build Status][travis-image]][travis-url]
+[![Test Coverage][coveralls-image]][coveralls-url]
 
 Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
 
+## Installation
+
+This is a [Node.js](https://nodejs.org/en/) module available through the
+[npm registry](https://www.npmjs.com/). Installation is done using the
+[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
+
+```bash
+$ npm install bytes
+```
+
 ## Usage
 
 ```js
 var bytes = require('bytes');
 ```
 
-#### bytes.format(number value, [options]): string|null
+#### bytes.format(number value, [options]): string|null
 
 Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
  rounded.
 
 **Arguments**
 
-| Name    | Type   | Description        |
-|---------|--------|--------------------|
+| Name    | Type     | Description        |
+|---------|----------|--------------------|
 | value   | `number` | Value in bytes     |
 | options | `Object` | Conversion options |
 
@@ -28,22 +39,23 @@ Format the given value in bytes into a string. If the value is negative, it is k
 
 | Property          | Type   | Description                                                                             |
 |-------------------|--------|-----------------------------------------------------------------------------------------|
-| decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. |
-| fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` |
-| thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `.`... Default value to `' '`. |
-| unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. |
+| decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. |
+| fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` |
+| thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `.`... Default value to `''`. |
+| unit | `string`|`null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |
+| unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. |
 
 **Returns**
 
-| Name    | Type        | Description             |
-|---------|-------------|-------------------------|
-| results | `string`|`null` | Return null upon error. String value otherwise. |
+| Name    | Type             | Description                                     |
+|---------|------------------|-------------------------------------------------|
+| results | `string`|`null` | Return null upon error. String value otherwise. |
 
 **Example**
 
 ```js
 bytes(1024);
-// output: '1kB'
+// output: '1KB'
 
 bytes(1000);
 // output: '1000B'
@@ -52,24 +64,25 @@ bytes(1000, {thousandsSeparator: ' '});
 // output: '1 000B'
 
 bytes(1024 * 1.7, {decimalPlaces: 0});
-// output: '2kB'
+// output: '2KB'
 
 bytes(1024, {unitSeparator: ' '});
-// output: '1 kB'
+// output: '1 KB'
 
 ```
 
-#### bytes.parse(string value): number|null
+#### bytes.parse(string|number value): number|null
 
-Parse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.
+Parse the string value into an integer in bytes. If no unit is given, or `value`
+is a number, it is assumed the value is in bytes.
 
 Supported units and abbreviations are as follows and are case-insensitive:
 
-  * "b" for bytes
-  * "kb" for kilobytes
-  * "mb" for megabytes
-  * "gb" for gigabytes
-  * "tb" for terabytes
+  * `b` for bytes
+  * `kb` for kilobytes
+  * `mb` for megabytes
+  * `gb` for gigabytes
+  * `tb` for terabytes
 
 The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
 
@@ -77,34 +90,30 @@ The units are in powers of two, not ten. This means 1kb = 1024b according to thi
 
 | Name          | Type   | Description        |
 |---------------|--------|--------------------|
-| value   | `string` | String to parse.   |
+| value   | `string`|`number` | String to parse, or number in bytes.   |
 
 **Returns**
 
 | Name    | Type        | Description             |
 |---------|-------------|-------------------------|
-| results | `number`|`null` | Return null upon error. Value in bytes otherwise. |
+| results | `number`|`null` | Return null upon error. Value in bytes otherwise. |
 
 **Example**
 
 ```js
-bytes('1kB');
+bytes('1KB');
 // output: 1024
 
 bytes('1024');
 // output: 1024
-```
-
-## Installation
 
-```bash
-npm install bytes --save
-component install visionmedia/bytes.js
+bytes(1024);
+// output: 1024
 ```
 
 ## License 
 
-[![npm](https://img.shields.io/npm/l/express.svg)](https://github.com/visionmedia/bytes.js/blob/master/LICENSE)
+[MIT](LICENSE)
 
 [downloads-image]: https://img.shields.io/npm/dm/bytes.svg
 [downloads-url]: https://npmjs.org/package/bytes
@@ -112,3 +121,5 @@ component install visionmedia/bytes.js
 [npm-url]: https://npmjs.org/package/bytes
 [travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg
 [travis-url]: https://travis-ci.org/visionmedia/bytes.js
+[coveralls-image]: https://img.shields.io/coveralls/visionmedia/bytes.js/master.svg
+[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master
diff --git a/component.json b/component.json
deleted file mode 100644
index 8f4eaff..0000000
--- a/component.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "name": "bytes",
-  "description": "Byte size string parser / serializer.",
-  "repository": "visionmedia/bytes.js.git",
-  "keywords": [
-    "bytes",
-    "utility"
-  ],
-  "version": "2.4.0",
-  "scripts": ["index.js"],
-  "license": "MIT"
-}
diff --git a/index.js b/index.js
index aa24231..1e39afd 100644
--- a/index.js
+++ b/index.js
@@ -33,9 +33,6 @@ var map = {
   tb: ((1 << 30) * 1024)
 };
 
-// TODO: use is-finite module?
-var numberIsFinite = Number.isFinite || function (v) { return typeof v === 'number' && isFinite(v); };
-
 var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb)$/i;
 
 /**
@@ -76,6 +73,7 @@ function bytes(value, options) {
  * @param {number} [options.decimalPlaces=2]
  * @param {number} [options.fixedDecimals=false]
  * @param {string} [options.thousandsSeparator=]
+ * @param {string} [options.unit=]
  * @param {string} [options.unitSeparator=]
  *
  * @returns {string|null}
@@ -83,7 +81,7 @@ function bytes(value, options) {
  */
 
 function format(value, options) {
-  if (!numberIsFinite(value)) {
+  if (!Number.isFinite(value)) {
     return null;
   }
 
@@ -92,16 +90,20 @@ function format(value, options) {
   var unitSeparator = (options && options.unitSeparator) || '';
   var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
   var fixedDecimals = Boolean(options && options.fixedDecimals);
-  var unit = 'B';
-
-  if (mag >= map.tb) {
-    unit = 'TB';
-  } else if (mag >= map.gb) {
-    unit = 'GB';
-  } else if (mag >= map.mb) {
-    unit = 'MB';
-  } else if (mag >= map.kb) {
-    unit = 'kB';
+  var unit = (options && options.unit) || '';
+
+  if (!unit || !map[unit.toLowerCase()]) {
+    if (mag >= map.tb) {
+      unit = 'TB';
+    } else if (mag >= map.gb) {
+      unit = 'GB';
+    } else if (mag >= map.mb) {
+      unit = 'MB';
+    } else if (mag >= map.kb) {
+      unit = 'KB';
+    } else {
+      unit = 'B';
+    }
   }
 
   var val = value / map[unit.toLowerCase()];
diff --git a/package.json b/package.json
index fc289ba..2193296 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "bytes",
   "description": "Utility to parse a string bytes to bytes and vice-versa",
-  "version": "2.4.0",
+  "version": "3.0.0",
   "author": "TJ Holowaychuk <tj at vision-media.ca> (http://tjholowaychuk.com)",
   "contributors": [
     "Jed Watson <jed.watson at me.com>",
@@ -18,13 +18,9 @@
     "converter"
   ],
   "repository": "visionmedia/bytes.js",
-  "component": {
-    "scripts": {
-      "bytes/index.js": "index.js"
-    }
-  },
   "devDependencies": {
-    "mocha": "1.21.5"
+    "mocha": "2.5.3",
+    "nyc": "10.3.2"
   },
   "files": [
     "History.md",
@@ -32,7 +28,12 @@
     "Readme.md",
     "index.js"
   ],
+  "engines": {
+    "node": ">= 0.8"
+  },
   "scripts": {
-    "test": "mocha --check-leaks --reporter spec"
+    "test": "mocha --check-leaks --reporter spec",
+    "test-ci": "nyc --reporter=text npm test",
+    "test-cov": "nyc --reporter=html --reporter=text npm test"
   }
 }
diff --git a/test/byte-format.js b/test/byte-format.js
index 0914a01..0975177 100644
--- a/test/byte-format.js
+++ b/test/byte-format.js
@@ -54,7 +54,7 @@ describe('Test byte format function', function(){
 
   it('Should return standard case', function(){
     assert.equal(bytes.format(10), '10B');
-    assert.equal(bytes.format(kb), '1kB');
+    assert.equal(bytes.format(kb), '1KB');
     assert.equal(bytes.format(mb), '1MB');
     assert.equal(bytes.format(gb), '1GB');
     assert.equal(bytes.format(tb), '1TB');
@@ -70,11 +70,11 @@ describe('Test byte format function', function(){
   });
 
   it('Should custom unit separator', function(){
-    assert.equal(bytes.format(1024), '1kB');
-    assert.equal(bytes.format(1024, {unitSeparator: ''}), '1kB');
-    assert.equal(bytes.format(1024, {unitSeparator: null}), '1kB');
-    assert.equal(bytes.format(1024, {unitSeparator: ' '}), '1 kB');
-    assert.equal(bytes.format(1024, {unitSeparator: '\t'}), '1\tkB');
+    assert.equal(bytes.format(1024), '1KB');
+    assert.equal(bytes.format(1024, {unitSeparator: ''}), '1KB');
+    assert.equal(bytes.format(1024, {unitSeparator: null}), '1KB');
+    assert.equal(bytes.format(1024, {unitSeparator: ' '}), '1 KB');
+    assert.equal(bytes.format(1024, {unitSeparator: '\t'}), '1\tKB');
   });
 
   it('Should support custom number of decimal places', function(){
@@ -97,4 +97,13 @@ describe('Test byte format function', function(){
     assert.equal(bytes.format(-1.2 * mb).toLowerCase(), '-1.2mb');
     assert.equal(bytes.format(1.2 * kb).toLowerCase(), '1.2kb');
   })
+
+  it('Should support custom unit', function(){
+    assert.equal(bytes.format(12 * mb, {unit: 'b'}).toLowerCase(), '12582912b');
+    assert.equal(bytes.format(12 * mb, {unit: 'kb'}).toLowerCase(), '12288kb');
+    assert.equal(bytes.format(12 * gb, {unit: 'mb'}).toLowerCase(), '12288mb');
+    assert.equal(bytes.format(12 * tb, {unit: 'gb'}).toLowerCase(), '12288gb');
+    assert.equal(bytes.format(12 * mb, {unit: ''}).toLowerCase(), '12mb');
+    assert.equal(bytes.format(12 * mb, {unit: 'bb'}).toLowerCase(), '12mb');
+  })
 });
diff --git a/test/byte-parse.js b/test/byte-parse.js
index 7fa8272..e4efadc 100644
--- a/test/byte-parse.js
+++ b/test/byte-parse.js
@@ -21,7 +21,7 @@ describe('Test byte parse function', function(){
     assert.strictEqual(bytes.parse(10.5), 10.5);
   });
 
-  it('Should parse kB', function(){
+  it('Should parse KB', function(){
     assert.equal(bytes.parse('1kb'), 1 * Math.pow(1024, 1));
     assert.equal(bytes.parse('1KB'), 1 * Math.pow(1024, 1));
     assert.equal(bytes.parse('1Kb'), 1 * Math.pow(1024, 1));
diff --git a/test/bytes.js b/test/bytes.js
index 4ad8165..64e3c37 100644
--- a/test/bytes.js
+++ b/test/bytes.js
@@ -8,14 +8,24 @@ describe('Test constructor', function(){
     assert.equal(typeof bytes, 'function');
   });
 
+  it('Should return null if input invalid', function(){
+    assert.strictEqual(bytes(undefined), null);
+    assert.strictEqual(bytes(null), null);
+    assert.strictEqual(bytes(true), null);
+    assert.strictEqual(bytes(false), null);
+    assert.strictEqual(bytes(NaN), null);
+    assert.strictEqual(bytes(function(){}), null);
+    assert.strictEqual(bytes({}), null);
+  });
+
   it('Shoud be able to parse a string into a number', function(){
     // This function is testes more accurately in another test suite
-    assert.equal(bytes('1kB'), 1024);
+    assert.equal(bytes('1KB'), 1024);
   });
 
   it('Should convert a number into a string', function(){
     // This function is testes more accurately in another test suite
-    assert.equal(bytes(1024), '1kB');
+    assert.equal(bytes(1024), '1KB');
   });
 
   it('Should convert a number into a string with options', function(){

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-bytes.git



More information about the Pkg-javascript-commits mailing list