Skip to main content

Headers

Callable

  • Headers(values: Iterable<readonly [string, string], any, any> | Record<string, string>): Headers

  • HTTP header record constructor

    @example
    const headersFromIterable = Headers([
    ['key1', 'value1'],
    ['key2', 'value2']
    ]);// { key1: 'value1, key2: 'value2' }
    const headersFromObject = Headers({
    key1: 'value1',
    key2: 'value2'
    });// { key1: 'value1, key2: 'value2' }

Index

Codec

__decode__

  • __decode__(this: void, input: unknown, context: Context<Record<string, string>>): Result<Record<string, string>, CodecError>
  • Returns the decoded input, Result.Ok or Result.Error()

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const input: unknown = ...;
    const decoded = Codec.decode(someCodec, input);

__encode__

  • __encode__(this: void, input: Record<string, string>): unknown
  • Returns the encoded input

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const someObject: SomeObject = { foo: "bar" }
    const encoded = Codec.decode(someCodec, someObject);

__schema__

  • __schema__(this: void): JSONValue
  • Returns the JSONSchema corresponding to the decoded type

    @example
    const someCodec: Codec<unknown> = ...;
    const jsonSchema = Codec.schema(someCodec);

Formatting

asString

  • asString(this: void, self: Record<string, string>): string
  • Converts the given value to a String.

    @example
    Number.asString(123); // '123'

Type

__inspect__

__inspect__: Option<(anyValue: Record<string, string>, depth: number, options: InspectOptions, inspect: InspectFunction) => string>

When defined, returns a custom string representation. To be useful, it should be bound to a prototype (ex: Struct)

@example
import { inspect } from 'node:util';

interface Foo {
foo: boolean;
}
const Foo = Struct.define<Foo>({
typeName: 'Foo',
__inspect__: (self) => `Foo { ${String(self.foo)} }`,
});
const myStruct = Struct.create(Foo, { foo: true });// 'Foo { true }'
inspect(myStruct);// 'Foo { true }'
@param

asInstance

  • asInstance(anyValue: unknown): Option<Record<string, string>>
  • Try to convert anyValue to enum value or else returns Option.None

    @example
    const StringType: Type<string>;
    StringType.asInstance('foo'); // Option.Some('foo')
    StringType.asInstance(12); // Option.None

hasInstance

  • hasInstance(anyValue: unknown): anyValue is Record<string, string>
  • Return true if the given value is an instance of the class.

    @example
    const StringType: Type<string>;
    StringType.hasInstance('foo'); // true
    StringType.hasInstance(42); // false

Other

__call__

__call__: (values: Iterable<readonly [string, string], any, any> | Record<string, string>) => Headers = ...

empty

empty: () => Readonly<{}>

typeName

typeName: string = 'Headers'