Skip to main content

Utils

Defined in: js-api/src/utils.ts:174

Constructors

Constructor

new Utils(): Utils

Returns

Utils

Methods

createResultsCsv()

static createResultsCsv(resultDF?): string

Defined in: js-api/src/utils.ts:400

Internal

Parameters

ParameterType
resultDF?DataFrame

Returns

string


detectColumnHierarchy()

static detectColumnHierarchy(columns, maxDepth?): string[]

Defined in: js-api/src/utils.ts:395

Detects natural hierarchy in the list of categorical columns based on their values. Mind that the function can be n^2 in the worst case scenario, although in most cases, it is quite fast as it exits early if missmatch is found.

Parameters

ParameterTypeDefault valueDescription
columnsColumn<any, any>[]undefinedList of columns to detect hierarchy in.
maxDepthnumber3Maximum depth of the hierarchy to detect.

Returns

string[]


download()

static download(filename, content, contentType?): void

Defined in: js-api/src/utils.ts:239

Downloads the specified content locally

Parameters

ParameterType
filenamestring
contentBlobPart
contentType?string

Returns

void


executeTests()

static executeTests(testsParams, stopOnFail?): Promise<any>

Defined in: js-api/src/utils.ts:299

Internal

Runs the specified package tests and aggregates their results (used by the test runner).

Parameters

ParameterType
testsParamsobject[]
stopOnFail?boolean

Returns

Promise<any>


firstOrNull()

static firstOrNull<T>(iterable): T | null

Defined in: js-api/src/utils.ts:176

Type Parameters

Type Parameter
T

Parameters

ParameterType
iterableIterable<T>

Returns

T | null


formatDuration()

static formatDuration(seconds): string

Defined in: js-api/src/utils.ts:416

Formats a duration in seconds as a compact human string: 45s, 3m 12s, 2h 5m.

Parameters

ParameterType
secondsnumber

Returns

string


getJsonValueType()

static getJsonValueType(x): "string" | "bigint" | "object" | "bool" | "int" | "double" | "byte_array" | "datetime" | "qnum" | "dataframe" | null

Defined in: js-api/src/utils.ts:269

Parameters

ParameterType
xany

Returns

"string" | "bigint" | "object" | "bool" | "int" | "double" | "byte_array" | "datetime" | "qnum" | "dataframe" | null


identity()

static identity(length): Uint32Array<ArrayBuffer>

Defined in: js-api/src/utils.ts:182

Returns an 'identity' array where the element in idx-th position is equals to idx.

Parameters

ParameterType
lengthnumber

Returns

Uint32Array<ArrayBuffer>


isEmpty()

static isEmpty(s?): boolean

Defined in: js-api/src/utils.ts:204

Parameters

ParameterType
s?string

Returns

boolean


jsonToColumns()

static jsonToColumns(column): void

Defined in: js-api/src/utils.ts:283

Expands a column of JSON strings into multiple columns, one per unique key

Parameters

ParameterType
columnColumn<string>

Returns

void


loadJsCss()

static loadJsCss(files): Promise<null>

Defined in: js-api/src/utils.ts:252

Loads the specified common libraries, if they were not loaded already. Use it in plugins when a big JS dependency is used infrequently, such as exporting to Excel, or showing a 3d structure. Example: loadJsCss(['common/exceljs.min.js', 'common/exceljs.min.css'])

Parameters

ParameterType
filesstring[]

Returns

Promise<null>


nullIfEmpty()

static nullIfEmpty(s?): string | null | undefined

Defined in: js-api/src/utils.ts:208

Parameters

ParameterType
s?string

Returns

string | null | undefined


openFile()

static openFile(options): void

Defined in: js-api/src/utils.ts:213

Shows "Open File" dialog, and lets you process the result.

Parameters

ParameterType
options{ accept: string; open: (file) => void; }
options.acceptstring
options.open(file) => void

Returns

void


openFileBytes()

static openFileBytes(options): void

Defined in: js-api/src/utils.ts:225

Shows "Open File" dialog, and lets you process the result.

Parameters

ParameterType
options{ accept: string; open: (bytes) => void; }
options.acceptstring
options.open(bytes) => void

Returns

void


random()

static random<T>(items): T

Defined in: js-api/src/utils.ts:190

Returns random element from the array. Useful for demo data, tests, etc.

Type Parameters

Type Parameter
T

Parameters

ParameterType
itemsT[]

Returns

T


randomString()

static randomString(length): string

Defined in: js-api/src/utils.ts:427

Parameters

ParameterType
lengthnumber

Returns

string


replaceAll()

static replaceAll(string, search, replace): string

Defined in: js-api/src/utils.ts:200

Parameters

ParameterType
stringstring
searchstring
replacestring

Returns

string


streamToObservable()

static streamToObservable<T>(dartStream): Observable<T>

Defined in: js-api/src/utils.ts:256

Type Parameters

Type ParameterDefault type
Tany

Parameters

ParameterType
dartStreamany

Returns

Observable<T>


uuid4()

static uuid4(): string

Defined in: js-api/src/utils.ts:196

A random v4 UUID. Unlike crypto.randomUUID() this also works outside a secure context — a stand served over plain HTTP on a hostname has no randomUUID.

Returns

string