fairmont-helpers
Advanced tools
Comparing version 1.1.2 to 1.2.0
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var Crypto, Method, base64, base64url, isBuffer, isString, md5, ref; | ||
var Base64Words, Crypto, Method, async, base64, base64URL, fromBase64Words, fs, isBuffer, isString, md5, promise, randomBytes, randomKey, randomWords, ref, ref1, toBase64Words; | ||
fs = require("fs"); | ||
Crypto = require("crypto"); | ||
@@ -11,2 +13,6 @@ | ||
Base64Words = require("base64-words"); | ||
ref1 = require("./promise"), promise = ref1.promise, async = ref1.async; | ||
md5 = Method.create(); | ||
@@ -22,16 +28,69 @@ | ||
base64 = function(string) { | ||
return new Buffer(string).toString('base64').replace(/\=+$/, ''); | ||
base64 = Method.create(); | ||
Method.define(base64, isString, function(string) { | ||
return base64(new Buffer(string)); | ||
}); | ||
Method.define(base64, isBuffer, function(buffer) { | ||
return buffer.toString('base64'); | ||
}); | ||
base64URL = function(buffer) { | ||
return base64(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''); | ||
}; | ||
base64url = function(string) { | ||
return new Buffer(string).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''); | ||
toBase64Words = function(buffer) { | ||
return Base64Words.fromBase64(base64URL(buffer)); | ||
}; | ||
fromBase64Words = function(string) { | ||
return new Buffer(Base64Words.toBase64(string), 'base64'); | ||
}; | ||
randomBytes = process.platform !== "win32" ? function(n) { | ||
return promise(function(resolve, reject) { | ||
return fs.open("/dev/urandom", "r", function(error, fd) { | ||
var buffer; | ||
buffer = Buffer.alloc(n); | ||
return fs.read(fd, buffer, 0, n, 0, function(error, m) { | ||
if (n === m) { | ||
return resolve(buffer); | ||
} else { | ||
return reject("Unable to read " + n + " bytes from /dev/urandom"); | ||
} | ||
}); | ||
}); | ||
}); | ||
} : function(n) { | ||
return promise(function(resolve, reject) { | ||
return Crypto.randomBytes(n, function(error, buffer) { | ||
if (error == null) { | ||
return resolve(buffer); | ||
} else { | ||
return reject(error); | ||
} | ||
}); | ||
}); | ||
}; | ||
randomKey = async(function*(n) { | ||
return base64URL((yield randomBytes(n))); | ||
}); | ||
randomWords = async(function*(n) { | ||
return toBase64Words((yield randomBytes(n))); | ||
}); | ||
module.exports = { | ||
md5: md5, | ||
base64: base64, | ||
base64url: base64url | ||
base64URL: base64URL, | ||
toBase64Words: toBase64Words, | ||
fromBase64Words: fromBase64Words, | ||
randomBytes: randomBytes, | ||
randomKey: randomKey, | ||
randomWords: randomWords | ||
}; | ||
}).call(this); |
{ | ||
"name": "fairmont-helpers", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Functional and reactive programming for JavaScript.", | ||
@@ -32,2 +32,3 @@ "files": [ | ||
"dependencies": { | ||
"base64-words": "^0.1.1", | ||
"fairmont-core": "1.0.x", | ||
@@ -34,0 +35,0 @@ "fairmont-multimethods": "1.0.x" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42300
963
3
1
+ Addedbase64-words@^0.1.1
+ Addedbase64-words@0.1.2(transitive)