Options
All
  • Public
  • Public/Protected
  • All
Menu

Module index

core/prelude

This module provides extensions for a bunch of builtin objects, such as String, Number, etc. The module is uploaded to the runtime automatically, you don't need to require it.

Index

Type aliases

AddSelf<M, S>: M extends (...args: infer A) => infer R ? (self: S, ...args: A) => R : never

Returns a new function based on the specified with adding as the first parameter the passed object

example
// (self: bFoo, a: number) => string
AddSelf<(a: number) => string, bFoo>

Type parameters

  • M: Function

  • S: object

AnyIterable<T>: Iterable<T> | AsyncIterable<T>

Type parameters

  • T = unknown

AnyToBoolean: any
AnyToIgnore: any
CanArray<T>: T | T[]

Type parameters

  • T

CanPromise<T>: T | Promise<T>

Type parameters

  • T

CanPromiseLike<T>: T | PromiseLike<T>

Type parameters

  • T

CanUndef<T>: T | undefined

Type parameters

  • T

CanVoid<T>: T | void

Type parameters

  • T

ClassConstructor<ARGS, R>: new (...args: ARGS) => R

Type parameters

  • ARGS: any[] = any[]

  • R = any

Type declaration

    • new (...args: ARGS): R
    • Parameters

      • Rest ...args: ARGS

      Returns R

DateCreateValue: number | string | Date
DateRelativeType: "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years"
DictionaryType<T>: T extends Dictionary<infer V> ? NonNullable<V> : T

Type parameters

I18nParams: { count?: number | StringPluralizationForms } & {}

Parameters for the internationalization function

IterableType<T>: T extends Iterable<infer V> ? V : T extends AsyncIterable<infer V> ? V : T

Type parameters

  • T: Iterable<any> | AsyncIterable<any>

JSONLikeValue: string | number | boolean | null | JSONLikeValue[] | Dictionary<JSONLikeValue>
Language: "be" | "en" | "kk" | "ru" | "tr" | "tt" | "uk" | "id" | "uz" | "es" | "de" | "hy" | "ka" | "ky" | "sr" | "fr" | "lv" | "lt" | "ro" | "fi" | "az" | "zh" | "he" | "et" | "no" | "sv" | "pt" | "ar" | "sw"
NewPromise<K, V>: K extends Maybe ? Maybe<V> : K extends Either ? Either<V> : Promise<V>

Type parameters

  • K

  • V

Nullable<T>: T | null | undefined

Type parameters

  • T

NumberOption: "decimal" | "thousands"
ObjectPropertyPath: string | any[]
Overwrite<T, U>: Pick<T, Exclude<keyof T, keyof U>> & U

Overrides properties of the specified type or interface. Don't use this helper if you simply extend one type from another, i.e. without overriding properties.

example
type A = {
x: number;
y: number;
};

// {x:number; y: string}
type B = Overwrite<A, {y: string}>;

Type parameters

  • T

    original type

  • U

    type with the overridden properties

Primitive: string | symbol | number | bigint | boolean | undefined | null
PromiseType<T>: T extends Maybe<infer V> ? NonNullable<V> : T extends Promise<infer V> ? V : T

Type parameters

  • T

RegExpFlag: "" | "g" | "i" | "m" | "u" | "y" | "s"
ReturnPromise<T>: (...args: Parameters<T>) => Promise<ReturnType<T>>

Type parameters

Type declaration

    • (...args: Parameters<T>): Promise<ReturnType<T>>
    • Wraps the specified function to return a value as Promise

      example
      type A = typeof () => null;

      // () => Promise<null>
      type B = ReturnPromise<A>;

      Parameters

      • Rest ...args: Parameters<T>

      Returns Promise<ReturnType<T>>

StringPluralizationForms: "one" | "some" | "many" | "none"

String pluralization constants that can be used instead of numbers

Trait<C, I>: { [ K in Extract<keyof C, keyof I>]: I[K] }

Returns a new non-abstract class from the specified abstract class where methods can have the default implementation. The default implementations are taken from the static methods that match by names with the class's methods.

example
abstract class iFoo {
static bar(self: object): string {
return self.bla.toString();
}

bar(): string {
return Object.throw();
}

abstract bar(): number;
}

// class { bar(): string; }
Trait<typeof bFoo>

Type parameters

  • C: Function

  • I: C["prototype"] = C["prototype"]

Writable<T>: { -readonly [ K in keyof T]: T[K] }

Creates an interface based on the specified type or interface but every property can be edited

Type parameters

  • T

Variables

API_URL: CanUndef<string>
APP_NAME: string
DEBUG: boolean
IS_PROD: boolean
LOCALE: Language

Functions

  • Any(obj: any): any
  • Any(obj: any): any
  • Converts the specified unknown value to any

    Parameters

    • obj: any

    Returns any

  • Converts the specified unknown value to any

    Parameters

    • obj: any

    Returns any

  • i18n(keysetNameOrNames: CanArray<string>, customLocale?: Language): (key: string | TemplateStringsArray, params?: I18nParams) => string
  • i18n(strings: any, ...expr: any[]): string
  • Creates a function to internationalize strings in an application based on the given locale and keyset. Keyset allows you to share the same keys in different contexts. For example, the key "Next" may have a different value in different components of the application, therefore, we can use the name of the component as a keyset value.

    Parameters

    • keysetNameOrNames: CanArray<string>

      the name of keyset or array with names of keysets to use. If passed as an array, the priority of the cases will be arranged in the order of the elements, the first one will have the highest priority.

    • Optional customLocale: Language

    Returns (key: string | TemplateStringsArray, params?: I18nParams) => string

      • (key: string | TemplateStringsArray, params?: I18nParams): string
      • Creates a function to internationalize strings in an application based on the given locale and keyset. Keyset allows you to share the same keys in different contexts. For example, the key "Next" may have a different value in different components of the application, therefore, we can use the name of the component as a keyset value.

        Parameters

        • key: string | TemplateStringsArray
        • Optional params: I18nParams

        Returns string

  • Global i18n function (can be used as a string tag or simple function)

    Parameters

    • strings: any
    • Rest ...expr: any[]

    Returns string

  • stderr(err: any): void
  • stderr(err: any): void
  • STDERR wrapper

    Parameters

    • err: any

    Returns void

  • STDERR wrapper

    Parameters

    • err: any

    Returns void

  • structuredClone<T>(obj: T): T