JSPM

  • Created
  • Published
  • Downloads 26585211
  • Score
    100M100P100Q218139F
  • License MIT

Parse URL in node using the URL module and in the browser using the DOM

Package Exports

  • url-parse

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 (url-parse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

url-parse

Build Status NPM version Coverage Status

When required on node it will expose the url module's .parse method. When required in the browser it will offload the URL parsing to the <a> element in the DOM. This allows the module to be really tiny on the browser and still be usable on node.

In addition to parsing URL's it also has a really simple query string parser and query string stringify.

Installation

This module is designed to be used using either browserify or node.js it's released in the public npm registry and can be installed using:

npm install url-parse

Usage

All examples assume that this library is bootstrapped using:

'use strict';

var parse = require('url-parse');

To parse an URL simply call the parse method with the URL that needs to be transformed in to an object.

var url = parse('https://github.com/foo/bar');

The URL should now be somewhat the same as the node.js's url.parse output. The notable exception being that in the browser not all properties would be set to null.

parse.querystring()

Parse the given query string and return an object representation from it.

parse.querystring('foo=bar&bar=foo');
parse.querystring('?foo=bar&bar=foo');

parse.querystringify()

Take an object and make a query string from it.

parse.querystringify({ foo: 'bar' });       // foo=bar
parse.querystringify({ foo: 'bar' }, true); // ?foo=bar
parse.querystringify({ foo: 'bar' }, '&');  // &foo=bar

License

MIT