Socket
Book a DemoInstallSign in
Socket

@reasonableconsulting/url

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

@reasonableconsulting/url

Work with URLs in ReasonML.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@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.

Keywords

Reason

FAQs

Package last updated on 15 Dec 2018

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