Ordering
Index
Codec
__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);
__encode__
Returns the encoded
inputinterface SomeObject {foo: string}const someCodec: Codec<SomeObject> = ...;const someObject: SomeObject = { foo: "bar" }const encoded = Codec.decode(someCodec, someObject);
__schema__
Returns the JSONSchema corresponding to the decoded type
const someCodec: Codec<unknown> = ...;const jsonSchema = Codec.schema(someCodec);
Formatting
asString
Converts the given value to a String.
Number.asString(123); // '123'
Indexable
indexType
Index type
at
Returns the value at the index
indexOf
Returns the integer index of a value
range
Returns an Iterable starting from
starttoend. Ifstartorendis not in range then returns an empty iterable.
rangeSize
Returns the size of a range. If
startorendis not in range then returns 0.
Type
__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 }'
typeName
Type string representation
StringType.typeName // 'String'
Int.typeName // 'Int'
Person.typeName // 'Person'
asInstance
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
hasInstance
Return
trueif the given value is an instance of the class.const StringType: Type<string>;StringType.hasInstance('foo'); // trueStringType.hasInstance(42); // false
Other
readonly__enumKeys__
An array of all keys
Equal
An ordering where a compared value is equal to another.
Greater
An ordering where a compared value is greater than another.
Less
An ordering where a compared value is less than another.
reverse
Reverses the
Ordering.LessbecomesGreater.GreaterbecomesLess.EqualbecomesEqual.
reverse(Ordering.Less); // == Ordering.Greaterreverse(Ordering.Greater); // == Ordering.Lessreverse(Ordering.Equal); // == Ordering.Equal
A collection of functions to manipulate ordering values