GithubHelp home page GithubHelp logo

jhiode / universal-parse-url Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unstubbable/universal-parse-url

0.0 0.0 0.0 46 KB

πŸ”— A universal URL parser for Node.js and browser environments with a minimal footprint.

License: MIT License

JavaScript 36.37% TypeScript 63.63%

universal-parse-url's Introduction

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).

universal-parse-url's People

Contributors

unstubbable avatar greenkeeper[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.