Skip to content

Commit

Permalink
Merge 7cf1805 into 36e519b
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimserafim committed Jan 18, 2018
2 parents 36e519b + 7cf1805 commit c60e791
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: node_js
node_js:
- 6
- 8
- 9
branches:
only:
- master
Expand Down
19 changes: 12 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
'use strict'

const base64url = module.exports
module.exports = {
unescape,
escape,
encode,
decode
}

base64url.unescape = function unescape (str) {
function unescape (str) {
return (str + '==='.slice((str.length + 3) % 4))
.replace(/-/g, '+')
.replace(/_/g, '/')
}

base64url.escape = function escape (str) {
function escape (str) {
return str.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '')
}

base64url.encode = function encode (str, encoding) {
return this.escape(Buffer.from(str, encoding || 'utf8').toString('base64'))
function encode (str, encoding) {
return escape(Buffer.from(str, encoding || 'utf8').toString('base64'))
}

base64url.decode = function decode (str, encoding) {
return Buffer.from(this.unescape(str), 'base64').toString(encoding || 'utf8')
function decode (str, encoding) {
return Buffer.from(unescape(str), 'base64').toString(encoding || 'utf8')
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "base64-url",
"version": "2.0.1",
"version": "2.1.0",
"description": "Base64 encode, decode, escape and unescape for URL applications",
"main": "index.js",
"files": [
Expand Down Expand Up @@ -29,8 +29,8 @@
},
"homepage": "https://github.com/joaquimserafim/base64-url",
"devDependencies": {
"coveralls": "^2.13.1",
"nyc": "^11.1.0",
"coveralls": "^3.0.0",
"nyc": "^11.4.1",
"pre-commit": "^1.2.2",
"standard": "^10.0.3",
"tape": "^4.8.0"
Expand Down

0 comments on commit c60e791

Please sign in to comment.