Skip to main content

Char

A collection of functions to manipulate characters

Index

Bound

readonlymaxValue

maxValue: Char

Maximum value for this type

@example
const anyNumber: number
anyNumber < Number.maxValue // true

readonlyminValue

minValue: Char

Minimum value for this type

@example
const anyNumber: number
anyNumber > Number.minValue // true

Codec

codecDecode

  • 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);

codecEncode

  • codecEncode(this: void, input: Char): 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);

codecSchema

  • Returns the JSONSchema corresponding to the decoded type

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

Comparator

!=

  • !=(this: void, left: Char, right: Char): boolean
  • "Not equal to" operator

    @example
    const TEqual: Equal<T>;
    TEqual['!='](value, otherValue); // true
    TEqual['!='](value, value); // false

  • (this: void, left: Char, right: Char): boolean
  • "Less than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<'](smallerT, smallerT); // false
    TCompare['<'](smallerT, greaterT); // true
    TCompare['<'](greaterT, smallerT); // false

<=

  • <=(this: void, left: Char, right: Char): boolean
  • "Less than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<='](smallerT, smallerT); // true
    TCompare['<='](smallerT, greaterT); // true
    TCompare['<='](greaterT, smallerT); // false

==

  • ==(this: void, left: Char, right: Char): boolean
  • "Equal to" operator

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual['=='](value, value); // true
    TEqual['=='](value, otherValue); // false

  • (this: void, left: Char, right: Char): boolean
  • "Greater than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>'](smallerT, smallerT); // false
    TCompare['>'](smallerT, greaterT); // false
    TCompare['>'](greaterT, smallerT); // true

>=

  • >=(this: void, left: Char, right: Char): boolean
  • "Greater than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>='](smallerT, smallerT); // true
    TCompare['>='](smallerT, greaterT); // false
    TCompare['>='](greaterT, smallerT); // true

clamp

  • clamp(this: void, value: Char, minValue: Char, maxValue: Char): Char
  • Clamp value between minValue and maxValue

    @example
    type T;
    const TCompare: Comparable<T>;
    TCompare.clamp(value, min, max); // min if value < min, max if value > max, otherwise value itself

compare

  • compare(this: void, left: Char, right: Char): number
  • Return a number that represents comparison

    @example
    type T;
    const TCompare: Comparable<T>;
    const sorted = [3, 1, 1].sort(TCompare.compare);

equals

  • equals(this: void, left: Char, right: Char): boolean
  • Alias to '=='

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual.equals(value, value); // true
    TEqual.equals(value, otherValue); // false

max

  • max(this: void, left: Char, right: Char): Char
  • "maximum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.max(smallerT, greaterT); // greaterT

min

  • min(this: void, left: Char, right: Char): Char
  • "minimum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.min(smallerT, greaterT); // smallerT

Constructor

asInstance

  • asInstance(anyValue: unknown): Option<Char>
  • 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

fromCodePoint

  • fromCodePoint(...code: number[]): Char
  • Returns a Char created by using the specified code point.

    @example
    Char.fromCodePoint(65, 9731) == "A☃"

Type

inspect

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

When defined, returns a custom string representation

@example

@param

hasInstance

  • hasInstance(anyValue: unknown): anyValue is Char
  • 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

typeName

Re-exports typeName

indexType

indexType: number

Index type

__call__

  • __call__(value: string): Char

at

  • at(index: number): Option<string>
  • Returns the value at the index

indexOf

  • indexOf(value: string): Option<number>
  • Returns the integer index of a value

range

  • range(start: string, end: string): Range<string>
  • Returns an Iterable starting from start to end. If start or end is not in range then returns an empty iterable.

rangeSize

  • rangeSize(start: string, end: string): number
  • Returns the size of a range. If start or end is not in range then returns 0.

unwrap

  • unwrap(value: Char): string
  • Convert a tagged value to the underlying type

wrap

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