Comparing version 1.0.3 to 1.0.4
@@ -40,4 +40,4 @@ function fromBase64(base64string) { | ||
function base64url(stringOrBuffer) { | ||
return fromBase64(Buffer(stringOrBuffer).toString('base64')); | ||
function base64url(stringOrBuffer, encoding) { | ||
return fromBase64(Buffer(stringOrBuffer, encoding).toString('base64')); | ||
} | ||
@@ -44,0 +44,0 @@ |
{ | ||
"name": "base64url", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "For encoding to/from base64urls", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const fs = require('fs'); | ||
const test = require('tap').test; | ||
const base64url = require('..'); | ||
const testString = fs.readFileSync(__dirname + '/test.jpg').toString(); | ||
const testBuffer = fs.readFileSync(__dirname + '/test.jpg'); | ||
function base64(s) { | ||
return Buffer(s).toString('base64'); | ||
return Buffer(s, 'binary').toString('base64'); | ||
} | ||
test('from string to base64url', function (t) { | ||
const b64 = base64(testString); | ||
const b64url = base64url(testString); | ||
const b64 = base64(testBuffer); | ||
const b64url = base64url(testBuffer, 'binary'); | ||
t.same(b64url.indexOf('+'), -1, 'should not contain plus signs'); | ||
@@ -22,4 +22,4 @@ t.same(b64url.indexOf('/'), -1, 'should not contain slashes'); | ||
test('from base64url to base64', function (t) { | ||
const b64 = base64(testString); | ||
const b64url = base64url(testString); | ||
const b64 = base64(testBuffer); | ||
const b64url = base64url(testBuffer, 'binary'); | ||
const result = base64url.toBase64(b64url); | ||
@@ -31,4 +31,4 @@ t.same(result, b64, 'should be able to convert back'); | ||
test('from base64 to base64url', function (t) { | ||
const b64 = base64(testString); | ||
const b64url = base64url(testString); | ||
const b64 = base64(testBuffer); | ||
const b64url = base64url(testBuffer, 'binary'); | ||
const result = base64url.fromBase64(b64); | ||
@@ -40,5 +40,5 @@ t.same(result, b64url, 'should be able to convert to b64url from b64'); | ||
test('from base64url to string', function (t) { | ||
const b64url = base64url(testString); | ||
const result = base64url.decode(b64url); | ||
t.same(Buffer(result), Buffer(testString), 'should be able to decode'); | ||
const b64url = base64url(testBuffer, 'binary'); | ||
const result = base64url.decode(b64url, 'binary'); | ||
t.same(result, testBuffer.toString('binary'), 'should be able to decode'); | ||
t.end(); | ||
@@ -48,5 +48,5 @@ }); | ||
test('from base64url to string (buffer)', function (t) { | ||
const b64url = base64url(testString); | ||
const result = base64url.decode(Buffer(b64url)); | ||
t.same(Buffer(result), Buffer(testString), 'should be able to decode'); | ||
const b64url = base64url(testBuffer, 'binary'); | ||
const result = base64url.decode(new Buffer(b64url), 'binary'); | ||
t.same(result, testBuffer.toString('binary'), 'should be able to decode'); | ||
t.end(); | ||
@@ -56,6 +56,6 @@ }); | ||
test('from base64url to buffer', function (t) { | ||
const b64url = base64url(testString); | ||
const b64url = base64url(testBuffer, 'binary'); | ||
const result = base64url.toBuffer(b64url); | ||
t.same(result, Buffer(testString), 'should be able to convert to buffer'); | ||
t.same(result, testBuffer, 'should be able to convert to buffer'); | ||
t.end(); | ||
}); |
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
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
99895