Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

url-parse-as-address

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-parse-as-address

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
increased by46.32%
Maintainers
1
Weekly downloads
 
Created
Source

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

  • https://iojs.org/api/url.html
  • https://nodejs.org/api/url.html

Keywords

FAQs

Package last updated on 20 Jan 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc