JSPM

urltool

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q28361F
  • License MIT

Node Module & Browser Library for parsing, formatting and serializing URLs

Package Exports

  • urltool
  • urltool/dist.js

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

Readme

urltool

Node Module & Browser Library for parsing, formatting and serializing URLs

Import

In the browser, you can use UrlTool to access urltool However in node.js, you have to use require('urltool') to access urltool

Usage

Url

This class is used to parse and format URLs.

const url = new UrlTool.Url('http://example.com/path/to/file.html?param=value#hash')

.format(?template)

Format the URL.

url.format()

You can use custom templates by passing it as an argument. The default template is: {protocol}://{host}/{path}/{query}{hash}. Available properties are protocol, host, path, query, hostWithoutPort, port and hash.

.protocol

The protocol of the URL. e.g.: http

.host

The host of the URL. If the port isn't the default port for the given protocol, it will be included. e.g.: example.com, example.com:8080

.hostWithoutPort

The host of the URL ALWAYS without the port. e.g.: example.com

.port

The port of the URL. e.g.: 80

.path

The path of the URL. e.g.: /path/to/file.html

.query

The query of the URL. e.g.: ?param=value

.hash

The hash of the URL. e.g.: #hash

parseQuerystring(querystring)

Parse a querystring into an object.

UrlTool.parseQuerystring('param=value&param2=value2') // { param: 'value', param2: 'value2' }

stringifyQuerystring(query)

Stringify a query object into a querystring.

UrlTool.stringifyQuerystring({ param: 'value', param2: 'value2' }) // 'param=value&param2=value2'