Boolean
Index
Codec
Comparator
Formatting
Type
Other
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);
Comparator
!=
"Not equal to" operator
const TEqual: Equal<T>;TEqual['!='](value, otherValue); // trueTEqual['!='](value, value); // false
<
"Less than" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['<'](smallerT, smallerT); // falseTCompare['<'](smallerT, greaterT); // trueTCompare['<'](greaterT, smallerT); // false
<=
"Less than or equal to" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['<='](smallerT, smallerT); // trueTCompare['<='](smallerT, greaterT); // trueTCompare['<='](greaterT, smallerT); // false
==
"Equal to" operator
type T = // ...const TEqual: Equal<T>;TEqual['=='](value, value); // trueTEqual['=='](value, otherValue); // false
>
"Greater than" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['>'](smallerT, smallerT); // falseTCompare['>'](smallerT, greaterT); // falseTCompare['>'](greaterT, smallerT); // true
>=
"Greater than or equal to" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['>='](smallerT, smallerT); // trueTCompare['>='](smallerT, greaterT); // falseTCompare['>='](greaterT, smallerT); // true
clamp
Clamp value between minValue and maxValue
type T;const TCompare: Comparable<T>;TCompare.clamp(value, min, max); // min if value < min, max if value > max, otherwise value itself
compare
equals
Alias to '=='
type T = // ...const TEqual: Equal<T>;TEqual.equals(value, value); // trueTEqual.equals(value, otherValue); // false
max
"maximum" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare.max(smallerT, greaterT); // greaterT
min
"minimum" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare.min(smallerT, greaterT); // smallerT
Formatting
asString
Converts the given value to a String.
Number.asString(123); // '123'
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
not
Performs the equivalent of the
!operation.type Answer = 'yes' | 'no';const Answer: Not<Answer> = {not(self) => self === 'yes' ? 'no' : 'yes',};Answer.not('yes') // 'no'Answer.not('no') // 'yes'
A collection of functions to manipulate
boolean