Aller au contenu principal

UUID

UUID namespace

Index

Codec

__decode__

  • __decode__(this, input, context): Result<UUID, CodecError>
  • Returns the decoded input, Result.Ok or Result.Error()

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

__encode__

  • __encode__(this, input): unknown
  • Returns the encoded input

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

__schema__

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

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

Constructor

empty

  • Returns an UUID with only 0

    const emptyUUID = UUID.empty();// '00000000-0000-0000-0000-000000000000'

of

  • UUID constructor

    const uuid = UUID.of('1c19548b-7cac-4222-b722-dc38f2870669');

Formatting

asString

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

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

Type

__inspect__

__inspect__: Option<(anyValue, depth, options, inspect) => string>

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

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

asInstance

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

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

hasInstance

  • hasInstance(this, anyValue): anyValue is UUID
  • Return true if the given value is an instance of the class.

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

unwrap

  • unwrap(value): `${string}-${string}-${string}-${string}-${string}`
  • Convert a tagged value to the underlying type

wrap

  • wrap(value): UUID
  • Convert an underlying type to a tagged type

Other

typeName

Re-exports typeName

__call__

  • __call__(value): UUID

toBigInt

  • toBigInt(self): bigint
  • Returns a bigint from UUID

    const uuid = UUID('1c19548b-7cac-4222-b722-dc38f2870669');
    const bigint = UUID.toBigInt(uuid);// BigInt('Ox1c19548b7cac4222b722dc38f2870669');

toUint32Array

  • toUint32Array(self): Uint32Array
  • Converts a UUID to an array of uint32 values.

    const uuid: UUID;
    const parts = UUID.toUint32Array(uuid);