Welcome to mirror list, hosted at ThFree Co, Russian Federation.

url.js « src - github.com/twbs/bootlint.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd49ed6665fe8cb0ddd60fa6480dfc5b2651ee28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-env browser */

/**
 * Simple lightweight shim of Node.js's `url.parse()`
 * ( https://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;
})();