Skip to content

Commit

Permalink
better docs, adding to namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed May 11, 2018
1 parent 6b1f678 commit d5ecc77
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
22 changes: 11 additions & 11 deletions can-parse-uri-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var QUnit = require('steal-qunit');
QUnit.module("can-parse-uri");

QUnit.test("basics", function(){
QUnit.deepEqual(parseURI("http://foo:8080/bar.html#change"), {
authority: "//foo:8080",
hash: "#change",
host: "foo:8080",
hostname: "foo",
href: "http://foo:8080/bar.html#change",
pathname: "/bar.html",
port: "8080",
protocol: "http:",
search: ""
});
QUnit.deepEqual(parseURI("http://foo:8080/bar.html?query#change"), {
authority: "//foo:8080",
hash: "#change",
host: "foo:8080",
hostname: "foo",
href: "http://foo:8080/bar.html?query#change",
pathname: "/bar.html",
port: "8080",
protocol: "http:",
search: "?query"
});
});
23 changes: 20 additions & 3 deletions can-parse-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@
*
* Parse a URI into its components.
*
* ```js
* import {parseURI} from "can"
* parseURI("http://foo:8080/bar.html?query#change")
* //-> {
* // authority: "//foo:8080",
* // hash: "#change",
* // host: "foo:8080",
* // hostname: "foo",
* // href: "http://foo:8080/bar.html?query#change",
* // pathname: "/bar.html",
* // port: "8080",
* // protocol: "http:",
* // search: "?query"
* // }
* ```
*
* @param {String} url The URL you want to parse.
*
* @return {Object} Returns an object with properties for each part of the URL.
* @return {Object} Returns an object with properties for each part of the URL. `null`
* is returned if the url can not be parsed.
*/

module.exports = function(url){
var namespace = require("can-namespace");
module.exports = namespace.parseURI = function(url){
var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
// authority = '//' + user + ':' + pass '@' + hostname + ':' port
return (m ? {
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"develop": "done-serve --static --develop --port 8080",
"detect-cycle": "detect-cyclic-packages --ignore done-serve"
},
"main": "dist/cjs/can-parse-uri",
"main": "can-parse-uri",
"keywords": [
"canjs",
"parse",
Expand All @@ -44,12 +44,11 @@
"steal-tools"
]
},
"dependencies": {},
"dependencies": {
"can-namespace": "^1.0.0"
},
"devDependencies": {
"detect-cyclic-packages": "^1.1.0",
"done-serve": "^1.0.0",
"donejs-cli": "^1.0.0",
"generator-donejs": "^1.0.0",
"jshint": "^2.9.1",
"steal": "^1.3.1",
"steal-qunit": "^1.0.1",
Expand Down

0 comments on commit d5ecc77

Please sign in to comment.