@reasonableconsulting/url
Work with URLs in ReasonML.
Last updated 2 years ago by phated .
MPL-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @reasonableconsulting/url 
SYNC missed versions from official npm registry.

@reasonableconsulting/url

Work with URLs in ReasonML.

Travis Build Status AppVeyor Build Status

Usage

let url = Url.fromString("http://google.com/");
Js.log(url.pathname === Some("/"));

let str = Url.toString(url);
Js.log(str === "http://google.com/");

/* Or with base location */
let url = Url.fromString(~location=Url.fromString("http://google.com"), "/foo?foo=bar");

Js.log(url.href === "http://google.com/foo?foo=bar");

API

type t

The Url type. Has the shape:

{
  href: string,
  protocol: option(string),
  slashes: bool,
  origin: option(string),
  host: option(string),
  hostname: option(string),
  port: option(int),
  auth: option(string),
  username: option(string),
  password: option(string),
  pathname: option(string),
  querystring: option(string),
  hash: option(string),
}

empty

A completely empty Url.t.

toString(url)

Turns a Url.t into a string representation.

fromString(~location: t=?, string)

Turns a string into a Url.t. Optionally, takes a "base" Url.t as ~location.

make(~protocol: string=?, ~slashes: bool=?, ~host: string=?, ~hostname: string=?, ~port: int=?, ~auth: string=?, ~username: string=?, ~password: string=?, ~pathname: string=?, ~querystring: string=?, ~hash: string=?, unit)

Makes a Url.t from all the optional arguments. Useful if you are building up a Url to later stringify.

makeWithLocation(~protocol: string=?, ~slashes: bool=?, ~host: string=?, ~hostname: string=?, ~port: int=?, ~auth: string=?, ~username: string=?, ~password: string=?, ~pathname: string=?, ~querystring: string=?, ~hash: string=?, option(t))

Makes a Url.t from all the optional arguments and an option(Url.t) representing the "base" location. This method is mostly used internally but made available for other use cases.

Inspiration

The resolvePathname implementation is a rewrite of mjackson/resolve-pathname - Originally licensed, MIT License - Copyright (c) Michael Jackson 2016-2018.

The fromString, toString, and make implementations are a rewrite of unshiftio/url-parse - Originally licensed, MIT License - Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.

Current Tags

  • 0.1.0                                ...           latest (2 years ago)

1 Versions

  • 0.1.0                                ...           2 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 (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |