forked from twbs/bootlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request twbs#182 from twbs/W005
improve W005 checker by properly parsing URL and checking filename
- Loading branch information
Showing
3 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*eslint-env node, browser */ | ||
/* jshint browser: true */ | ||
/** | ||
* Simple lightweight shim of Node.js's `url.parse()` | ||
* ( http://nodejs.org/docs/latest/api/url.html ) | ||
* for use within browsers. | ||
*/ | ||
(function () { | ||
'use strict'; | ||
|
||
// Only properties common to both browsers and Node.js are supported. | ||
// For what browsers support, see https://developer.mozilla.org/en-US/docs/Web/API/URLUtils | ||
var URL_PROPERTIES = [ | ||
'hash', | ||
'host', | ||
'hostname', | ||
'href', | ||
'pathname', | ||
'port', | ||
'protocol', | ||
'search' | ||
]; | ||
|
||
/** | ||
* @param {string} urlStr URL to parse | ||
* @returns {object} Object with fields representing the various parts of the parsed URL. | ||
*/ | ||
function parse(urlStr) { | ||
var anchor = document.createElement('a'); | ||
anchor.href = urlStr; | ||
var urlObj = {}; | ||
URL_PROPERTIES.forEach(function (property) { | ||
urlObj[property] = anchor[property]; | ||
}); | ||
return urlObj; | ||
} | ||
exports.parse = parse; | ||
})(); |