Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

parse-url

v0.0.11arrow_drop_down
v0.0.11
v0.0.10
v0.0.9
v0.0.8
v0.0.7
v0.0.6
v0.0.5
v0.0.4
v0.0.3
v0.0.2
v0.0.1
STATUS
Passing
DOWNLOADS
61
VISIBILITY
Public
PUBLISHED
3 years ago
SIZE
745 B
Creates an object from the given url.
Install parse-url as a package?
Copied
npm i @bit/gideonshils.url.global.parse-url
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
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
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'
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
```js
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