Comparing version 0.11.0 to 0.11.1
57
index.js
@@ -1,21 +0,64 @@ | ||
var base64 = exports; | ||
var buffer64 = exports; | ||
base64.encode = function(unencoded) { | ||
buffer64.encode = function(unencoded) { | ||
return new Buffer(unencoded || '').toString('base64'); | ||
}; | ||
base64.decode = function(encoded) { | ||
buffer64.decode = function(encoded) { | ||
return new Buffer(encoded || '', 'base64').toString('utf8'); | ||
}; | ||
base64.urlEncode = function(unencoded) { | ||
var encoded = base64.encode(unencoded); | ||
buffer64.urlEncode = function(unencoded) { | ||
var encoded = buffer64.encode(unencoded); | ||
return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); | ||
}; | ||
base64.urlDecode = function(encoded) { | ||
buffer64.urlDecode = function(encoded) { | ||
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/'); | ||
while (encoded.length % 4) | ||
encoded += '='; | ||
return base64.decode(encoded); | ||
return buffer64.decode(encoded); | ||
}; | ||
buffer64.ripper = function(href, output){ | ||
var output = output || 'all', | ||
rx = /(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/i, | ||
quoter = href.indexOf('?'), | ||
schemer = href.indexOf('://'), | ||
query = quoter > -1 ? href.substr(quoter, href.length) : undefined; | ||
if(!href) | ||
return "ERROR: Missing encoded(url) parameter."; | ||
if(schemer == -1) href = 'http://' + href; | ||
if(query) href = href.split(query).shift(); | ||
if(href[href.length - 1] !== '/') href += '/'; | ||
var schema = href.substr(0, href.indexOf('://') + 3), | ||
subdomain = (href.match(rx) || [""]).shift().split(schema).pop() || "", | ||
anfitrion = href.split(schema + subdomain).pop(), | ||
domain = anfitrion.substr(0, anfitrion.indexOf('/')), | ||
path = anfitrion.substr(anfitrion.indexOf('/'), anfitrion.length), | ||
extension = domain.substr(domain.indexOf('.'), domain.length - 1), | ||
root = path === '/' ? true : false, | ||
uri = (subdomain || 'www.') + domain + path, | ||
hash = buffer64.urlEncode(uri), | ||
ripped = { | ||
anfitrion: anfitrion, | ||
domain: domain, | ||
extension: extension, | ||
hash: hash, | ||
href: href, | ||
path: path, | ||
query: query, | ||
root: root, | ||
schema: schema, | ||
subdomain: subdomain, | ||
uri: uri | ||
}; | ||
if(output === 'all') | ||
return ripped; | ||
return ripped[output] || 'ERROR: undefined output parameter.'; | ||
}; |
{ | ||
"name": "buffer64", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "Super easy native-node buffer and url safe encoding", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2758
65