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

UrlParams.ts overview

Since v1.0.0


Exports Grouped by Category


combinators

append

Signature

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

Source

Since v1.0.0

appendAll

Signature

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

Source

Since v1.0.0

getAll

Signature

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

Source

Since v1.0.0

getFirst

Signature

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

Source

Since v1.0.0

getLast

Signature

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

Source

Since v1.0.0

remove

Signature

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

Source

Since v1.0.0

set

Signature

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

Source

Since v1.0.0

setAll

Signature

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

Source

Since v1.0.0

constructors

empty

Signature

declare const empty: UrlParams

Source

Since v1.0.0

fromInput

Signature

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

Source

Since v1.0.0

conversions

makeUrl

Signature

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

Source

Since 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)

Example

import * as assert from "node:assert"
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"] })

Signature

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

Source

Since v1.0.0

toString

Signature

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

Source

Since v1.0.0

models

Coercible (type alias)

Signature

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

Source

Since v1.0.0

CoercibleRecord (interface)

Signature

export interface CoercibleRecord {
  readonly [key: string]: Coercible | ReadonlyArray<Coercible> | CoercibleRecord
}

Source

Since v1.0.0

Input (type alias)

Signature

type Input = CoercibleRecord | Iterable<readonly [string, Coercible]> | URLSearchParams

Source

Since v1.0.0

UrlParams (interface)

Signature

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

Source

Since v1.0.0

schema

schemaJson

Signature

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>
}

Source

Since v1.0.0

schemaStruct

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

Example

import * as assert from "node:assert"
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
  })
})

Signature

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>

Source

Since v1.0.0

schemas

schema

Signature

declare const schema: Schema.Schema<UrlParams, ReadonlyArray<readonly [string, string]>>

Source

Since v1.0.0