Skip to content

Commit

Permalink
Merge 36aff43 into d951c19
Browse files Browse the repository at this point in the history
  • Loading branch information
levinunnink committed May 3, 2018
2 parents d951c19 + 36aff43 commit cf9b053
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
9 changes: 1 addition & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const parseBase64ByPlattform = base64String => {
if (!base64String || !isValidBase64(base64String)) throw new Error('No valid base64 passed')
if (!base64String) throw new Error('No valid base64 passed')

if (typeof window === 'undefined' && (process && process.version !== 'undefined')) {
return Buffer.from(base64String, 'base64').toString()
Expand All @@ -8,13 +8,6 @@ export const parseBase64ByPlattform = base64String => {
}
}

export const isValidBase64 = base64String => {
if (!base64String) return false
if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(base64String))) return false

return true
}

export const parseJwtToken = jwtToken => {
if (!jwtToken) return false
if (typeof jwtToken !== 'string') return false
Expand Down
10 changes: 0 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import { parseBase64ByPlattform, isValidBase64, parseJwtToken } from './index'
const jwtToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqd3QiOiJpcyBhd2Vzb21lISJ9.j8Z3twgi5nCrZJXH1JoxfQ8q1u5btwr3vS3wyqfytOo'

describe('JWT Valid', () => {
describe('isValidBase64', () => {
it('returns false if a not valid base64 string is passed', () => {
expect(isValidBase64('No Valid Base64 String')).to.equal(false)
})

it('returns true if a valid base64 string is passed', () => {
expect(isValidBase64('SSBhbSB2YWxpZA==')).to.equal(true)
})
})

describe('parseBase64ByPlattform', () => {
it('returns error if no valid token is passed', () => {
expect(() => parseBase64ByPlattform()).to.throw('No valid base64 passed')
Expand Down

0 comments on commit cf9b053

Please sign in to comment.