Skip to content

Commit

Permalink
Merge pull request #1 from jrgleason/ESM_REFACTOR
Browse files Browse the repository at this point in the history
Moving everything around
  • Loading branch information
jrgleason committed Jun 24, 2019
2 parents d46adc1 + 6e59a62 commit cb07968
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 424 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ lib-cov
*.pid
*.gz

*.iml

pids
logs
results
Expand Down
78 changes: 0 additions & 78 deletions Gruntfile.js

This file was deleted.

20 changes: 0 additions & 20 deletions bower.json

This file was deleted.

125 changes: 0 additions & 125 deletions build/jwt-decode.js

This file was deleted.

1 change: 0 additions & 1 deletion build/jwt-decode.min.js

This file was deleted.

15 changes: 15 additions & 0 deletions lib/JWTErrors.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// TODO: Class?
function InvalidCharacterError(message) {
this.message = message;
}

InvalidCharacterError.prototype = new Error();
InvalidCharacterError.prototype.name = 'InvalidCharacterError';

function InvalidTokenError(message) {
this.message = message;
}
InvalidTokenError.prototype = new Error();
InvalidTokenError.prototype.name = 'InvalidTokenError';

export { InvalidCharacterError, InvalidTokenError }
23 changes: 7 additions & 16 deletions lib/atob.js → lib/atob.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
* The code was extracted from:
* https://github.com/davidchambers/Base64.js
*/

var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

function InvalidCharacterError(message) {
this.message = message;
}

InvalidCharacterError.prototype = new Error();
InvalidCharacterError.prototype.name = 'InvalidCharacterError';

function polyfill (input) {
var str = String(input).replace(/=+$/, '');
import { InvalidCharacterError } from "./JWTErrors.mjs"
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function atob(input) {
const str = String(input).replace(/=+$/, "");
let output = "";
if (str.length % 4 == 1) {
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");
}
for (
// initialize result and counters
var bc = 0, bs, buffer, idx = 0, output = '';
let bc = 0, bs, buffer, idx = 0;
// get next character
buffer = str.charAt(idx++);
// character found in table? initialize bit storage and add its ascii value;
Expand All @@ -34,5 +26,4 @@ function polyfill (input) {
return output;
}


module.exports = typeof window !== 'undefined' && window.atob && window.atob.bind(window) || polyfill;
export { atob }
4 changes: 2 additions & 2 deletions lib/base64_url_decode.js → lib/base64_url_decode.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var atob = require('./atob');
import { atob } from "./atob.mjs";

function b64DecodeUnicode(str) {
return decodeURIComponent(atob(str).replace(/(.)/g, function (m, p) {
Expand All @@ -10,7 +10,7 @@ function b64DecodeUnicode(str) {
}));
}

module.exports = function(str) {
export default function(str) {
var output = str.replace(/-/g, "+").replace(/_/g, "/");
switch (output.length % 4) {
case 0:
Expand Down
14 changes: 4 additions & 10 deletions lib/index.js → lib/index.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
'use strict';

var base64_url_decode = require('./base64_url_decode');
import base64_url_decode from "./base64_url_decode.mjs";

function InvalidTokenError(message) {
this.message = message;
}
import { InvalidTokenError } from "./JWTErrors.mjs"

InvalidTokenError.prototype = new Error();
InvalidTokenError.prototype.name = 'InvalidTokenError';

module.exports = function (token,options) {
const decode = (token,options) => {
if (typeof token !== 'string') {
throw new InvalidTokenError('Invalid token specified');
}

options = options || {};
var pos = options.header === true ? 0 : 1;
try {
Expand All @@ -23,4 +17,4 @@ module.exports = function (token,options) {
}
};

module.exports.InvalidTokenError = InvalidTokenError;
export { decode, InvalidTokenError }
32 changes: 6 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
{
"name": "jwt-decode",
"version": "2.2.0",
"description": "Decode JWT tokens, mostly useful for browser applications.",
"main": "lib/index.js",
"name": "@jrg/jwt-decode",
"version": "0.0.6",
"description": "Decode JWT tokens, mostly useful for browser applications. Based on https://github.com/auth0/jwt-decode",
"main": "lib/index.mjs",
"keywords": [
"jwt",
"browser"
],
"scripts": {
"test": "grunt test"
},
"repository": {
"type": "git",
"url": "git://github.com/auth0/jwt-decode"
},
"author": "Jose F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)",
"author": "Jackie Gleason",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"expect.js": "~0.2.0",
"grunt": "~0.4.0",
"grunt-browserify": "~5.0.0",
"grunt-cli": "~0.1.9",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-watch": "~0.2.0",
"grunt-exec": "~0.4.2",
"grunt-s3": "~0.2.0-alpha.3",
"mocha": "~1.13.0",
"rimraf": "~2.2.2",
"testem": "~0.5.8",
"uglify-js": "^2.8.29"
}
"dependencies": {}
}

0 comments on commit cb07968

Please sign in to comment.