Options
All
  • Public
  • Public/Protected
  • All
Menu

tsjam

Index

Namespaces

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

Bit

Bit: 0 | 1

An integer data type that can take a value of 1, 0

BooleanLike

BooleanLike: "false" | "true" | "FALSE" | "TRUE" | "0" | "1" | Bit | boolean

Unifies all option input flags

Callback

Callback: (...args: readonly any[]) => void

Semantic Marker for the Callback function.

Type declaration

    • (...args: readonly any[]): void
    • Parameters

      • Rest ...args: readonly any[]

      Returns void

Comparator

Comparator<T>: (first: T, second: T) => ComparisonResult

Type parameters

  • T

Type declaration

CurrencyCode

CurrencyCode: typeof CurrencyCodes[number]

DisposeCallback

DisposeCallback: (...args: readonly any[]) => void

Callback function that should be invoked on Dispose.

Type declaration

    • (...args: readonly any[]): void
    • Parameters

      • Rest ...args: readonly any[]

      Returns void

Float

Float: number

Marker for Float numbers

IdFactory

IdFactory<TValue, TResult>: { create: MapFn<TValue | undefined, TResult>; unknown: TResult }

Type parameters

  • TValue

  • TResult

Type declaration

  • Readonly create: MapFn<TValue | undefined, TResult>
  • Readonly unknown: TResult

Integer

Integer: number

Marker for Integer numbers

Json

Json: number | string | null | boolean | Json[] | {}

LogEntry

LogEntry: { appId?: undefined | string; context?: LogContext; data?: readonly unknown[]; date: Date; level: LogLevel; message: string; stack?: undefined | string }

Type declaration

  • Optional Readonly appId?: undefined | string
  • Optional Readonly context?: LogContext
  • Optional Readonly data?: readonly unknown[]
  • Readonly date: Date
  • Readonly level: LogLevel
  • Readonly message: string
  • Optional Readonly stack?: undefined | string

LogMessage

LogMessage: { message: string; optionalParams: readonly any[] }

Type declaration

  • Readonly message: string
  • Readonly optionalParams: readonly any[]

LogOutputChannel

LogOutputChannel: { level?: LogLevel; out: LogOutput }

Sets the logLevel for your particular output channel.

Type declaration

LogTag

LogTag: string

String label for quick search across logs. Note: '#' would be added automatically

LogTranslator

LogTranslator<U>: { map: PipeFn<LogMessage, U> }

Log Message mapping layer, common use-case is sensitive data sanitization

Type parameters

  • U = unknown

Type declaration

LoggerOptions

LoggerOptions: { appId?: undefined | string; channels?: readonly LogOutputChannel[]; tags?: readonly LogTag[]; translator?: LogTranslator }

Type declaration

  • Optional Readonly appId?: undefined | string

    Application Id - to distinguish loggers of multiple instances of your Apps or services

  • Optional Readonly channels?: readonly LogOutputChannel[]

    Stream your log simultaneously into multiple output channels

  • Optional Readonly tags?: readonly LogTag[]

    Tag your logger, so it would be easily to filter logs

  • Optional Readonly translator?: LogTranslator

    Implement your custom transformation of your log data before write, e.g sanitize

MapFn

MapFn<T, U>: (info: T) => U

Literally – its not nullable ParseFn

Type parameters

  • T

  • U

Type declaration

    • (info: T): U
    • Parameters

      • info: T

      Returns U

MessageOf

MessageOf<T>: T["message"]

Helper type to retrieve message content from any type

Type parameters

  • T: { message: unknown }

MessagingProvider

MessagingProvider<InboundT, OutboundT>: { message$: Observable<InboundT>; send: any }

Type parameters

  • InboundT

  • OutboundT

Type declaration

  • Readonly message$: Observable<InboundT>
  • send: function
    • send(message: OutboundT): void
    • send<ResponseT>(message: OutboundT, responseMatcher: Typeguard<ResponseT, InboundT>): Observable<ResponseT>
    • Send one way Notification.

      Parameters

      • message: OutboundT

        notification message

      Returns void

    • Send Request, pick corresponding Response.

      Type parameters

      • ResponseT: InboundT

      Parameters

      • message: OutboundT

        outbound notification / request

      • responseMatcher: Typeguard<ResponseT, InboundT>

        picks the corresponding response

      Returns Observable<ResponseT>

      last response that replays for later subscriptions

