[Pkg-javascript-commits] [node-randomfill] 12/47: use standard.js

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:52:51 UTC 2017


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

rouca pushed a commit to branch master
in repository node-randomfill.

commit 4e3fac8461c06b23a639699ca9c4c9dd5f988482
Author: Daniel Cousens <github at dcousens.com>
Date:   Fri Mar 27 12:53:51 2015 +1100

    use standard.js
---
 browser.js   | 40 +++++++++++++++++++++-------------------
 index.js     |  2 +-
 package.json |  3 ++-
 test.js      | 32 +++++++++++++++++---------------
 4 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/browser.js b/browser.js
index 1a6e3e3..d4fa120 100644
--- a/browser.js
+++ b/browser.js
@@ -1,28 +1,30 @@
-'use strict';
+'use strict'
+
+function oldBrowser () {
+  throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
+}
 
 var crypto = global.crypto || global.msCrypto
-if(crypto && crypto.getRandomValues) {
-  module.exports = randomBytes;
+
+if (crypto && crypto.getRandomValues) {
+  module.exports = randomBytes
 } else {
-  module.exports = oldBrowser;
+  module.exports = oldBrowser
 }
-function randomBytes(size, cb) {
-  var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array
-    /* This will not work in older browsers.
-     * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
-     */
 
-  crypto.getRandomValues(bytes);
+function randomBytes (size, cb) {
+  // in browserify, this is becomes an extended UInt8Array
+  var bytes = new Buffer(size)
+
+  // This will not work in older browsers.
+  // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
+  crypto.getRandomValues(bytes)
+
   if (typeof cb === 'function') {
     return process.nextTick(function () {
-      cb(null, bytes);
-    });
+      cb(null, bytes)
+    })
   }
-  return bytes;
-}
-function oldBrowser() {
-  throw new Error(
-      'secure random number generation not supported by this browser\n'+
-      'use chrome, FireFox or Internet Explorer 11'
-    )
+
+  return bytes
 }
diff --git a/index.js b/index.js
index ccdab3f..a2d9e39 100644
--- a/index.js
+++ b/index.js
@@ -1 +1 @@
-module.exports = require('crypto').randomBytes;
\ No newline at end of file
+module.exports = require('crypto').randomBytes
diff --git a/package.json b/package.json
index c6f2f34..6a8617b 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
   "description": "random bytes from browserify stand alone",
   "main": "index.js",
   "scripts": {
-    "test": "node test.js | tspec"
+    "test": "standard && node test.js | tspec"
   },
   "repository": {
     "type": "git",
@@ -22,6 +22,7 @@
   "homepage": "https://github.com/crypto-browserify/randombytes",
   "browser": "browser.js",
   "devDependencies": {
+    "standard": "^3.3.0",
     "tap-spec": "^2.1.2",
     "tape": "^3.0.3"
   }
diff --git a/test.js b/test.js
index 51a80cc..9d447e1 100644
--- a/test.js
+++ b/test.js
@@ -1,12 +1,13 @@
-var test = require("tape");
-var randomBytes = require('./');
+var test = require('tape')
+var randomBytes = require('./')
 
 test('sync', function (t) {
-    t.plan(3);
-    t.equals(randomBytes(3).length, 3, 'len: ' + 3);
-    t.equals(randomBytes(30).length, 30, 'len: ' + 30);
-    t.equals(randomBytes(300).length, 300, 'len: ' + 300);
-});
+  t.plan(3)
+  t.equals(randomBytes(3).length, 3, 'len: ' + 3)
+  t.equals(randomBytes(30).length, 30, 'len: ' + 30)
+  t.equals(randomBytes(300).length, 300, 'len: ' + 300)
+})
+
 test('async', function (t) {
   t.plan(3)
 
@@ -31,13 +32,14 @@ test('async', function (t) {
 
 if (process.browser) {
   test('requesting to much throws', function (t) {
-    t.plan(1);
-    t.throws(randomBytes.bind(null, 65537));
-  });
+    t.plan(1)
+    t.throws(randomBytes.bind(null, 65537))
+  })
+
   test('requesting to much throws async', function (t) {
-    t.plan(1);
+    t.plan(1)
     t.throws(randomBytes.bind(null, 65537, function () {
-      t.ok(false, 'should not get here');
-    }));
-  });
-}
\ No newline at end of file
+      t.ok(false, 'should not get here')
+    }))
+  })
+}

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



More information about the Pkg-javascript-commits mailing list