New Upstream Snapshot - node-has-binary

Ready changes

Summary

Merged new upstream version: 0.1.7+git20170301.2.f9be9b3 (was: 0.1.7+git20170301.1.f9be9b3).

Resulting package

Built on 2023-01-16T04:11 (took 8m53s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-snapshots node-has-binary

Lintian Result

Diff

diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index a72b52e..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,15 +0,0 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
-npm-debug.log
-node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b9c11b6
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+sudo: false
+node_js:
+  - "node"
diff --git a/debian/changelog b/debian/changelog
index 781f7d1..5fdad8b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+node-has-binary (0.1.7+git20170301.2.f9be9b3-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot.
+  * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 16 Jan 2023 04:05:38 -0000
+
 node-has-binary (0.1.7-4) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/debian/patches/00-better-assert.diff b/debian/patches/00-better-assert.diff
index 70a1f81..6c2c6b7 100644
--- a/debian/patches/00-better-assert.diff
+++ b/debian/patches/00-better-assert.diff
@@ -2,15 +2,16 @@ Description: Replace dependency from better-assert with assert.
 Forwarded: not-needed
 Author: Paolo Greppi <paolo.greppi@libpf.com>
 
-Index: node-has-binary/test.js
+Index: node-has-binary.git/test.js
 ===================================================================
---- node-has-binary.orig/test.js
-+++ node-has-binary/test.js
-@@ -1,6 +1,6 @@
+--- node-has-binary.git.orig/test.js
++++ node-has-binary.git/test.js
+@@ -1,7 +1,7 @@
+ /* global describe it Blob */
  
  var hasBinary = require('./');
 -var assert = require('better-assert');
 +var assert = require('assert');
  var fs = require('fs');
  
- describe('has-binarydata', function(){
+ describe('has-binarydata', function () {
diff --git a/index.js b/index.js
index 434ccfa..395036e 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,4 @@
+/* global Blob File */
 
 /*
  * Module requirements.
@@ -14,46 +15,44 @@ module.exports = hasBinary;
 /**
  * Checks for binary data.
  *
- * Right now only Buffer and ArrayBuffer are supported..
+ * Supports Buffer, ArrayBuffer, Blob and File.
  *
  * @param {Object} anything
  * @api public
  */
 
-function hasBinary(data) {
-
-  function _hasBinary(obj) {
-    if (!obj) return false;
+function hasBinary (obj) {
+  if (!obj || typeof obj !== 'object') {
+    return false;
+  }
 
-    if ( (global.Buffer && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) ||
-         (global.ArrayBuffer && obj instanceof ArrayBuffer) ||
-         (global.Blob && obj instanceof Blob) ||
-         (global.File && obj instanceof File)
-        ) {
-      return true;
+  if (isArray(obj)) {
+    for (var i = 0, l = obj.length; i < l; i++) {
+      if (hasBinary(obj[i])) {
+        return true;
+      }
     }
+    return false;
+  }
 
-    if (isArray(obj)) {
-      for (var i = 0; i < obj.length; i++) {
-          if (_hasBinary(obj[i])) {
-              return true;
-          }
-      }
-    } else if (obj && 'object' == typeof obj) {
-      // see: https://github.com/Automattic/has-binary/pull/4
-      if (obj.toJSON && 'function' == typeof obj.toJSON) {
-        obj = obj.toJSON();
-      }
+  if ((typeof global.Buffer === 'function' && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) ||
+     (typeof global.ArrayBuffer === 'function' && obj instanceof ArrayBuffer) ||
+     (typeof global.Blob === 'function' && obj instanceof Blob) ||
+     (typeof global.File === 'function' && obj instanceof File)
+    ) {
+    return true;
+  }
 
-      for (var key in obj) {
-        if (Object.prototype.hasOwnProperty.call(obj, key) && _hasBinary(obj[key])) {
-          return true;
-        }
-      }
-    }
+  // see: https://github.com/Automattic/has-binary/pull/4
+  if (obj.toJSON && typeof obj.toJSON === 'function') {
+    return hasBinary(obj.toJSON());
+  }
 
-    return false;
+  for (var key in obj) {
+    if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
+      return true;
+    }
   }
 
-  return _hasBinary(data);
+  return false;
 }
diff --git a/package.json b/package.json
index 8a19661..13dd5ce 100644
--- a/package.json
+++ b/package.json
@@ -3,11 +3,16 @@
   "version": "0.1.7",
   "description": "A function that takes anything in javascript and returns true if its argument contains binary data.",
   "dependencies": {
-    "isarray": "0.0.1"
+    "isarray": "2.0.1"
   },
   "devDependencies": {
-    "better-assert": "1.0.0",
-    "mocha": "2.3.4"
+    "better-assert": "^1.0.2",
+    "mocha": "^3.2.0",
+    "semistandard": "^9.2.1"
+  },
+  "scripts": {
+    "checkstyle": "semistandard",
+    "test": "npm run checkstyle && mocha --bail"
   },
   "author": "Kevin Roark",
   "license": "MIT"
diff --git a/test.js b/test.js
index c6bd5aa..8e65ff3 100644
--- a/test.js
+++ b/test.js
@@ -1,43 +1,48 @@
+/* global describe it Blob */
 
 var hasBinary = require('./');
 var assert = require('better-assert');
 var fs = require('fs');
 
-describe('has-binarydata', function(){
-
-  it('should work with buffer', function(){
+describe('has-binarydata', function () {
+  it('should work with buffer', function () {
     assert(hasBinary(fs.readFileSync('./test.js')));
   });
 
-  it('should work with an array that does not contain binary', function() {
+  it('should work with an array that does not contain binary', function () {
     var arr = [1, 'cool', 2];
     assert(!hasBinary(arr));
   });
 
-  it('should work with an array that contains a buffer', function() {
+  it('should work with an array that contains a buffer', function () {
     var arr = [1, new Buffer('asdfasdf', 'utf8'), 2];
     assert(hasBinary(arr));
   });
 
-  it('should work with an object that does not contain binary', function() {
-    var ob = {a: 'a', b: [], c: 1234, toJSON: '{\"a\": \"a\"}'};
+  it('should work with an object that does not contain binary', function () {
+    var ob = {a: 'a', b: [], c: 1234, toJSON: '{"a": "a"}'};
     assert(!hasBinary(ob));
   });
 
-  it('should work with an object that contains a buffer', function() {
-    var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{\"a\": \"a\"}'};
+  it('should work with an object that contains a buffer', function () {
+    var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{"a": "a"}'};
     assert(hasBinary(ob));
   });
 
-  it('should work with null', function() {
+  it('should work with an object whose toJSON() returns a buffer', function () {
+    var ob = {a: 'a', b: [], c: 1234, toJSON: function () { return new Buffer('abc'); }};
+    assert(hasBinary(ob));
+  });
+
+  it('should work with null', function () {
     assert(!hasBinary(null));
   });
 
-  it('should work with undefined', function() {
+  it('should work with undefined', function () {
     assert(!hasBinary(undefined));
   });
 
-  it('should work with a complex object that contains undefined and no binary', function() {
+  it('should work with a complex object that contains undefined and no binary', function () {
     var ob = {
       x: ['a', 'b', 123],
       y: undefined,
@@ -47,7 +52,7 @@ describe('has-binarydata', function(){
     assert(!hasBinary(ob));
   });
 
-  it('should work with a complex object that contains undefined and binary', function() {
+  it('should work with a complex object that contains undefined and binary', function () {
     var ob = {
       x: ['a', 'b', 123],
       y: undefined,
@@ -59,15 +64,19 @@ describe('has-binarydata', function(){
   });
 
   if (global.ArrayBuffer) {
-      it('should work with an ArrayBuffer', function() {
-        assert(hasBinary(new ArrayBuffer()));
-      });
+    it('should work with an ArrayBuffer', function () {
+      assert(hasBinary(new ArrayBuffer()));
+    });
   }
 
   if (global.Blob) {
-     it('should work with a Blob', function() {
-        assert(hasBinary(new Blob()));
-     });
+    it('should work with a Blob', function () {
+      assert(hasBinary(new Blob()));
+    });
+  } else {
+    it('should not crash if global Blob is not a function', function () {
+      global.Blob = [ 1, 2, 3 ];
+      assert(!hasBinary(global.Blob));
+    });
   }
-
 });

Debdiff

File lists identical (after any substitutions)

No differences were encountered in the control files

More details

Full run details