parse-url

v0.0.2arrow_drop_down
v0.0.2
v0.0.1
STATUS
Passing
DOWNLOADS
0
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 years ago
SIZE
760 B
Creates an object from the given url.
1 contributor
Install parse-url as a package?
Copied
npm i @bit/tomlandau.simple-js.global.parse-url
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
parseUrl (
url:string
) : object

Creates an object from the given url. If any property doesn’t exist in the provided url its value will be an empty string.

Example
var url = parseUrl('http://www.example.com:80/sample/path?user=john&type=administrator#sample') 
 
url.href          // => 'http://www.example.com:80/sample/path?user=john&type=administrator#sample'
url.searchParams  // => { user: 'john', type: 'administrator' }
url.hash          // => '#sample'
url.search        // => '?user=john&type=administrator'
url.protocol      // => 'http:'
url.hostname      // => 'www.example.com'
url.host          // => 'www.example.com:80'
url.path          // => '/sample/path/'
url.port          // => '80'
Argument
url: string

The url to parse

Returns
object

the parsed url object

Test Summary

parseUrl should return an object with a defined href property when a url is passed

Pass

parseUrl should return an object with a defined searchParams property when url contains a single parameter

Pass

parseUrl should return an object with a defined searchParams property when url contains multiple parameters

Pass

parseUrl should return an object with an empty searchParams property when the url has no query string

Pass

parseUrl should return an object with a defined hash property when a url is passed with a #

Pass

parseUrl should return an object with an empty hash property when a url is passed without a #

Pass

parseUrl should return an object with a defined query property when a url is passed with a query string

Pass

parseUrl should return an object with an empty query property when a url is passed without a query string

Pass

parseUrl should return an object with a correctly defined protocol property for http

Pass

parseUrl should return an object with a correctly defined protocol property for https

Pass

parseUrl should return an object with a correctly defined protocol property for ftp

Pass

parseUrl should return an object with a correctly defined protocol property for file

Pass

parseUrl should return an object with a default protocol of http if url does not contain a protocol

Pass

parseUrl should return an object with properly formatted host when a url is passed with specific port

Pass

parseUrl should return an object with properly formatted hostname when a url is passed with www

Pass

parseUrl should return an object with properly formatted hostname when a url is passed without www

Pass

parseUrl should return an object with a defined path property when a url is passed with a path

Pass

parseUrl should return an object with an empty path property when a url is passed without a path

Pass

parseUrl should return an object with an empty port property when a url is passed without a specified port

Pass

parseUrl should return an object with an defined port property when a url is passed with a specified port

Pass
Help and resources