Skip to content

Commit

Permalink
Merge pull request #124 from launchdarkly/eb/ch26918/base64-dep
Browse files Browse the repository at this point in the history
replace Base64 dependency with a package that has a lowercase name
  • Loading branch information
eli-darkly committed Nov 21, 2018
2 parents d6c0f62 + d5228b6 commit b3c1778
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"typescript": "3.0.1"
},
"dependencies": {
"Base64": "1.0.1",
"base64-js": "1.3.0",
"escape-string-regexp": "1.0.5"
},
"repository": {
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/EventSender-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base64 from 'Base64';
import * as base64 from 'base64-js';
import sinon from 'sinon';

import EventSender from '../EventSender';
Expand Down Expand Up @@ -44,7 +44,9 @@ describe('EventSender', () => {
s = s + '=';
}
s = s.replace(/_/g, '/').replace(/-/g, '+');
return decodeURIComponent(escape(Base64.atob(s)));
const decodedBytes = base64.toByteArray(s);
const decodedStr = String.fromCharCode.apply(String, decodedBytes);
return decodeURIComponent(escape(decodedStr));
}

function decodeOutputFromUrl(url) {
Expand Down
13 changes: 11 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import Base64 from 'Base64';
import * as base64 from 'base64-js';

// See http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
export function btoa(s) {
return Base64.btoa(unescape(encodeURIComponent(s)));
const escaped = unescape(encodeURIComponent(s));
return base64.fromByteArray(stringToBytes(escaped));
}

function stringToBytes(s) {
const b = [];
for (let i = 0; i < s.length; i++) {
b.push(s.charCodeAt(i));
}
return b;
}

export function base64URLEncode(s) {
Expand Down

0 comments on commit b3c1778

Please sign in to comment.