Skip to main content

@cognizone/model-utils

Classes​

Interfaces​

Type aliases​

Completable​

Ƭ Completable<T>: Observable<T> | Promise<T> | T

The Completable type represents a resource that should "complete" in the Observable sense. A Completable is either directly the generic type given, a Promise that returns that type or an Observable that does the same.

Type parameters​

Name
T

Defined in​

lib/models/completable.ts:8


CzLabel​

Ƭ CzLabel: LangString | LangStringSimple | string

Union type that encompass all the usual types we use for labels

Defined in​

lib/models/cz-label.ts:6


Dictionary​

Ƭ Dictionary<T>: Object

A shorthand for indexed object with string as keys

Type parameters​

Name
T

Index signature​

â–ª [index: string]: T

Defined in​

lib/models/dictionary.ts:4


Many​

Ƭ Many<T>: T | T[]

A shorthand to specify if it's either the given type or an array of it

Type parameters​

Name
T

Defined in​

lib/models/many.ts:4


Nil​

Ƭ Nil<T>: T | null | undefined

Shorthand type for type being either itself, null or undefined

Type parameters​

Name
T

Defined in​

lib/models/nil.ts:4


SelectOptionLabel​

Ƭ SelectOptionLabel: LangString | LangStringSimple | string

The label of a SelectOption

Defined in​

lib/models/select-option.ts:34


Sorter​

Ƭ Sorter<T>: (a: T, b: T) => number

Type parameters​

Name
T

Type declaration​

â–¸ (a, b): number

Describes a function to be used as argument for Array<T>::sort

Parameters​
NameType
aT
bT
Returns​

number

Defined in​

lib/models/sorter.ts:4


UnknownObject​

Ƭ UnknownObject: Record<string | number | symbol, unknown>

To be used instead of {} or object as type for whe just want objects as type.

Defined in​

lib/models/unknown-object.ts:4

Functions​

awaitForCompletable​

â–¸ Const awaitForCompletable<T>(resource): Promise<T>

deprecated use completableToPromise instead

Type parameters​

Name
T

Parameters​

NameType
resourceCompletable<T>

Returns​

Promise<T>

Defined in​

lib/utils/completable-to-promise.ts:9


completableToObservable​

â–¸ completableToObservable<T>(resource): Observable<T>

Convert a Completable to an Observable

Type parameters​

Name
T

Parameters​

NameTypeDescription
resourceCompletable<T>The Completable to be transformed into an Observable.

Returns​

Observable<T>

resource as an Observable

Defined in​

lib/utils/completable-to-observable.ts:11


completableToPromise​

â–¸ completableToPromise<T>(resource): Promise<T>

Convert a Completable to a Promise

Type parameters​

Name
T

Parameters​

NameTypeDescription
resourceCompletable<T>The Completable to be transformed into a Promise. For ease of use, if it is an Observable, it is piped with first()

Returns​

Promise<T>

resource as a Promise

Defined in​

lib/utils/completable-to-promise.ts:18


createElasticQuery​

â–¸ createElasticQuery(): ElasticQuery

Create a basic structure for an ElasticQuery

deprecated

Returns​

ElasticQuery

Defined in​

lib/models/elastic-query.ts:53


czLabelToString​

â–¸ czLabelToString(label, lang, fallbackLangs?): string | undefined

Extract from a CzLabel the label in a corresponding lang. If not found, it will try to extract the label of one of the fallback languages. It is to be noted that even if the label is a string[] with multiple values, only the 0th element will be taken.

Parameters​

NameTypeDefault valueDescription
labelNil<CzLabel>undefined-
langstringundefinedThe preferred lang to get the label for
fallbackLangsstring[][]ordered list of fallback languages

Returns​

string | undefined

Defined in​

lib/utils/cz-label-to-string.ts:14


dateToDateString​

â–¸ dateToDateString(value): string

Returns the given Date as a string in the YYYY-MM-dd format

Parameters​

NameType
valueDate

Returns​

string

Defined in​

lib/utils/date-to-date-string.ts:4


debounceSync​

â–¸ debounceSync<T>(): MonoTypeOperatorFunction<T>

rxjs operator to be used for debouncing the source in a synchronous way

Type parameters​

Name
T

Returns​

MonoTypeOperatorFunction<T>

Defined in​

lib/operators/debounce-sync.ts:7


downloadBlob​

â–¸ downloadBlob(data, fileName?): void

Triggers a browser download of the given Blob, and should be cross-browser compatible (looking at you IE).

Parameters​

NameType
dataBlob
fileName?string

Returns​

void

Defined in​

lib/utils/download-blob.ts:5


extractOneSourceFromElasticResponse​

â–¸ extractOneSourceFromElasticResponse<T>(response): T

Extract the first _source of the first hits of an {@link ElasticResponse}

Type parameters​

Name
T

Parameters​

NameTypeDescription
responseElasticSearchResponse<T>The json returned by a _search elastic call

Returns​

T

Defined in​

lib/utils/extract-one-source-from-elastic-response.ts:9


extractSourcesFromElasticResponse​

â–¸ extractSourcesFromElasticResponse<T>(response): T[]

Aggregate all _source in all hits of an {@link ElasticResponse} in a single array

Type parameters​

Name
T

Parameters​

NameTypeDescription
responseElasticSearchResponse<T>The json returned by a _search elastic call

