Skip to main content Link Search Menu Expand Document (external link)

UrlParams overview

Added in v1.0.0


Table of contents


combinators

append

Signature

export declare const append: {
  (key: string, value: Coercible): (self: UrlParams) => UrlParams
  (self: UrlParams, key: string, value: Coercible): UrlParams
}

Added in v1.0.0

appendAll

Signature

export declare const appendAll: {
  (input: Input): (self: UrlParams) => UrlParams
  (self: UrlParams, input: Input): UrlParams
}

Added in v1.0.0

getAll

Signature

export declare const getAll: {
  (key: string): (self: UrlParams) => ReadonlyArray<string>
  (self: UrlParams, key: string): ReadonlyArray<string>
}

Added in v1.0.0

getFirst

Signature

export declare const getFirst: {
  (key: string): (self: UrlParams) => Option.Option<string>
  (self: UrlParams, key: string): Option.Option<string>
}

Added in v1.0.0

getLast

Signature

export declare const getLast: {
  (key: string): (self: UrlParams) => Option.Option<string>
  (self: UrlParams, key: string): Option.Option<string>
}

Added in v1.0.0

remove

Signature

export declare const remove: {
  (key: string): (self: UrlParams) => UrlParams
  (self: UrlParams, key: string): UrlParams
}

Added in v1.0.0

set

Signature

export declare const set: {
  (key: string, value: Coercible): (self: UrlParams) => UrlParams
  (self: UrlParams, key: string, value: Coercible): UrlParams
}

Added in v1.0.0

setAll

Signature

export declare const setAll: {
  (input: Input): (self: UrlParams) => UrlParams
  (self: UrlParams, input: Input): UrlParams
}

Added in v1.0.0

constructors

empty

Signature

export declare const empty: UrlParams

Added in v1.0.0

fromInput

Signature

export declare const fromInput: (input: Input) => UrlParams

Added in v1.0.0

conversions

makeUrl

Signature

export declare const makeUrl: (url: string, params: UrlParams, hash: Option.Option<string>) => Either.Either<URL, Error>

Added in v1.0.0

toRecord

Builds a Record containing all the key-value pairs in the given UrlParams as string (if only one value for a key) or a NonEmptyArray<string> (when more than one value for a key)

Signature

export declare const toRecord: (self: UrlParams) => Record<string, string | Arr.NonEmptyArray<string>>

Example

import { UrlParams } from "@effect/platform"

const urlParams = UrlParams.fromInput({ a: 1, b: true, c: "string", e: [1, 2, 3] })
const result = UrlParams.toRecord(urlParams)

assert.deepStrictEqual(result, { a: "1", b: "true", c: "string", e: ["1", "2", "3"] })

Added in v1.0.0

toString

Signature

export declare const toString: (self: UrlParams) => string

Added in v1.0.0

models

Coercible (type alias)

Signature

export type Coercible = string | number | bigint | boolean | null | undefined

Added in v1.0.0

Input (type alias)

Signature

export type Input =
  | Readonly<Record<string, Coercible | ReadonlyArray<Coercible>>>
  | Iterable<readonly [string, Coercible]>
  | URLSearchParams

Added in v1.0.0

UrlParams (interface)

Signature

export interface UrlParams extends ReadonlyArray<readonly [string, string]> {}

Added in v1.0.0

schema

schemaJson

Signature

export declare const schemaJson: <A, I, R>(
  schema: Schema.Schema<A, I, R>,
  options?: ParseOptions | undefined
) => {
  (field: string): (self: UrlParams) => Effect.Effect<A, ParseResult.ParseError, R>
  (self: UrlParams, field: string): Effect.Effect<A, ParseResult.ParseError, R>
}

Added in v1.0.0

schemaStruct

Extract schema from all key-value pairs in the given UrlParams.

Signature

export declare const schemaStruct: <A, I extends Record<string, string | ReadonlyArray<string> | undefined>, R>(
  schema: Schema.Schema<A, I, R>,
  options?: ParseOptions | undefined
) => (self: UrlParams) => Effect.Effect<A, ParseResult.ParseError, R>

Example

import { Effect, Schema } from "effect"
import { UrlParams } from "@effect/platform"

Effect.gen(function* () {
  const urlParams = UrlParams.fromInput({ a: [10, "string"], b: false })
  const result = yield* UrlParams.schemaStruct(
    Schema.Struct({
      a: Schema.Tuple(Schema.NumberFromString, Schema.String),
      b: Schema.BooleanFromString
    })
  )(urlParams)

  assert.deepStrictEqual(result, {
    a: [10, "string"],
    b: false
  })
})

Added in v1.0.0

schemas

schema

Signature

export declare const schema: Schema.Schema<UrlParams, readonly (readonly [string, string])[]>

Added in v1.0.0