Skip to content

afeiship/url-parse

Repository files navigation

url-parse

To parse an URL to object.

version license size download

installation

yarn add @jswork/url-parse

usage

import urlParse from '@jswork/url-parse';

// URL with protocol
const parsedUrl1 = urlParse('https://www.example.com/path?query=value#hash');
console.log(parsedUrl1.protocol); // 'https:'
console.log(parsedUrl1.hostname); // 'www.example.com'

// URL without protocol (http:// will be added)
const parsedUrl2 = urlParse('www.example.com/another-path');
console.log(parsedUrl2.protocol); // 'http:'
console.log(parsedUrl2.hostname); // 'www.example.com'

// URL with only domain
const parsedUrl3 = urlParse('example.com');
console.log(parsedUrl3.protocol); // 'http:'
console.log(parsedUrl3.hostname); // 'example.com'
console.log(parsedUrl3.pathname); // '/'

// URL with IP address
const parsedUrl4 = urlParse('192.168.1.1/dashboard');
console.log(parsedUrl4.protocol); // 'http:'
console.log(parsedUrl4.hostname); // '192.168.1.1'

license

Code released under the MIT license.

About

To parse an URL to object.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published