Link Search Menu Expand Document

URL overview

Various functions to aid in working with JavaScript’s URL interface.

Added in v0.1.0


Table of contents


utils

isURL

Refine a foreign value to URL.

Signature

export declare const isURL: Refinement<unknown, URL>
isURL :: Refinement unknown URL

Example

import { isURL } from 'fp-ts-std/URL'

assert.strictEqual(isURL(new URL('https://samhh.com')), true)
assert.strictEqual(isURL({ not: { a: 'url' } }), false)

Added in v0.1.0

parse

Safely parse a URL.

Signature

export declare const parse: <E>(f: (e: TypeError) => E) => (x: string) => Either<E, URL>
parse :: (TypeError -> e) -> string -> Either e URL

Example

import { parse } from 'fp-ts-std/URL'
import * as E from 'fp-ts/Either'
import { constant } from 'fp-ts/function'

const f = parse(constant('e'))

assert.deepStrictEqual(f('https://samhh.com'), E.right(new URL('https://samhh.com')))
assert.deepStrictEqual(f('invalid'), E.left('e'))

Added in v0.1.0

parseO

Safely parse a URL, returning an Option.

Signature

export declare const parseO: (href: string) => Option<URL>
parseO :: string -> Option URL

Example

import { parseO } from 'fp-ts-std/URL'
import * as O from 'fp-ts/Option'

assert.deepStrictEqual(parseO('https://samhh.com'), O.some(new URL('https://samhh.com')))
assert.deepStrictEqual(parseO('invalid'), O.none)

Added in v0.1.0

unsafeParse

Unsafely parse a URL, throwing on failure.

Signature

export declare const unsafeParse: (x: string) => URL
unsafeParse :: string -> URL

Example

import { unsafeParse } from 'fp-ts-std/URL'

assert.deepStrictEqual(unsafeParse('https://samhh.com'), new URL('https://samhh.com'))

Added in v0.1.0