Milliseconds

Milliseconds: number

It's good practice to use Milliseconds as time unit

NumericEnum

NumericEnum: {}

Type declaration

  • [id: number]: string

OneOrMany

OneOrMany<T>: T | readonly T[]

Type parameters

  • T

Opaque

Opaque<K, T>: T & { __TYPE__: K }

Type parameters

  • K: string

  • T

ParseFn

ParseFn<T, U>: (data: T) => U | undefined

Helper for data parsing modifiers

Type parameters

  • T

  • U

Type declaration

    • (data: T): U | undefined
    • Parameters

      • data: T

      Returns U | undefined

PipeFn

PipeFn<T, U>: (data: T, info?: U) => T

Helper for pipeline like modifiers

Type parameters

  • T

  • U

Type declaration

    • (data: T, info?: U): T
    • Parameters

      • data: T
      • Optional info: U

      Returns T

RPCFn

RPCFn<ResponseT, RequestT>: (request: RequestT) => Observable<ResponseT>

Type parameters

  • ResponseT

  • RequestT

Type declaration

    • (request: RequestT): Observable<ResponseT>
    • Parameters

      • request: RequestT

      Returns Observable<ResponseT>

RipId

RipId: Opaque<"RipId", number>

Rest in Peace Process Identifier. Identifier number used to kill the entity when necessary.

Seconds

Seconds: number

1000 Milliseconds

SomeObject

SomeObject: Record<string, unknown>

Useful Type for prop access via []

see

suggestion: treat in operator as type guard which asserts property existence #21732 https://github.com/microsoft/TypeScript/issues/21732

StringCaseInsensitive

StringCaseInsensitive: string

Marker for Case Insensitive strings

StringCaseSensitive

StringCaseSensitive: string

Marker for Case Sensitive strings

StringEnum

StringEnum: Record<string, string>

Approximate Type for String Enums

see

suggestion: allow "T extends enum" generic constraint #30611 https://github.com/microsoft/TypeScript/issues/30611

Typeguard

Typeguard<T, RawT>: (obj: RawT) => obj is T

Typeguard for narrowing raw types for compilation-type checks

Type parameters

  • T: RawT

  • RawT = unknown

Type declaration

    • (obj: RawT): obj is T
    • Parameters

      • obj: RawT

      Returns obj is T

UnixTimestamp

UnixTimestamp: number

It's good practice to use Milliseconds as time unit

UnsubscribeCallback

UnsubscribeCallback: DisposeCallback

Variables

Const CurrencyCodes

CurrencyCodes: ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "CRC", "HRK", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XAF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "LRD", "LYD", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "XUA", "MXN", "MXV", "MDL", "MNT", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "WST", "STN", "SAR", "RSD", "SCR", "SLL", "SGD", "XSU", "SBD", "SOS", "ZAR", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHF", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "XOF", "NZD", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "GBP", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VND", "XPF", "MAD", "YER", "ZMW", "ZWL"] = <const>['AFN','ALL','DZD','USD','EUR','AOA','ARS','AMD','AWG','AUD','AZN','BSD','BHD','BDT','BBD','BYN','BZD','BMD','BTN','INR','BOB','BOV','BAM','BWP','NOK','BRL','BND','BGN','BIF','CVE','KHR','CAD','KYD','CLF','CLP','CNY','COP','COU','KMF','CDF','CRC','HRK','CUC','CUP','ANG','CZK','DKK','DJF','DOP','EGP','SVC','ERN','ETB','FKP','FJD','XAF','GMD','GEL','GHS','GIP','GTQ','GNF','GYD','HTG','HNL','HKD','HUF','ISK','IDR','XDR','IRR','IQD','ILS','JMD','JPY','JOD','KZT','KES','KPW','KRW','KWD','KGS','LAK','LBP','LSL','LRD','LYD','MOP','MGA','MWK','MYR','MVR','MRU','XUA','MXN','MXV','MDL','MNT','MZN','MMK','NAD','NPR','NIO','NGN','OMR','PKR','PAB','PGK','PYG','PEN','PHP','PLN','QAR','MKD','RON','RUB','RWF','WST','STN','SAR','RSD','SCR','SLL','SGD','XSU','SBD','SOS','ZAR','SSP','LKR','SDG','SRD','SZL','SEK','CHE','CHF','CHW','SYP','TWD','TJS','TZS','THB','XOF','NZD','TOP','TTD','TND','TRY','TMT','UGX','UAH','AED','GBP','USN','UYI','UYU','UZS','VUV','VEF','VND','XPF','MAD','YER','ZMW','ZWL']

