Enum
Index
Interfaces
Module
Type parameters
- T: Record<string, any> = Record<string, unknown>
typeName
readonlyinherited__enumKeys__
An array of all keys
inherited__inspect__
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 }'
inheritedindexType
Index type
inherited__decode__
Returns the decoded
input,Result.OkorResult.Error()interface SomeObject {foo: string}const someCodec: Codec<SomeObject> = ...;const input: unknown = ...;const decoded = Codec.decode(someCodec, input);
inherited__encode__
Returns the encoded
inputinterface SomeObject {foo: string}const someCodec: Codec<SomeObject> = ...;const someObject: SomeObject = { foo: "bar" }const encoded = Codec.decode(someCodec, someObject);
inherited__schema__
Returns the JSONSchema corresponding to the decoded type
const someCodec: Codec<unknown> = ...;const jsonSchema = Codec.schema(someCodec);
inheritedasInstance
Try to convert anyValue to enum value or else returns
Option.Noneconst StringType: Type<string>;StringType.asInstance('foo'); // Option.Some('foo')StringType.asInstance(12); // Option.None
inheritedasString
Converts the given value to a String.
Number.asString(123); // '123'
inheritedat
Returns the value at the index
inheritedhasInstance
Return
trueif the given value is an instance of the class.const StringType: Type<string>;StringType.hasInstance('foo'); // trueStringType.hasInstance(42); // false
inheritedindexOf
Returns the integer index of a value
inheritedrange
Returns an Iterable starting from
starttoend. Ifstartorendis not in range then returns an empty iterable.
inheritedrangeSize
Returns the size of a range. If
startorendis not in range then returns 0.
Type Aliases
KeyOf
ValueOf
Variables
enumKeys
Symbol for the property holding enum keys
Functions
define
Define a new Enum Object
const MyEnum = Enum.define({// typeName: 'MyEnum', // Add this we want a named EnumFoo: 'foo',Bar: 'bar',});
keys
Returns an array of enum keys
const MyEnum = Enum.define({ Foo: 'foo', Bar: 'bar' });Enum.keys(MyEnum) // ['Foo', 'Bar']
values
Returns an array of enum values
const MyEnum = Enum.define({ Foo: 'foo', Bar: 'bar' });Enum.values(MyEnum) // ['foo', 'bar']
Module containing methods for working with enum types