Returns​

T[]

Defined in​

lib/utils/extract-sources-from-elastic-response.ts:8


getAllProperties​

â–¸ getAllProperties(obj): string[]

get all properties of the given object, and goes up the prototype chain. This is mostly useful for debugging purposes and javascript digging.

Parameters​

NameType
objObject

Returns​

string[]

Defined in​

lib/utils/get-all-properties.ts:5


getAllSelectOptions​

â–¸ getAllSelectOptions<T>(options): SelectOption<T>[]

getAllSelectOptions spread options and sub options into one flat list of options @typedef SelectOption []

Type parameters​

Name
T

Parameters​

NameType
options(SelectOption<T> | SelectOptionGroup<T>)[]

Returns​

SelectOption<T>[]

Defined in​

lib/utils/get-all-select-options.ts:6


getLangStringValue​

â–¸ getLangStringValue(langString, lang, fallbackLangs?): string | undefined

Extract from a LangString the label in a corresponding lang. If not found, it will try to extract the label of one of the fallback languages. If even there nothing is found, it will fallback to the first label found. It is to be noted that even if the label is a string[] with multiple values, only the 0th element will be taken.

Parameters​

NameTypeDefault valueDescription
langStringNil<LangString | LangStringSimple>undefinedThe lang string from which we want to extract a label
langstringundefinedThe preferred lang to get the label for
fallbackLangsstring[][]ordered list of fallback languages

Returns​

string | undefined

Defined in​

lib/utils/get-lang-string-value.ts:15


groupSelectOptions​

â–¸ groupSelectOptions<T>(options): SelectOptionGroup<T>[]

Type parameters​

Name
T

Parameters​

NameType
options(SelectOption<T> | SelectOptionGroup<T>)[]

Returns​

SelectOptionGroup<T>[]

Defined in​

lib/utils/group-select-options.ts:4


isSelectOption​

â–¸ isSelectOption<T>(o): o is SelectOption<T>

Type parameters​

Name
T

Parameters​

NameType
oSelectOption<T> | SelectOptionGroup<T>

Returns​

o is SelectOption<T>

Defined in​

lib/utils/is-select-option.ts:3


manyToArray​

â–¸ manyToArray<T>(x): T[]

Convert a Many to an array. It gives an empty array if the given value is nullish.

Type parameters​

Name
T

Parameters​

NameType
xMany<T>

Returns​

T[]

Defined in​

lib/utils/many-to-array.ts:6


manyToOne​

â–¸ manyToOne<T>(x): T

Convert a Many to its base type, taking the 0th element of the array, if applicable.

Type parameters​

Name
T

Parameters​

NameType
xMany<T>

Returns​

T

Defined in​

lib/utils/many-to-one.ts:7


mapElasticSources​

â–¸ mapElasticSources<T, U>(response, project): ElasticSearchResponse<U>

Return a transformed {@link ElasticResponse} where all _source are transformed using the given project function

Type parameters​

Name
T
U

Parameters​

NameTypeDescription
responseElasticSearchResponse<T>The json returned by a _search elastic call
project(data: T) => UThe projection function

Returns​

ElasticSearchResponse<U>

Defined in​

lib/utils/map-elastic-sources.ts:9


notNil​

â–¸ notNil<T>(o): o is Exclude<T, undefined | null>

Checking that the argument is not Nil, so basically o != null. Its main usage is to be used in array filtering or rxjs stream filtering, like:

const myStringArray = ['a', undefined, null, 'b'].filter(notNil); // ['a', 'b']
from(['a', undefined, null, 'b']).pipe(filter(notNil)).subscribe(console.log); // logs: 'a' and 'b'

Type parameters​

Name
T

Parameters​

NameType
oT

Returns​

o is Exclude<T, undefined | null>

Defined in​

lib/utils/not-nil.ts:9


orElse​

â–¸ orElse<T, R>(value): OperatorFunction<T, R>

rxjs operator to be used for defaulting to a given value if the stream passes a nullish value. For example:

from(['a', undefined, 'c']).pipe(orElse('b')).subscribe(console.log) // logs 'a', 'b', 'c'.

Type parameters​

Name
T
R

Parameters​

NameType
valueR

Returns​

OperatorFunction<T, R>

Defined in​

lib/operators/or-else.ts:11


selectOptionMatchQuery​

â–¸ selectOptionMatchQuery<T>(option, query): boolean

This will (naively) check that on the labels of the given option matches the query.

Type parameters​

Name
T

Parameters​

NameType
optionSelectOption<T>
queryNil<string>

Returns​

boolean

Defined in​

lib/utils/select-option-match-query.ts:7


strictEntries​

â–¸ strictEntries<T>(o): [keyof T, T[keyof T]][]

Same as Object.entries, but strongly typed

Type parameters​

Name
T

Parameters​

NameType
oT

Returns​

[keyof T, T[keyof T]][]

Defined in​

lib/utils/strict-entries.ts:4


trackBySelectOption​

â–¸ trackBySelectOption<T>(index, option): T

a TrackByFn to be used with an *ngFor in case it is used on an array of SelectOption

Type parameters​

Name
T

Parameters​

NameType
indexnumber
optionSelectOption<T>

Returns​

T

Defined in​

lib/utils/track-by-select-option.ts:6