ALL ISO Currency Codes.

see

https://www.iban.com/currency-codes

Const __DEVELOPMENT__

__DEVELOPMENT__: boolean

Const commonSensitiveFields

commonSensitiveFields: string[] = ['password', 'token', 'secret', 'sessionId']

Const jamBlank

jamBlank: "-" = blank.dash

Ready-made blank '-' make all your empty fields look consistent.

example:

{`username: ${user.name ?? jamBlank}`}

{`password: ${blank.mask(user.password)}`}

Const jamLogger

jamLogger: Logger = createLogger()

Ready made - Application Logger with:

  • Console Output (same api)
  • stacks for Error log Level
  • auto-generated appId
  • tags support
  • fields sanitization by demand. (e.g. jamLogger.info({ sanitize: ['sessionId'] }, 'Wow', someData))

log example: [app1611253982848][2021-01-21T18:33:02.981Z][debug][#client] Logged In, { username: Bob, password: '***' }

Const noValue

noValue: undefined = void 0

void 0 is effectively a compile time bulletproof constant for undefined with no look-up requirements. difference is that some browsers allow to overwrite undefined, yet not void 0

example:

readonly notification$: Observable; ... notification$ = source$.pipe( mapTo(noValue) );

Const nonenumerable

nonenumerable: (Anonymous function) = enumerable(false)

ownProperty

ownProperty: ownProperty

Const semver

semver: RegExp = /^$|^([v=~^><*]?(\d+[a-z-]*\.?)+)|(\*)/

Functions

JSONParseAsync

  • JSONParseAsync(data: string): Promise<Json>

JSONParseSafely

  • JSONParseSafely(data: string, logCb?: undefined | ((err: any) => void)): Json | undefined
  • Parameters

    • data: string
    • Optional logCb: undefined | ((err: any) => void)

    Returns Json | undefined

Const bakeFactoryOfType

  • bakeFactoryOfType<TValue>(): (Anonymous function)

Const bakeLogWithLevel

comparePrimitives

compareStrings

compareVersions

  • compareVersions(ver1: string, ver2: string, maxPrecision?: number): ComparisonResult

compareVersionsSemantically

  • compareVersionsSemantically(ver1: string, ver2: string, sem?: SemanticRange): boolean

Const connectablePublishReplay

  • connectablePublishReplay<T>(bufferSize: number): UnaryFunction<Observable<T>, ConnectableObservable<T>>
  • publishReplay operator that correctly returns ConnectableObservable

    Type parameters

    • T

    Parameters

    • bufferSize: number

    Returns UnaryFunction<Observable<T>, ConnectableObservable<T>>

Const contextLine

  • contextLine(context: LogContext | undefined): string

Const createLogger

  • createLogger(__namedParameters?: { appId: undefined | string; channels: undefined | ReadonlyArray<LogOutputChannel>; tags: undefined | ReadonlyArray<string>; translator: undefined | LogTranslator<unknown> }): Logger
  • Factory method for Main application Logger. Use jamLogger instance if you prefer out of box solution.

    see

    LoggerOptions to customize.

    Parameters

    • Default value __namedParameters: { appId: undefined | string; channels: undefined | ReadonlyArray<LogOutputChannel>; tags: undefined | ReadonlyArray<string>; translator: undefined | LogTranslator<unknown> } = {}
      • appId: undefined | string
      • channels: undefined | ReadonlyArray<LogOutputChannel>
      • tags: undefined | ReadonlyArray<string>
      • translator: undefined | LogTranslator<unknown>

    Returns Logger

Const createStack

  • createStack(numStackLines: number | undefined): string

enumerable

  • enumerable(flag: boolean): (Anonymous function)

fetchData

  • Fetch does not fire reject event when external resources was not found. So here is wrapper around it with handling not valid response

    Parameters

    Returns Promise<Response>

filterMessage$

  • filterMessage$<T, U>(source$: Observable<T>, parser: ParseFn<T, U>): Observable<U>

Const firstValueFrom

  • firstValueFrom<T>(stream: Observable<T>): Promise<T>

Const generateAppId

  • generateAppId(): string

isArrayLike

  • isArrayLike(item: unknown): item is any[]
  • Shorthand for Array.isArray(item).

    Parameters

    • item: unknown

    Returns item is any[]

isCallback

  • isCallback(x: unknown): x is Callback

Const isCurrencyCode

  • isCurrencyCode(isoCode: string): isoCode is CurrencyCode

Const isDisposable

  • isDisposable(x: unknown): x is DisposableLike

isEmpty

  • isEmpty<T>(collection: Iterable<T> | null | undefined): boolean
  • Checks Iterable like entities whether it's empty or not.

    isEmpty(null) => true isEmpty(undefined) => true isEmpty('') => true isEmpty([]) => true isEmpty('ABC') => false isEmpty('[A, B]') => false

    Type parameters

    • T

    Parameters

    • collection: Iterable<T> | null | undefined

    Returns boolean

Const isEquatable

  • isEquatable(x: unknown): x is Equatable

Const isHashable

  • isHashable(x: unknown): x is Hashable

isInteger

  • isInteger(x: unknown): x is Integer

isNumber

  • isNumber(x: unknown): x is number

isObject

  • isObject(item: unknown): item is SomeObject

isSomething

  • isSomething<T>(x: T | undefined | null): x is NonNullable<T>
  • Type guard (also great for rx filter operations), that restricts undefined or null values.

    Type parameters

    • T

    Parameters

    • x: T | undefined | null

    Returns x is NonNullable<T>

isString

  • isString(x: unknown): x is string

Const isUnsubscribable

  • isUnsubscribable(x: unknown): x is Unsubscribable

Const lastValueFrom

  • lastValueFrom<T>(stream: Observable<T>): Promise<T>

Const mapFilterNotUndefined

  • mapFilterNotUndefined<T, R>(mapFn: (value: T) => R | undefined): (Anonymous function)
  • map + filter operator - maps then filters out undefined values.

    Type parameters

    • T

    • R

    Parameters

    • mapFn: (value: T) => R | undefined
        • (value: T): R | undefined
        • Parameters

          • value: T

          Returns R | undefined

    Returns (Anonymous function)

Const noop

  • noop(): void

optionalMap

  • optionalMap<T, U>(optionalValue: T | undefined | null, mapper: (nonOpt: NonNullable<T>) => U): U | undefined
  • optionalMap<T, U>(optionalValue: T | undefined | null, mapper: (nonOpt: NonNullable<T>) => U, defaultValue: U): U
  • Applies map function to optionalValue if it contains value, otherwise returns undefined

    Type parameters

    • T

    • U

    Parameters

    • optionalValue: T | undefined | null
    • mapper: (nonOpt: NonNullable<T>) => U
        • (nonOpt: NonNullable<T>): U
        • Parameters

          • nonOpt: NonNullable<T>

          Returns U

    Returns U | undefined

  • Applies map function to optionalValue if it contains value, otherwise returns default

    Type parameters

    • T

    • U

    Parameters

    • optionalValue: T | undefined | null
    • mapper: (nonOpt: NonNullable<T>) => U
        • (nonOpt: NonNullable<T>): U
        • Parameters

          • nonOpt: NonNullable<T>

          Returns U

    • defaultValue: U

    Returns U

Const passThrough

  • passThrough<T>(value: T): T
  • Returns exactly same value - acts as null object patter for dynamic mappings

    Type parameters

    • T

    Parameters

    • value: T

    Returns T

primitiveToBoolean

  • Handles boolean like primitives. For objects use !!obj directly.

    Parameters

    • value: StringCaseInsensitive | number | boolean | null | undefined

      string (case-insensitive) | number | boolean | null | undefined

    Returns boolean

    Returns true for 1, '1', true, 'true' (case-insensitive) . Otherwise false.

Const replayLastMessage$

  • replayLastMessage$<ResponseT, SourceT>(source$: Observable<SourceT>, matcher: Typeguard<ResponseT, SourceT>): Observable<ResponseT>
  • Single last response value that replays for later subscriptions

    Type parameters

    • ResponseT: SourceT

    • SourceT

    Parameters

    • source$: Observable<SourceT>

      stream of incoming messages

    • matcher: Typeguard<ResponseT, SourceT>

      selector for the appropriate response

    Returns Observable<ResponseT>

Const sanitizeSemantic

  • sanitizeSemantic(ver: string): string

sanitizeSensitiveData

  • sanitizeSensitiveData<T>(data: T, deep?: boolean, sensitiveFields?: readonly string[]): T
  • Sanitizes sensitive Data. Supports primitives, objects and arrays.

    Type parameters

    • T

    Parameters

    • data: T
    • Default value deep: boolean = false
    • Default value sensitiveFields: readonly string[] = commonSensitiveFields

    Returns T

semanticRangeFromVersion

  • semanticRangeFromVersion(ver: string): SemanticRange | undefined

Const shareReplayRefCount

  • shareReplayRefCount<T>(bufferSize: number): MonoTypeOperatorFunction<T>
  • shareReplay operator with internal refCount. When the reference count drops to zero, the replay-able notifications are flushed if the subject has not completed.

    usage

    Useful to replay last message to subscriber e.g. refCountShareReplay(1). For example in the stream of some setting values you're interested only in the latest one.

    see

    https://github.com/ReactiveX/rxjs/pull/4059#issuecomment-416783538

    Type parameters

    • T

    Parameters

    • bufferSize: number

    Returns MonoTypeOperatorFunction<T>

Const stringNode

  • stringNode(value: string | undefined): string

stringToEnum

  • stringToEnum<T>(enumType: T, rawValue: string | undefined | null, ignoreCase?: boolean): T[keyof T] | undefined
  • Finds matching enum value or returns undefined instead.

    Useful for "transforming" incoming raw string values from outside world (e.g. URL params) to our internal enum (limited set of values). Safer than doing something naive like someValue as MyEnum.

    Type parameters

    Parameters

    • enumType: T
    • rawValue: string | undefined | null
    • Default value ignoreCase: boolean = true

    Returns T[keyof T] | undefined

stringToInteger

  • stringToInteger(value: string | null | undefined, defaultValue?: Integer): Integer
  • Parameters

    • value: string | null | undefined
    • Default value defaultValue: Integer = 0

    Returns Integer

    Returns integer from numeric string. Otherwise default value (0 by default).

Const stringifyError

  • stringifyError(error: Error, numStackLines: number | undefined): string

Const tagsLine

  • tagsLine(tags: readonly string[] | undefined): string

Const validateVersion

  • validateVersion(ver: string): void

windowMessage$

  • windowMessage$<T, U>(target: Window, parseFn: ParseFn<T, U>): Observable<U>

Const write

Object literals

Const emptyTranslator

emptyTranslator: object

map

Const jsonStringifyTranslator

jsonStringifyTranslator: object

Invokes JSON.stringify on log data arguments. Stringifies Errors fairly (not just {} as regular JSON.stringify(new Error('Boo')))

map

  • map(__namedParameters: { message: string; optionalParams: ReadonlyArray<any> }): { message: string; optionalParams: string[] }
  • Parameters

    • __namedParameters: { message: string; optionalParams: ReadonlyArray<any> }
      • message: string
      • optionalParams: ReadonlyArray<any>

    Returns { message: string; optionalParams: string[] }

    • message: string
    • optionalParams: string[]

Const sanitizeSensitiveTranslator

sanitizeSensitiveTranslator: object

Sanitizes all sensitive data that should not be exposed. For performance optimization – it's good to sanitize data ONLY in places when it's actually needed.

map

  • map(__namedParameters: { message: string; optionalParams: ReadonlyArray<any> }, sensitive?: undefined | ReadonlyArray<string>): LogMessage
  • Parameters

    • __namedParameters: { message: string; optionalParams: ReadonlyArray<any> }
      • message: string
      • optionalParams: ReadonlyArray<any>
    • Default value sensitive: undefined | ReadonlyArray<string> = commonSensitiveFields

    Returns LogMessage

Const stringifyErrorStackTranslator

stringifyErrorStackTranslator: object

Stringifies Error Stack.

map

  • map(__namedParameters: { message: string; optionalParams: ReadonlyArray<any> }, trimStack: undefined | number): LogMessage
  • Parameters

    • __namedParameters: { message: string; optionalParams: ReadonlyArray<any> }
      • message: string
      • optionalParams: ReadonlyArray<any>
    • trimStack: undefined | number

    Returns LogMessage

Generated using TypeDoc