Socket
Socket
Sign inDemoInstall

universal-parse-url

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    universal-parse-url

A universal URL parser for Node.js and browser environments with a minimal footprint.


Version published
Weekly downloads
124
increased by10.71%
Maintainers
1
Install size
9.90 kB
Created
Weekly downloads
 

Changelog

Source

1.0.2 (2017-11-22)

Bug Fixes

  • prepend slash to pathname when it does not start with a slash (#35) (f31b81e)

<a name="1.0.1"></a>

Readme

Source

universal-parse-url

NPM Travis Build Status Commitizen Friendly MIT License

Sauce Labs Build Status

A universal URL parser for Node.js and browser environments with a minimal footprint (gzipped only 600 bytes for the browser version).

Installation

Install with npm:

npm install --save universal-parse-url

Note: The installed node module also includes a d.ts file, and thus works out of the box with TypeScript.

Usage

import { parseURL } from 'universal-parse-url';
const url = parseURL('http://www.example.com:1234/foo?bar=1#baz');

The resulting url object looks like this:

{
  hash: '#baz',
  host: 'www.example.com:1234',
  hostname: 'www.example.com',
  href: 'http://www.example.com:1234/foo?bar=1#baz',
  pathname: '/foo',
  port: '1234',
  protocol: 'http:',
  search: '?bar=1'
}

How It Works

  • In Node.js parseURL just delegates to URL.parse.
  • In browser environments:
    • An HTMLAnchorElement is created initially (with document.createElement('a')).
    • When parseURL is called, the href attribute of this element is set to the given url string.
    • The element is then used to extract the URL details.

Requirements

If you plan on targeting browser environments as well, you need to use a bundler like Webpack, Browserify or Rollup (with rollup-plugin-node-resolve) that makes use of the browser field in the package.json.

Caveats

To keep universal-parse-url as small and simple as possible, only the URL details that are available in Node’s URL object as well as HTMLAnchorElement are supported (see the above example).

Keywords

FAQs

Last updated on 22 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc