@serenity-is/corelib

@serenity-is/corelib

Serenity Core Library

This is the package containing core TypeScript classes and functions used in Serenity applications.

It should be installed by default in your projects created from Serene or StartSharp template:

{
  "dependencies": {
    // ...
    "@serenity-is/corelib": "6.9.0"
  }
}

The version number for this package should be equal or as close as possible to Serenity NuGet package versions in your project file.

When using classic namespaces instead of the ESM modules, the types and functions in this module are directly available from the global Serenity and Q namespaces. e.g. Serenity.EntityGrid

Table of contents

Namespaces

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

AnyWidgetClass

Ƭ AnyWidgetClass<TOptions>: WidgetClass<TOptions> | WidgetDialogClass<TOptions>

Type parameters

Name Type
TOptions object

Defined in

src/ui/widgets/widget.ts:17


CancellableViewCallback

Ƭ CancellableViewCallback<TEntity>: (view: RemoteView<TEntity>) => boolean | void

Type parameters

Name
TEntity

Type declaration

▸ (view): boolean | void

Parameters
Name Type
view RemoteView<TEntity>
Returns

boolean | void

Defined in

src/slick/remoteview.ts:37


Constructor

Ƭ Constructor<T>: (...args: any[]) => T

Type parameters

Name
T

Type declaration

• (...args)

Parameters
Name Type
...args any[]

Defined in

src/index.ts:109


Dictionary

Ƭ Dictionary<TItem>: Object

Type parameters

Name
TItem

Index signature

▪ [key: string]: TItem

Defined in

src/q/system.ts:1


Format

Ƭ Format<TItem>: (ctx: FormatterContext<TItem>) => string

Type parameters

Name Type
TItem any

Type declaration

▸ (ctx): string

Parameters
Name Type
ctx FormatterContext<TItem>
Returns

string

Defined in

src/slick/slicktypes.ts:4


GroupByElement

Ƭ GroupByElement<TItem>: Object

A group item returned by groupBy().

Type parameters

Name
TItem

Type declaration

Name Type Description
items TItem[] the items in the group
key string key of the group
order number index of the item in inOrder array
start number index of the first item of this group in the original array

Defined in

src/q/arrays.ts:43


GroupByResult

Ƭ GroupByResult<TItem>: Object

Return type of the groupBy function.

Type parameters

Name
TItem

Type declaration

Name Type
byKey { [key: string]: GroupByElement<TItem>; }
inOrder GroupByElement<TItem>[]

Defined in

src/q/arrays.ts:57


Grouping

Ƭ Grouping<TItem>: Object

Type parameters

Name
TItem

Index signature

▪ [key: string]: TItem[]

Defined in

src/q/arrays.ts:169


NotifyMap

Ƭ NotifyMap: Object

Type declaration

Name Type
iconClass string
message? string
title? string
type string

Defined in

src/q/toastr2.ts:40


RemoteViewAjaxCallback

Ƭ RemoteViewAjaxCallback<TEntity>: (view: RemoteView<TEntity>, options: JQueryAjaxSettings) => boolean | void

Type parameters

Name
TEntity

Type declaration

▸ (view, options): boolean | void

Parameters
Name Type
view RemoteView<TEntity>
options JQueryAjaxSettings
Returns

boolean | void

Defined in

src/slick/remoteview.ts:38


RemoteViewFilter

Ƭ RemoteViewFilter<TEntity>: (item: TEntity, view: RemoteView<TEntity>) => boolean

Type parameters

Name
TEntity

Type declaration

▸ (item, view): boolean

Parameters
Name Type
item TEntity
view RemoteView<TEntity>
Returns

boolean

Defined in

src/slick/remoteview.ts:39


RemoteViewProcessCallback

Ƭ RemoteViewProcessCallback<TEntity>: (data: ListResponse<TEntity>, view: RemoteView<TEntity>) => ListResponse<TEntity>

Type parameters

Name
TEntity

Type declaration

▸ (data, view): ListResponse<TEntity>

Parameters
Name Type
data ListResponse<TEntity>
view RemoteView<TEntity>
Returns

ListResponse<TEntity>

Defined in

src/slick/remoteview.ts:40


ToastContainerOptions

Ƭ ToastContainerOptions: Object

Type declaration

Name Type
containerId? string
positionClass? string
target? string

Defined in

src/q/toastr2.ts:5


ToastrOptions

Ƭ ToastrOptions: ToastContainerOptions & { closeButton?: boolean ; closeClass?: string ; closeDuration?: number | false ; closeEasing?: boolean ; closeHtml?: string ; closeMethod?: boolean ; closeOnHover?: boolean ; escapeHtml?: boolean ; extendedTimeOut?: number ; hideDuration?: number ; iconClass?: string ; messageClass?: string ; newestOnTop?: boolean ; onCloseClick?: (event: Event) => void ; onHidden?: () => void ; onShown?: () => void ; onclick?: (event: MouseEvent) => void ; positionClass?: string ; preventDuplicates?: boolean ; rtl?: boolean ; showDuration?: number ; tapToDismiss?: boolean ; target?: string ; timeOut?: number ; titleClass?: string ; toastClass?: string }

Defined in

src/q/toastr2.ts:11


Type

Ƭ Type: Function | Object

Defined in

src/q/system.ts:84

Variables

Config

Config: Object

Type declaration

Name Type Description
applicationPath string This is the root path of your application. If your application resides under http://localhost/mysite/, your root path is "mysite/". This variable is automatically initialized by reading from a element with ID "ApplicationPath" from current page, which is usually located in your _LayoutHead.cshtml file
bootstrapMessages boolean Set this to true, to prefer bootstrap dialogs over jQuery UI dialogs by default for message dialogs
emailAllowOnlyAscii boolean Email validation by default only allows ASCII characters. Set this to true if you want to allow unicode.
notLoggedInHandler Function This is an optional method for handling when user is not logged in. If a users session is expired and when a NotAuthorized response is received from a service call, Serenity will call this handler, so you may intercept it and notify user about this situation and ask if she wants to login again...
responsiveDialogs boolean Obsolete defaulted to false before for backward compatibility, now it is true by default
rootNamespaces string[] This is the list of root namespaces that may be searched for types. For example, if you specify an editor type of "MyEditor", first a class with name "MyEditor" will be searched, if not found, search will be followed by "Serenity.MyEditor" and "MyApp.MyEditor" if you added "MyApp" to the list of root namespaces. You should usually add your application root namespace to this list in ScriptInit(ialization).ts file.

Defined in

src/q/config.ts:1


Culture

Culture: Locale

Current culture, e.g. CultureInfo.CurrentCulture. This is overridden by settings passed from a <script> element in the page with id ScriptCulture containing a JSON object if available. This element is generally created in the _LayoutHead.cshtml file for Serenity applications, so that the culture settings determined server, can be passed to the client.

Defined in

src/q/formatting.ts:132


Invariant

Invariant: Locale

Invariant locale (e.g. CultureInfo.InvariantCulture)

Defined in

src/q/formatting.ts:64


datePickerIconSvg

datePickerIconSvg: string = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 17 17"><g></g><path d="M14 2v-1h-3v1h-5v-1h-3v1h-3v15h17v-15h-3zM12 2h1v2h-1v-2zM4 2h1v2h-1v-2zM16 16h-15v-8.921h15v8.921zM1 6.079v-3.079h2v2h3v-2h5v2h3v-2h2v3.079h-15z" fill="currentColor"></path></svg>'

Defined in

src/ui/editors/dateeditor.ts:6


defaultNotifyOptions

defaultNotifyOptions: ToastrOptions

Defined in

src/q/notify.ts:10

Functions

Criteria

Criteria(field): CriteriaBuilder

Creates a new criteria builder containg the passed field name.

Parameters

Name Type Description
field string The field name.

Returns

CriteriaBuilder

Defined in

src/q/criteria.ts:750


addAttribute

addAttribute(type, attr): void

Parameters

Name Type
type any
attr any

Returns

void

Defined in

src/q/system.ts:605


addEmptyOption

addEmptyOption(select): void

Adds an empty option to the select.

Parameters

Name Type Description
select JQuery | HTMLSelectElement the select element

Returns

void

Defined in

src/q/html.ts:8


addOption

addOption(select, key, text): void

Adds an option to the select.

Parameters

Name Type
select JQuery | HTMLSelectElement
key string
text string

Returns

void

Defined in

src/q/html.ts:15


addTypeMember

addTypeMember(type, member): TypeMember

Parameters

Name Type
type any
member TypeMember

Returns

TypeMember

Defined in

src/q/system.ts:279


addValidationRule

addValidationRule(element, eventClass, rule): JQuery

Parameters

Name Type
element JQuery
eventClass string
rule (p1: JQuery) => string

Returns

JQuery

Defined in

src/q/validation.ts:234


alert

alert(message, options?): void

Obsolete

use alertDialog

Parameters

Name Type
message string
options? AlertOptions

Returns

void

Defined in

src/q/dialogs.ts:328


alertDialog

alertDialog(message, options?): void

Displays an alert dialog

See

AlertOptions

Example

alertDialog("An error occured!"); }

Parameters

Name Type Description
message string The message to display
options? AlertOptions Additional options.

Returns

void

Defined in

src/q/dialogs.ts:328


any

any<TItem>(array, predicate): boolean

Tests if any of array elements matches given predicate. Prefer Array.some() over this function (e.g. [1, 2, 3].some(predicate)).

Type parameters

Name
TItem

Parameters

Name Type Description
array TItem[] Array to test.
predicate (x: TItem) => boolean Predicate to test elements.

Returns

boolean

True if any element matches.

Defined in

src/q/arrays.ts:7


attrEncode

attrEncode(s): string

Obsolete

use htmlEncode as it also encodes quotes

Parameters

Name Type
s any

Returns

string

Defined in

src/q/html.ts:100


baseValidateOptions

baseValidateOptions(): JQueryValidation.ValidationOptions

Returns

JQueryValidation.ValidationOptions

Defined in

src/q/validation.ts:157


blockUI

blockUI(options): void

Uses jQuery BlockUI plugin to block access to whole page (default) or a part of it, by using a transparent overlay covering the whole area.

Remarks

If options are not specified, this function blocks whole page with a transparent overlay. Default z-order of the overlay div is 2000, so a higher z-order shouldn't be used in page.

Parameters

Name Type Description
options JQBlockUIOptions Parameters for the BlockUI plugin

Returns

void

Defined in

src/q/blockui.ts:36


blockUndo

blockUndo(): void

Unblocks the page.

Returns

void

Defined in

src/q/blockui.ts:60


bsModalMarkup

bsModalMarkup(title, body, modalClass?, escapeHtml?): HTMLDivElement

Builds HTML DIV element for a Bootstrap modal dialog

Parameters

Name Type Default value Description
title string undefined Modal title
body string undefined Modal body, it will not be HTML encoded, so make sure it is encoded
modalClass? string undefined Optional class to add to the modal element
escapeHtml boolean true True to html encode body, default is true

Returns

HTMLDivElement

Defined in

src/q/dialogs.ts:147


canLoadScriptData

canLoadScriptData(name): boolean

Parameters

Name Type
name string

Returns

boolean

Defined in

src/q/scriptdata.ts:281


cast

cast(instance, type): any

Parameters

Name Type
instance any
type Type

Returns

any

Defined in

src/q/system.ts:195


centerDialog

centerDialog(el): void

Parameters

Name Type
el JQuery

Returns

void

Defined in

src/q/layout.ts:99


clearKeys

clearKeys(d): void

Parameters

Name Type
d any

Returns

void

Defined in

src/q/system.ts:335


clearOptions

clearOptions(select): void

Clears the options in the select element

Parameters

Name Type
select JQuery

Returns

void

Defined in

src/q/html.ts:23


closePanel

closePanel(element, e?): void

Closes a panel, triggering panelbeforeclose and panelclose events on the panel element. If the panelbeforeclose prevents the default, the operation is cancelled.

Parameters

Name Type Description
element HTMLElement | JQuery The panel element
e? Event The event triggering the close

Returns

void

Defined in

src/q/dialogs.ts:602


coalesce

coalesce(a, b): any

Parameters

Name Type
a any
b any

Returns

any

Defined in

src/q/system.ts:3


compareStringFactory

compareStringFactory(order): (a: string, b: string) => number

Factory for a function that compares two strings, based on a character order passed in the order argument.

Parameters

Name Type
order string

Returns

fn

▸ (a, b): number

Parameters
Name Type
a string
b string
Returns

number

Defined in

src/q/formatting.ts:92


confirm

confirm(message, onYes, options?): void

Obsolete

use confirmDialog

Parameters

Name Type
message string
onYes () => void
options? ConfirmOptions

Returns

void

Defined in

src/q/dialogs.ts:396


confirmDialog

confirmDialog(message, onYes, options?): void

Display a confirmation dialog

See

ConfirmOptions

Example

confirmDialog("Are you sure you want to delete?", () => { 
    // do something when yes is clicked
}

Parameters

Name Type Description
message string The message to display
onYes () => void Callback for Yes button click
options? ConfirmOptions Additional options.

Returns

void

Defined in

src/q/dialogs.ts:396


count

count<TItem>(array, predicate): number

Counts number of array elements that matches a given predicate.

Type parameters

Name
TItem

Parameters

Name Type Description
array TItem[] Array to test.
predicate (x: TItem) => boolean Predicate to test elements.

Returns

number

Defined in

src/q/arrays.ts:16


dbText

dbText(prefix): (key: string) => string

Parameters

Name Type
prefix string

Returns

fn

▸ (key): string

Parameters
Name Type
key string
Returns

string

Defined in

src/q/localtext.ts:15


dbTryText

dbTryText(prefix): (key: string) => string

Parameters

Name Type
prefix string

Returns

fn

▸ (key): string

Parameters
Name Type
key string
Returns

string

Defined in

src/q/localtext.ts:57


debounce

debounce<T>(func, wait?, immediate?): DebouncedFunction<T>

Returns a function, that, as long as it continues to be invoked, will not be triggered. The function also has a property 'clear' that can be used to clear the timer to prevent previously scheduled executions, and flush method to invoke scheduled executions now if any.

Source

underscore.js

Type parameters

Name Type
T extends (...args: any) => any

Parameters

Name Type Description
func T -
wait? number The function will be called after it stops being called for N milliseconds.
immediate? boolean If passed, trigger the function on the leading edge, instead of the trailing.

Returns

DebouncedFunction<T>

Defined in

src/q/debounce.ts:39


deepClone

deepClone<T>(a, a2?, a3?): T

Type parameters

Name Type
T any

Parameters

Name Type
a T
a2? any
a3? any

Returns

T

Defined in

src/q/system.ts:23


delegateCombine

delegateCombine(delegate1, delegate2): any

Parameters

Name Type
delegate1 any
delegate2 any

Returns

any

Defined in

src/q/system.ts:342


delegateRemove

delegateRemove(delegate1, delegate2): any

Parameters

Name Type
delegate1 any
delegate2 any

Returns

any

Defined in

src/q/system.ts:454


dialogButtonToBS

dialogButtonToBS(x): HTMLButtonElement

Converts a DialogButton declaration to Bootstrap button element

Parameters

Name Type Description
x DialogButton Dialog button declaration

Returns

HTMLButtonElement

Bootstrap button element

Defined in

src/q/dialogs.ts:172


dialogButtonToUI

dialogButtonToUI(x): any

Converts a DialogButton declaration to jQuery UI button type

Parameters

Name Type Description
x DialogButton Dialog button declaration

Returns

any

jQuery UI button type

Defined in

src/q/dialogs.ts:191


endsWith

endsWith(s, suffix): boolean

Checks if the string ends with the specified substring.

Parameters

Name Type Description
s string String to check.
suffix string Suffix to check.

Returns

boolean

True if the string ends with the specified substring.

Defined in

src/q/strings.ts:7


executeEverytimeWhenVisible

executeEverytimeWhenVisible(element, callback, callNowIfVisible): void

Parameters

Name Type
element JQuery
callback Function
callNowIfVisible boolean

Returns

void

Defined in

src/q/layouttimer.ts:154


executeOnceWhenVisible

executeOnceWhenVisible(element, callback): void

Parameters

Name Type
element JQuery
callback Function

Returns

void

Defined in

src/q/layouttimer.ts:138


extend

extend<T>(a, b): T

Type parameters

Name Type
T any

Parameters

Name Type
a T
b T

Returns

T

Defined in

src/q/system.ts:16


fieldsProxy

fieldsProxy<TRow>(): Readonly<Record<keyof TRow, string>>

Type parameters

Name
TRow

Returns

Readonly<Record<keyof TRow, string>>

Defined in

src/q/system.ts:538


findElementWithRelativeId

findElementWithRelativeId(element, relativeId, context?): JQuery

Finds the first element with the given relative id to the source element. It can handle underscores in the source element id.

Parameters

Name Type Description
element JQuery the source element
relativeId string the relative id to the source element
context? HTMLElement the context element (optional)

Returns

JQuery

the element with the given relative id to the source element.

Defined in

src/q/html.ts:35

findElementWithRelativeId(element, relativeId, context?): HTMLElement

Finds the first element with the given relative id to the source element. It can handle underscores in the source element id.

Parameters

Name Type Description
element HTMLElement the source element
relativeId string the relative id to the source element
context? HTMLElement the context element (optional)

Returns

HTMLElement

the element with the given relative id to the source element.

Defined in

src/q/html.ts:44


first

first<TItem>(array, predicate): TItem

Gets first element in an array that matches given predicate similar to LINQ's First. Throws an error if no match is found.

Type parameters

Name
TItem

Parameters

Name Type Description
array TItem[] Array to test.
predicate (x: TItem) => boolean Predicate to test elements.

Returns

TItem

First element that matches.

Defined in

src/q/arrays.ts:32


format

format(format, ...prm): string

Formats a string with parameters similar to .NET's String.Format function using current Culture locale settings.

Parameters

Name Type
format string
...prm any[]

Returns

string

Defined in

src/q/formatting.ts:265


formatDate

formatDate(d, format?, locale?): string

Formats a date using the specified format string and optional culture. Supports .NET style format strings including custom formats. See .NET documentation for supported formats.

Example

// returns "2019-01-01"
formatDate(new Date(2019, 0, 1), "yyyy-MM-dd");

Example

// returns "2019-01-01 12:00:00"
formatDate(new Date(2019, 0, 1, 12), "yyyy-MM-dd HH:mm:ss");

Example

// returns "2019-01-01 12:00:00.000"
formatDate(new Date(2019, 0, 1, 12), "yyyy-MM-dd HH:mm:ss.fff");

Example

// returns "2019-01-01 12:00:00.000 AM"
formatDate(new Date(2019, 0, 1, 12), "yyyy-MM-dd HH:mm:ss.fff tt");

Parameters

Name Type Description
d string | Date the date to format. If null, it returns empty string.
format? string the format string to use. If null, it uses the current culture's default format. 'G' uses the culture's datetime format. 'g' uses the culture's datetime format with secs removed. 'd' uses the culture's date format. 't' uses the culture's time format. 'u' uses the sortable ISO format with UTC time. 'U' uses the culture's date format with UTC time.
locale? Locale the locale to use

Returns

string

the formatted date

Defined in

src/q/formatting.ts:671


formatDayHourAndMin

formatDayHourAndMin(n): string

Formats a number containing number of minutes into a string in the format "d.hh:mm".

Parameters

Name Type Description
n number The number of minutes.

Returns

string

Defined in

src/q/formatting.ts:842


formatISODateTimeUTC

formatISODateTimeUTC(d): string

Formats a date as the ISO 8601 UTC date/time format.

Parameters

Name Type
d Date

Returns

string

Defined in

src/q/formatting.ts:865


formatNumber

formatNumber(num, format?, decOrLoc?, grp?): string

Formats a number using the current Culture locale (or the passed locale) settings. It supports format specifiers similar to .NET numeric formatting strings.

Parameters

Name Type Description
num number the number to format
format? string the format specifier. default is 'g'. See .NET numeric formatting strings documentation for more information.
decOrLoc? string | NumberFormat -
grp? string -

Returns

string

Defined in

src/q/formatting.ts:318


getAttributes

getAttributes(type, attrType, inherit?): any[]

Parameters

Name Type
type any
attrType any
inherit? boolean

Returns

any[]

Defined in

src/q/system.ts:228


getBaseType

getBaseType(type): any

Parameters

Name Type
type any

Returns

any

Defined in

src/q/system.ts:203


getColumns

getColumns(key): PropertyItem[]

Parameters

Name Type
key string

Returns

PropertyItem[]

Defined in

src/q/scriptdata.ts:241


getColumnsAsync

getColumnsAsync(key): Promise<PropertyItem[]>

Parameters

Name Type
key string

Returns

Promise<PropertyItem[]>

Defined in

src/q/scriptdata.ts:249


getColumnsData

getColumnsData(key): PropertyItemsData

Parameters

Name Type
key string

Returns

PropertyItemsData

Defined in

src/q/scriptdata.ts:245


getColumnsDataAsync

getColumnsDataAsync(key): Promise<PropertyItemsData>

Parameters

Name Type
key string

Returns

Promise<PropertyItemsData>

Defined in

src/q/scriptdata.ts:253


getCookie

getCookie(name): any

Parameters

Name Type
name string

Returns

any

Defined in

src/q/services.ts:8


getForm

getForm(key): PropertyItem[]

Parameters

Name Type
key string

Returns

PropertyItem[]

Defined in

src/q/scriptdata.ts:257


getFormAsync

getFormAsync(key): Promise<PropertyItem[]>

Parameters

Name Type
key string

Returns

Promise<PropertyItem[]>

Defined in

src/q/scriptdata.ts:265


getFormData

getFormData(key): PropertyItemsData

Parameters

Name Type
key string

Returns

PropertyItemsData

Defined in

src/q/scriptdata.ts:261


getFormDataAsync

getFormDataAsync(key): Promise<PropertyItemsData>

Parameters

Name Type
key string

Returns

Promise<PropertyItemsData>

Defined in

src/q/scriptdata.ts:269


getGlobalThis

getGlobalThis(): any

Returns

any

Defined in

src/q/system.ts:116


getHighlightTarget

getHighlightTarget(el): HTMLElement

Parameters

Name Type
el HTMLElement

Returns

HTMLElement

Defined in

src/q/validation.ts:149


getInstanceType

getInstanceType(instance): any

Parameters

Name Type
instance any

Returns

any

Defined in

src/q/system.ts:158


getLookup

getLookup<TItem>(key): Lookup<TItem>

Type parameters

Name
TItem

Parameters

Name Type
key string

Returns

Lookup<TItem>

Defined in

src/q/scriptdata.ts:225


getLookupAsync

getLookupAsync<TItem>(key): Promise<Lookup<TItem>>

Type parameters

Name
TItem

Parameters

Name Type
key string

Returns

Promise<Lookup<TItem>>

Defined in

src/q/scriptdata.ts:229


getMembers

getMembers(type, memberTypes): TypeMember[]

Parameters

Name Type
type any
memberTypes MemberType

Returns

TypeMember[]

Defined in

src/q/system.ts:262


getNested

getNested(from, name): any

Parameters

Name Type
from any
name string

Returns

any

Defined in

src/q/system.ts:98


getRemoteData

getRemoteData<TData>(key): TData

Type parameters

Name Type
TData any

Parameters

Name Type
key string

Returns

TData

Defined in

src/q/scriptdata.ts:217


getRemoteDataAsync

getRemoteDataAsync<TData>(key): Promise<TData>

Type parameters

Name Type
TData any

Parameters

Name Type
key string

Returns

Promise<TData>

Defined in

src/q/scriptdata.ts:221


getStateStore

getStateStore(key?): any

Parameters

Name Type
key? string

Returns

any

Defined in

src/q/system.ts:365


getTemplate

getTemplate(key): string

Parameters

Name Type
key string

Returns

string

Defined in

src/q/scriptdata.ts:273


getTemplateAsync

getTemplateAsync(key): Promise<string>

Parameters

Name Type
key string

Returns

Promise<string>

Defined in

src/q/scriptdata.ts:277


getType

getType(name, target?): Type

Parameters

Name Type
name string
target? any

Returns

Type

Defined in

src/q/system.ts:120


getTypeFullName

getTypeFullName(type): string

Parameters

Name Type
type Type

Returns

string

Defined in

src/q/system.ts:146


getTypeNameProp

getTypeNameProp(type): string

Parameters

Name Type
type Type

Returns

string

Defined in

src/q/system.ts:138


getTypeShortName

getTypeShortName(type): string

Parameters

Name Type
type Type

Returns

string

Defined in

src/q/system.ts:151


getTypes

getTypes(from?): any[]

Parameters

Name Type
from? any

Returns

any[]

Defined in

src/q/system.ts:310


groupBy

groupBy<TItem>(items, getKey): GroupByResult<TItem>

Groups an array with keys determined by specified getKey() callback. Resulting object contains group objects in order and a dictionary to access by key. This is similar to LINQ's ToLookup function with some additional details like start index.

Type parameters

Name
TItem

Parameters

Name Type Description
items TItem[] Array to group.
getKey (x: TItem) => any Function that returns key for each item.

Returns

GroupByResult<TItem>

GroupByResult object.

Defined in

src/q/arrays.ts:70


htmlEncode

htmlEncode(s): string

Html encodes a string (encodes single and double quotes, & (ampersand), > and < characters)

Parameters

Name Type Description
s any String (or number etc.) to be HTML encoded

Returns

string

Defined in

src/q/html.ts:100


iframeDialog

iframeDialog(options): void

Display a dialog that shows an HTML block in an IFRAME, which is usually returned from server callbacks

Parameters

Name Type Description
options IFrameDialogOptions The options

Returns

void

Defined in

src/q/dialogs.ts:465


indexOf

indexOf<TItem>(array, predicate): number

Gets index of first element in an array that matches given predicate.

Type parameters

Name
TItem

Parameters

Name Type Description
array TItem[] Array to test.
predicate (x: TItem) => boolean Predicate to test elements.

Returns

number

Defined in

src/q/arrays.ts:103


information

information(message, onOk?, options?): void

Obsolete

use informationDialog

Parameters

Name Type
message string
onOk? () => void
options? ConfirmOptions

Returns

void

Defined in

src/q/dialogs.ts:525


informationDialog

informationDialog(message, onOk?, options?): void

Display an information dialog

See

ConfirmOptions

Example

informationDialog("Operation complete", () => { 
    // do something when OK is clicked
}

Parameters

Name Type Description
message string The message to display
onOk? () => void Callback for OK button click
options? ConfirmOptions Additional options.

Returns

void

Defined in

src/q/dialogs.ts:525


initFormType

initFormType(typ, nameWidgetPairs): void

Parameters

Name Type
typ Function
nameWidgetPairs any[]

Returns

void

Defined in

src/q/system.ts:492


initFullHeightGridPage

initFullHeightGridPage(gridDiv, opt?): void

Parameters

Name Type
gridDiv HTMLElement | JQuery
opt? Object
opt.noRoute? boolean
opt.setHeight? boolean

Returns

void

Defined in

src/q/layout.ts:7


initializeTypes

initializeTypes(root, pre, limit): void

Parameters

Name Type
root any
pre string
limit number

Returns

void

Defined in

src/q/system.ts:621


insert

insert(obj, index, item): void

Inserts an item to the array at specified index. Prefer Array.splice unless you need to support IE.

Throws

Error if object does not support insert.

Example

insert([1, 2, 3], 1, 4); // [1, 4, 2, 3]
insert({ insert: (index, item) => { this.splice(index, 0, item); } }

Parameters

Name Type Description
obj any Array or array like object to insert to.
index number Index to insert at.
item any Item to insert.

Returns

void

Defined in

src/q/arrays.ts:122


isArray

isArray(arg): arg is any[]

Determines if the object is an array. Prefer Array.isArray over this function (e.g. Array.isArray(obj)).

Example

isArray([1, 2, 3]); // true
isArray({}); // false

Parameters

Name Type
arg any

Returns

arg is any[]

True if the object is an array.

Defined in

../../../../../Users/volka/AppData/Local/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/lib.es5.d.ts:1491


isAssignableFrom

isAssignableFrom(target, type): boolean

Parameters

Name Type
target any
type Type

Returns

boolean

Defined in

src/q/system.ts:171


isBS3

isBS3(): boolean

Returns true if Bootstrap 3 is loaded

Returns

boolean

Defined in

src/q/dialogs.ts:109


isBS5Plus

isBS5Plus(): boolean

Returns true if Bootstrap 5+ is loaded

Returns

boolean

Defined in

src/q/dialogs.ts:117


isEmptyOrNull

isEmptyOrNull(s): boolean

Checks if the string is empty or null.

Parameters

Name Type Description
s string String to check.

Returns

boolean

True if the string is empty or null.

Defined in

src/q/strings.ts:16


isEnum

isEnum(type): boolean

Parameters

Name Type
type any

Returns

boolean

Defined in

src/q/system.ts:487


isInstanceOfType

isInstanceOfType(instance, type): boolean

Parameters

Name Type
instance any
type Type

Returns

boolean

Defined in

src/q/system.ts:181


isMobileView

isMobileView(): boolean

Returns

boolean

Defined in

src/q/layout.ts:69


isTrimmedEmpty

isTrimmedEmpty(s): boolean

Checks if the string is empty or null or whitespace.

Parameters

Name Type Description
s string String to check.

Returns

boolean

True if the string is empty or null or whitespace.

Defined in

src/q/strings.ts:25


isValue

isValue(a): boolean

Parameters

Name Type
a any

Returns

boolean

Defined in

src/q/system.ts:7


jsxDomWidget

jsxDomWidget<TWidget, TOptions>(type): JsxDomWidget<TOptions & { ref?: (r: TWidget) => void }>

Type parameters

Name Type
TWidget extends Widget<TOptions, TWidget>
TOptions TOptions

Parameters

Name Type
type (element: JQuery, options?: TOptions) => TWidget

Returns

JsxDomWidget<TOptions & { ref?: (r: TWidget) => void }>

Defined in

src/ui/widgets/jsx.ts:74


keyOf

keyOf<T>(prop): keyof T

Type parameters

Name
T

Parameters

Name Type
prop keyof T

Returns

keyof T

Defined in

src/q/system.ts:542


layoutFillHeight

layoutFillHeight(element): void

Parameters

Name Type
element JQuery

Returns

void

Defined in

src/q/layout.ts:61


layoutFillHeightValue

layoutFillHeightValue(element): number

Parameters

Name Type
element JQuery

Returns

number

Defined in

src/q/layout.ts:46


loadValidationErrorMessages

loadValidationErrorMessages(): void

Returns

void

Defined in

src/q/validation.ts:116


localText

localText(key): string

Parameters

Name Type
key string

Returns

string

Defined in

src/q/localtext.ts:4


localeFormat

localeFormat(l, format, ...prm): string

Formats a string with parameters similar to .NET's String.Format function using the locale passed as the first argument.

Parameters

Name Type
l Locale
format string
...prm any[]

Returns

string

Defined in

src/q/formatting.ts:273


newBodyDiv

newBodyDiv(): JQuery

Creates a new DIV and appends it to the body.

Returns

JQuery

the new DIV element.

Defined in

src/q/html.ts:114


notifyError

notifyError(message, title?, options?): void

Parameters

Name Type
message string
title? string
options? ToastrOptions

Returns

void

Defined in

src/q/notify.ts:78


notifyInfo

notifyInfo(message, title?, options?): void

Parameters

Name Type
message string
title? string
options? ToastrOptions

Returns

void

Defined in

src/q/notify.ts:74


notifySuccess

notifySuccess(message, title?, options?): void

Parameters

Name Type
message string
title? string
options? ToastrOptions

Returns

void

Defined in

src/q/notify.ts:70


notifyWarning

notifyWarning(message, title?, options?): void

Parameters

Name Type
message string
title? string
options? ToastrOptions

Returns

void

Defined in

src/q/notify.ts:66


openPanel

openPanel(element, uniqueName?): void

Opens a panel, triggering panelbeforeopen and panelopen events on the panel element, and panelopening and panelopened events on the window. If the panelbeforeopen prevents the default, the operation is cancelled.

Parameters

Name Type Description
element HTMLElement | JQuery The panel element
uniqueName? string A unique name for the panel. If not specified, the panel id is used. If the panel has no id, a timestamp is used.

Returns

void

Defined in

src/q/dialogs.ts:674


outerHtml

outerHtml(element): string

Returns the outer HTML of the element.

Parameters

Name Type
element JQuery

Returns

string

Defined in

src/q/html.ts:121


padLeft

padLeft(s, len, ch?): any

Pads the string to the left with the specified character.

Parameters

Name Type Default value Description
s string | number undefined String to pad.
len number undefined Target length of the string.
ch string ' ' Character to pad with.

Returns

any

Padded string.

Defined in

src/q/strings.ts:36


parseCriteria

parseCriteria(expression, params?): any[]

Parses a criteria expression to Serenity Criteria array format. The string may optionally contain parameters like A >= @p1 and B < @p2.

Example

parseCriteria('A >=

P1

and B < @p2', { p1: 5, p2: 4 }) // [[[a], '>=' 5], 'and', [[b], '<', 4]]

Parameters

Name Type Description
expression string The criteria expression.
params? any The dictionary containing parameter values like { p1: 10, p2: 20 }.

Returns

any[]

Defined in

src/q/criteria.ts:694

parseCriteria(strings, ...values): any[]

Parses a criteria expression to Serenity Criteria array format. The expression may contain parameter placeholders like A >= ${p1} where p1 is a variable in the scope.

Example

var a = 5, b = 4;
parseCriteria`A >= ${a} and B < ${b}` // [[[a], '>=' 5], 'and', [[b], '<', 4]]

Parameters

Name Type Description
strings TemplateStringsArray The string fragments.
...values any[] The tagged template arguments.

Returns

any[]

Defined in

src/q/criteria.ts:705


parseDate

parseDate(s, dateOrder?): Date

Parses a string to a date. If the string is empty or whitespace, returns null. Returns a NaN Date if the string is not a valid date.

Parameters

Name Type Description
s string The string to parse.
dateOrder? string The order of the date parts in the string. Defaults to culture's default date order.

Returns

Date

Defined in

src/q/formatting.ts:964


parseDayHourAndMin

parseDayHourAndMin(s): number

Parses a string in the format "d.hh:mm" into a number containing number of minutes. Returns NaN if the hours not in range 0-23 or minutes not in range 0-59. Returns NULL if the string is empty or whitespace.

Parameters

Name Type
s string

Returns

number

Defined in

src/q/formatting.ts:935


parseDecimal

parseDecimal(s): number

Converts a string to a decimal. The difference between parseFloat and parseDecimal is that parseDecimal will return null if the string is empty or null, whereas parseFloat will return NaN and parseDecimal will use the current culture's group and decimal separators.

Parameters

Name Type Description
s string the string to parse

Returns

number

Defined in

src/q/formatting.ts:574


parseHourAndMin

parseHourAndMin(value): number

Parses a time string in the format "hh:mm" into a number containing number of minutes. Returns NaN if the hours not in range 0-23 or minutes not in range 0-59.

Parameters

Name Type
value string

Returns

number

Defined in

src/q/formatting.ts:908


parseISODateTime

parseISODateTime(s): Date

Parses a string in the ISO 8601 UTC date/time format.

Parameters

Name Type Description
s string The string to parse.

Returns

Date

Defined in

src/q/formatting.ts:887


parseInteger

parseInteger(s): number

Converts a string to an integer. The difference between parseInt and parseInteger is that parseInteger will return null if the string is empty or null, whereas parseInt will return NaN and parseInteger will use the current culture's group and decimal separators.

Parameters

Name Type Description
s string the string to parse

Returns

number

Defined in

src/q/formatting.ts:552


parseQueryString

parseQueryString(s?): Object

Parameters

Name Type
s? string

Returns

Object

Defined in

src/q/services.ts:153


positionToastContainer

positionToastContainer(create, options?): void

Parameters

Name Type
create boolean
options? ToastrOptions

Returns

void

Defined in

src/q/notify.ts:82


postToService

postToService(options): void

Parameters

Name Type
options PostToServiceOptions

Returns

void

Defined in

src/q/services.ts:169


postToUrl

postToUrl(options): void

Parameters

Name Type
options PostToUrlOptions

Returns

void

Defined in

src/q/services.ts:191


prefixedText

prefixedText(prefix): (text: string, key: string | (p?: string) => string) => string

Parameters

Name Type
prefix string

Returns

fn

▸ (text, key): string

Parameters
Name Type
text string
key string | (p?: string) => string
Returns

string

Defined in

src/q/localtext.ts:25


prop

prop(type, name, getter?, setter?): void

Parameters

Name Type
type any
name string
getter? string
setter? string

Returns

void

Defined in

src/q/system.ts:506


proxyTexts

proxyTexts(o, p, t): Object

Parameters

Name Type
o Record<string, any>
p string
t Record<string, any>

Returns

Object

Defined in

src/q/localtext.ts:63


reactPatch

reactPatch(): void

Returns

void

Defined in

src/ui/widgets/widget.ts:19


registerClass

registerClass(type, name, intf?): void

Parameters

Name Type
type any
name string
intf? any[]

Returns

void

Defined in

src/q/system.ts:579


registerEditor

registerEditor(type, name, intf?): void

Parameters

Name Type
type any
name string
intf? any[]

Returns

void

Defined in

src/q/system.ts:584


registerEnum

registerEnum(type, name, enumKey?): void

Parameters

Name Type
type any
name string
enumKey? string

Returns

void

Defined in

src/q/system.ts:589


registerInterface

registerInterface(type, name, intf?): void

Parameters

Name Type
type any
name string
intf? any[]

Returns

void

Defined in

src/q/system.ts:599


reloadLookup

reloadLookup<TItem>(key): Lookup<TItem>

Type parameters

Name Type
TItem any

Parameters

Name Type
key string

Returns

Lookup<TItem>

Defined in

src/q/scriptdata.ts:233


reloadLookupAsync

reloadLookupAsync<TItem>(key): Promise<Lookup<TItem>>

Type parameters

Name Type
TItem any

Parameters

Name Type
key string

Returns

Promise<Lookup<TItem>>

Defined in

src/q/scriptdata.ts:237


removeValidationRule

removeValidationRule(element, eventClass): JQuery

Parameters

Name Type
element JQuery
eventClass string

Returns

JQuery

Defined in

src/q/validation.ts:243


replaceAll

replaceAll(str, find, replace): string

Replaces all occurrences of the search string with the replacement string.

Parameters

Name Type Description
str string String to replace.
find string String to find.
replace string String to replace with.

Returns

string

Replaced string.

Defined in

src/q/strings.ts:111


resolveUrl

resolveUrl(url): string

Parameters

Name Type
url string

Returns

string

Defined in

src/q/services.ts:217


round

round(n, d?, rounding?): number

Rounds a number to specified digits or an integer number if digits are not specified.

Parameters

Name Type Description
n number the number to round
d? number the number of digits to round to. default is zero.
rounding? boolean whether to use banker's rounding

Returns

number

the rounded number

Defined in

src/q/formatting.ts:294


safeCast

safeCast(instance, type): any

Parameters

Name Type
instance any
type Type

Returns

any

Defined in

src/q/system.ts:191


serviceCall

serviceCall<TResponse>(options): JQueryXHR

Type parameters

Name Type
TResponse extends ServiceResponse

Parameters

Name Type
options ServiceOptions<TResponse>

Returns

JQueryXHR

Defined in

src/q/services.ts:28


serviceRequest

serviceRequest<TResponse>(service, request?, onSuccess?, options?): JQueryXHR

Type parameters

Name Type
TResponse extends ServiceResponse

Parameters

Name Type
service string
request? any
onSuccess? (response: TResponse) => void
options? ServiceOptions<TResponse>

Returns

JQueryXHR

Defined in

src/q/services.ts:124


setEquality

setEquality(request, field, value): void

Parameters

Name Type
request ListRequest
field string
value any

Returns

void

Defined in

src/q/services.ts:133


setTypeNameProp

setTypeNameProp(type, value): void

Parameters

Name Type
type Type
value string

Returns

void

Defined in

src/q/system.ts:142


single

single<TItem>(array, predicate): TItem

Gets first element in an array that matches given predicate. Throws an error if no matches is found, or there are multiple matches.

Example

first([1, 2, 3], x => x == 2); // 2
first([1, 2, 3], x => x == 4); // throws error.

Type parameters

Name
TItem

Parameters

Name Type Description
array TItem[] Array to test.
predicate (x: TItem) => boolean Predicate to test elements.

Returns

TItem

First element that matches.

Defined in

src/q/arrays.ts:151


splitDateString

splitDateString(s): string[]

Splits a date string into an array of strings, each containing a single date part. It can handle separators "/", ".", "-" and "".

Parameters

Name Type Description
s string The string to split.

Returns

string[]

Defined in

src/q/formatting.ts:1038


startsWith

startsWith(s, prefix): boolean

Checks if the string starts with the prefix

Parameters

Name Type Description
s string String to check.
prefix string Prefix to check.

Returns

boolean

True if the string starts with the prefix.

Defined in

src/q/strings.ts:51


success

success(message, onOk?, options?): void

Obsolete

use successDialog

Parameters

Name Type
message string
onOk? () => void
options? ConfirmOptions

Returns

void

Defined in

src/q/dialogs.ts:556


successDialog

successDialog(message, onOk?, options?): void

Display a success dialog

See

ConfirmOptions

Example

successDialog("Operation complete", () => { 
    // do something when OK is clicked
}

Parameters

Name Type Description
message string The message to display
onOk? () => void Callback for OK button click
options? ConfirmOptions Additional options.

Returns

void

Defined in

src/q/dialogs.ts:556


text

text(key): string

Obsolete

prefer localText for better discoverability

Parameters

Name Type
key string

Returns

string

Defined in

src/q/localtext.ts:4


toGrouping

toGrouping<TItem>(items, getKey): Grouping<TItem>

Maps an array into a dictionary with keys determined by specified getKey() callback, and values that are arrays containing elements for a particular key.

Example

toGrouping([1, 2, 3], x => x % 2 == 0 ? "even" : "odd"); // { odd: [1, 3], even: [2] }

Type parameters

Name
TItem

Parameters

Name Type Description
items TItem[] Array to map.
getKey (x: TItem) => any Function that returns key for each item.

Returns

Grouping<TItem>

Grouping object.

Defined in

src/q/arrays.ts:180


toId

toId(id): any

Converts a string to an ID. If the string is a number, it is returned as-is. If the string is empty, null or whitespace, null is returned. Otherwise, it is converted to a number if possible. If the string is not a valid number or longer than 14 digits, the trimmed string is returned as-is.

Parameters

Name Type Description
id any the string to convert to an ID

Returns

any

Defined in

src/q/formatting.ts:628


toSingleLine

toSingleLine(str): string

Converts the string to single line by removing line end characters

Parameters

Name Type Description
str string String to convert.

Returns

string

Defined in

src/q/strings.ts:59


today

today(): Date

Returns

Date

Defined in

src/q/system.ts:11


toggleClass

toggleClass(el, cls, remove?): void

Toggles the class on the element handling spaces like jQuery addClass does.

Parameters

Name Type Description
el Element the element
cls string the class to toggle
remove? boolean if true, the class will be added, if false the class will be removed, otherwise it will be toggled.

Returns

void

Defined in

src/q/html.ts:132


triggerLayoutOnShow

triggerLayoutOnShow(element): void

Parameters

Name Type
element JQuery

Returns

void

Defined in

src/q/layout.ts:93


trim

trim(s): string

Trims the whitespace characters from the start and end of the string This returns empty string even when the string is null or undefined.

Parameters

Name Type
s string

Returns

string

Defined in

src/q/strings.ts:81


trimEnd

trimEnd(s): any

Trims the whitespace characters from the end of the string

Parameters

Name Type
s string

Returns

any

Defined in

src/q/strings.ts:66


trimStart

trimStart(s): any

Trims the whitespace characters from the start of the string

Parameters

Name Type
s string

Returns

any

Defined in

src/q/strings.ts:73


trimToEmpty

trimToEmpty(s): string

Trims the whitespace characters from the start and end of the string Returns empty string if the string is null or undefined.

Parameters

Name Type
s string

Returns

string

Defined in

src/q/strings.ts:89


trimToNull

trimToNull(s): string

Trims the whitespace characters from the start and end of the string Returns null if the string is null, undefined or whitespace.

Parameters

Name Type
s string

Returns

string

Defined in

src/q/strings.ts:97


trunc

trunc(n): number

Truncates a number to an integer number.

Parameters

Name Type
n number

Returns

number

Defined in

src/q/formatting.ts:309


tryFirst

tryFirst<TItem>(array, predicate): TItem

Gets first element in an array that matches given predicate (similar to LINQ's FirstOrDefault). Returns null if no match is found.

Example

tryFirst([1, 2, 3], x => x == 2); // 2
tryFirst([1, 2, 3], x => x == 4); // null

Type parameters

Name
TItem

Parameters

Name Type Description
array TItem[] Array to test.
predicate (x: TItem) => boolean Predicate to test elements.

Returns

TItem

First element that matches.

Defined in

src/q/arrays.ts:204


tryGetText

tryGetText(key): string

Parameters

Name Type
key string

Returns

string

Defined in

src/q/localtext.ts:52


turkishLocaleCompare

turkishLocaleCompare(a, b): number

This is an alias for Culture.stringCompare, left in for compatibility reasons.

Parameters

Name Type
a string
b string

Returns

number

Defined in

src/q/formatting.ts:58


turkishLocaleToLower

turkishLocaleToLower(a): string

A string to lowercase function that handles special Turkish characters like 'ı'. Left in for compatibility reasons.

Parameters

Name Type
a string

Returns

string

Defined in

src/q/formatting.ts:170


turkishLocaleToUpper

turkishLocaleToUpper(a): string

A string to uppercase function that handles special Turkish characters like 'ı'. Left in for compatibility reasons.

Parameters

Name Type
a string

Returns

string

Defined in

src/q/formatting.ts:180


useIdPrefix

useIdPrefix(prefix): IdPrefixType

Parameters

Name Type
prefix string

Returns

IdPrefixType

Defined in

src/ui/widgets/templatedwidget.ts:138


validateForm

validateForm(form, opt): JQueryValidation.Validator

Parameters

Name Type
form JQuery
opt ValidationOptions

Returns

JQueryValidation.Validator

Defined in

src/q/validation.ts:230


validateOptions

validateOptions(options?): ValidationOptions

Parameters

Name Type
options? ValidationOptions

Returns

ValidationOptions

Defined in

src/q/validateoptions.ts:61


validatorAbortHandler

validatorAbortHandler(validator): void

Parameters

Name Type
validator any

Returns

void

Defined in

src/q/validateoptions.ts:54


warning

warning(message, options?): void

Obsolete

use warningDialog

Parameters

Name Type
message string
options? AlertOptions

Returns

void

Defined in

src/q/dialogs.ts:584


warningDialog

warningDialog(message, options?): void

Display a warning dialog

See

AlertOptions

Example

warningDialog("Something is odd!");

Parameters

Name Type Description
message string The message to display
options? AlertOptions Additional options.

Returns

void

Defined in

src/q/dialogs.ts:584


zeroPad

zeroPad(n, len): string

Pads the start of string to make it the specified length.

Parameters

Name Type Description
n number -
len number Target length of the string.

Returns

string

Defined in

src/q/strings.ts:121