url-parse-as-address
Parse a url assuming `http` if no protocol or `//` is provided.
Last updated 10 years ago by isaacs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install url-parse-as-address 
SYNC missed versions from official npm registry.

url-parse-as-address

Parse a url assuming http if no protocol or // is provided.

Useful for parsing things like foo.com and not interpreting it as a path.

USAGE

var parse = require('url-parse-as-address')
var assert = require('assert')

assert.deepEqual(parse('foo.com:1234/x?y=z#a=b'),
  { protocol: 'http:',
    slashes: true,
    auth: null,
    host: 'foo.com:1234',
    port: '1234',
    hostname: 'foo.com',
    hash: '#a=b',
    search: '?y=z',
    query: 'y=z',
    pathname: '/x',
    path: '/x?y=z',
    href: 'http://foo.com:1234/x?y=z#a=b' })

assert.deepEqual(parse('foo.com:1234/x?y=z#a=b', true),
  { protocol: 'http:',
    slashes: true,
    auth: null,
    host: 'foo.com:1234',
    port: '1234',
    hostname: 'foo.com',
    hash: '#a=b',
    search: '?y=z',
    query: { y: 'z' },
    pathname: '/x',
    path: '/x?y=z',
    href: 'http://foo.com:1234/x?y=z#a=b' })

// etc

By default this lib assumes http: is the protocol if none is provided, because that's what web browsers do.

API

  • parse(url, parseQueryString) Parse a string to object.

  • parse.parse(..) Same function, for symmetry to url builtin

  • parse.format(url) Like url.format()

SEE ALSO

Current Tags

  • 1.0.0                                ...           latest (10 years ago)

1 Versions

  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |