Comparing version 0.2.0 to 1.0.0
@@ -5,2 +5,46 @@ // Dependencies | ||
console.log(ParseUrl("http://ionicabizau.net/blog")); | ||
console.log(ParseUrl("http://ionicabizau.net/blog")); | ||
// => { | ||
// protocols: [ "http" ] | ||
// , port: null | ||
// , resource: "ionicabizau.net" | ||
// , user: "" | ||
// , pathname: "/blog" | ||
// , hash: "" | ||
// , search: "" | ||
// , href: "http://ionicabizau.net/blog" | ||
// } | ||
console.log(ParseUrl("http://domain.com/path/name?foo=bar&bar=42#some-hash")); | ||
// => { | ||
// protocols: ["http"] | ||
// , port: null | ||
// , resource: "domain.com" | ||
// , user: "" | ||
// , pathname: "/path/name" | ||
// , hash: "some-hash" | ||
// , search: "foo=bar&bar=42" | ||
// , href: "http://domain.com/path/name?foo=bar&bar=42#some-hash" | ||
// } | ||
console.log(ParseUrl("git+ssh://git@host.xz/path/name.git")); | ||
// => { | ||
// protocols: ["git", "ssh"] | ||
// , port: null | ||
// , resource: "host.xz" | ||
// , user: "git" | ||
// , pathname: "/path/name.git" | ||
// , hash: "" | ||
// , search: "" | ||
// } | ||
console.log(ParseUrl("git@github.com:IonicaBizau/git-stats.git")); | ||
// => { | ||
// protocols: [] | ||
// , port: null | ||
// , resource: "github.com" | ||
// , user: "git" | ||
// , pathname: "/IonicaBizau/git-stats.git" | ||
// , hash: "" | ||
// , search: "" | ||
// , href: "git@github.com:IonicaBizau/git-stats.git" | ||
// } |
@@ -12,2 +12,11 @@ // Dependencies | ||
* @return {Object} An object containing the following fields: | ||
* | ||
* - `protocols` (Array): An array with the url protocols (usually it has one element). | ||
* - `port` (null|Number): The domain port. | ||
* - `resource` (String): The url domain (including subdomains). | ||
* - `user` (String): The authentication user (usually for ssh urls). | ||
* - `pathname` (String): The url pathname. | ||
* - `hash` (String): The url hash. | ||
* - `search` (String): The url querystring value. | ||
* - `href` (String): The input url. | ||
*/ | ||
@@ -21,3 +30,5 @@ function ParseUrl(url) { | ||
, pathname: "" | ||
, token: "" | ||
, hash: "" | ||
, search: "" | ||
, href: url | ||
} | ||
@@ -37,2 +48,3 @@ , protocolIndex = url.indexOf("://") | ||
// user@domain | ||
splits = output.resource.split("@"); | ||
@@ -43,18 +55,38 @@ if (splits.length === 2) { | ||
} | ||
// domain.com:port | ||
splits = output.resource.split(":"); | ||
if (splits.length === 2 && splits[1]) { | ||
if (splits.length === 2) { | ||
output.resource = splits[0]; | ||
output.port = isNaN(splits[1]) ? splits[1] : parseInt(splits[1]); | ||
output.port = parseInt(splits[1]); | ||
if (isNaN(output.port)) { | ||
output.port = null; | ||
parts.unshift(splits[1]); | ||
} | ||
} | ||
splits = output.user.split(":"); | ||
if (splits.length === 2 && splits[1] === "x-oauth-basic") { | ||
output.token = splits[0]; | ||
} | ||
// Remove empty elements | ||
parts = parts.filter(Boolean); | ||
parts = parts.filter(Boolean); | ||
// Stringify the pathname | ||
output.pathname = "/" + parts.join("/"); | ||
// #some-hash | ||
splits = output.pathname.split("#"); | ||
if (splits.length === 2) { | ||
output.pathname = splits[0]; | ||
output.hash = splits[1]; | ||
} | ||
// ?foo=bar | ||
splits = output.pathname.split("?"); | ||
if (splits.length === 2) { | ||
output.pathname = splits[0]; | ||
output.search = splits[1]; | ||
} | ||
return output; | ||
} | ||
module.exports = ParseUrl; |
{ | ||
"name": "parse-url", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "An advanced url parser supporting git urls too.", | ||
"main": "lib/index.js", | ||
"directories": { | ||
"example": "example" | ||
"example": "example", | ||
"test": "test" | ||
}, | ||
@@ -28,3 +29,9 @@ "scripts": { | ||
}, | ||
"homepage": "https://github.com/IonicaBizau/node-parse-url" | ||
} | ||
"homepage": "https://github.com/IonicaBizau/node-parse-url", | ||
"dependencies": { | ||
"protocols": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.2.5" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13294
9
194
0
0
111
1
1
80
+ Addedprotocols@^1.1.0
+ Addedprotocols@1.4.8(transitive)