Comparing version 0.0.2 to 0.0.3
32
index.js
@@ -1,8 +0,4 @@ | ||
function base64url(stringOrBuffer) { | ||
return fromBase64(Buffer(stringOrBuffer).toString('base64')); | ||
} | ||
function fromBase64(b64string) { | ||
function fromBase64(base64string) { | ||
return ( | ||
b64string | ||
base64string | ||
.replace(/=/g, '') | ||
@@ -14,2 +10,9 @@ .replace(/\+/g, '-') | ||
function toBase64(base64UrlString) { | ||
const b64str = padString(base64UrlString) | ||
.replace(/\-/g, '+') | ||
.replace(/_/g, '/'); | ||
return b64str; | ||
} | ||
function padString(string) { | ||
@@ -19,6 +22,4 @@ const segmentLength = 4; | ||
const diff = string.length % segmentLength; | ||
if (!diff) | ||
return string; | ||
var position = stringLength; | ||
@@ -34,11 +35,14 @@ var padLength = segmentLength - diff; | ||
base64url.toBase64 = function toBase64(base64UrlString) { | ||
const b64str = padString(base64UrlString) | ||
.replace(/\-/g, '+') | ||
.replace(/_/g, '/'); | ||
return b64str; | ||
}; | ||
function decodeBase64Url(base64UrlString, encoding) { | ||
return Buffer(toBase64(base64UrlString), 'base64').toString(encoding); | ||
} | ||
function base64url(stringOrBuffer) { | ||
return fromBase64(Buffer(stringOrBuffer).toString('base64')); | ||
} | ||
base64url.toBase64 = toBase64; | ||
base64url.fromBase64 = fromBase64; | ||
base64url.decode = decodeBase64Url; | ||
module.exports = base64url; |
{ | ||
"name": "base64url", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "For encoding to/from base64urls", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,2 +22,5 @@ # base64url [![Build Status](https://secure.travis-ci.org/brianloveswords/base64url.png)](http://travis-ci.org/brianloveswords/base64url) | ||
const b64url = base64url.fromBase64(b64) | ||
// decode base64url | ||
data === base64url.decode(encoded); | ||
``` |
@@ -36,1 +36,8 @@ const fs = require('fs'); | ||
}); | ||
test('from base64url to string', function (t) { | ||
const b64url = base64url(testString); | ||
const result = base64url.decode(b64url); | ||
t.same(result, testString, 'should be able to decode'); | ||
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
92799
75
26