Comparing version 2.0.6 to 2.0.7
56
index.js
@@ -1,3 +0,1 @@ | ||
const URL = require('url').URL; | ||
const build = function(base, options) { | ||
@@ -54,3 +52,2 @@ let urlOut = ""; | ||
return urlOut; | ||
@@ -61,45 +58,28 @@ }; | ||
const parse = function(url){ | ||
let parse = function(url){ | ||
const urlObject = new URL(url); | ||
const path = urlObject.pathname.split('/'); | ||
const lastSegment = path[path.length - 1]; | ||
const out = {}; | ||
const segments = url.split("://"); | ||
let format, filename; | ||
const params = {}; | ||
if (lastSegment.indexOf('.') !== -1){ | ||
const file = lastSegment.split('.'); | ||
filename = file[0]; | ||
format = file[file.length - 1]; | ||
path.pop(); | ||
if (segments.length === 2) { | ||
out.protocol = segments[0]; | ||
url = segments[1]; | ||
} | ||
let [noParams, params] = (url + "?").split("?"); | ||
for(var pair of urlObject.searchParams.entries()) { | ||
if (params[pair[0]] != null){ | ||
if (typeof params[pair[0]] === 'string'){ | ||
let tmp = params[pair[0]]; | ||
params[pair[0]] = [tmp]; | ||
} | ||
params[pair[0]].push(pair[1]); | ||
} else { | ||
params[pair[0]] = pair[1]; | ||
} | ||
} | ||
const [parent, anchor] = params.split("#"); | ||
out.anchor = anchor; | ||
const list = noParams.split("/"); | ||
out.path = list.slice(1); | ||
out.host = list.slice(0, 1)[0]; | ||
out.params = {}; | ||
for (let pair of parent.split("&")) { | ||
const [key, value] = pair.split("="); | ||
return { | ||
path: path.filter(function(item){ return item !== '' }), | ||
filename, | ||
format, | ||
host: urlObject.host, | ||
port: urlObject.port, | ||
searchParams: urlObject.searchParams, | ||
params: params, | ||
hash: urlObject.hash.replace('#', ''), | ||
protocol: urlObject.protocol.replace(':', ''), | ||
password: urlObject.password, | ||
username: urlObject.username | ||
out.params[key] = value || null; | ||
} | ||
return out; | ||
}; | ||
@@ -106,0 +86,0 @@ |
{ | ||
"name": "brembo", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "A simple utility for building URLs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4963
67