JSPM

@brillout/url-props

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19
  • Score
    100M100P100Q38807F

Package Exports

  • @brillout/url-props

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@brillout/url-props) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Fully-featured URL parsing.

  • Works in Node.js.
  • Works in the browser.
  • Parses URLs with hostname, e.g. https://example.org/hello/there, as well as URLs without origin, e.g. /hello/there.
  • Parses the query string.
  • Pretty logging when doing console.log(parseUrl('https://example.org/hello/there')).

Running

// ./example.js

const getUrlProps = require('@brillout/url-props');

console.log(getUrlProps('http://localhost:3000/hi'));
console.log(getUrlProps('hello/there?opt=1#sectionA'));

prints

{
  url: 'http://localhost:3000/hi',
  href: 'http://localhost:3000/hi',
  origin: 'http://localhost:3000',
  protocol: 'http:',
  hostname: 'localhost',
  port: '3000',
  pathname: '/hi',
  query: {},
  queryString: '',
  hash: ''
}
{
  url: 'hello/there?opt=1#sectionA',
  href: null,
  origin: null,
  protocol: null,
  hostname: null,
  port: null,
  pathname: '/hello/there',
  query: { opt: '1' },
  queryString: '?opt=1',
  hash: '#sectionA'
}