Namespace: Util

January 18, 2022 · View on GitHub

Kui API Documentation - v11.0.0 / @kui-shell/core / Util

Namespace: Util

@kui-shell/core.Util

Table of contents

Functions

Functions

absolute

absolute(filepath): string

Notes:

  • path.resolve() turns /kui/x into c:\kui\x. We just want to absolute-ify a local filepath if it isn't already so.

  • this only works for local filepaths; if we wanted this to work for all kui VFS, we would need to use vfs ls, which is asynchronous.

Parameters

NameType
filepathstring

Returns

string

An absolute path for the given path, only if it is not already absolute

Defined in

packages/core/src/util/absolute.ts:31


base64PlusGzip

base64PlusGzip(plaintext, compress?): string

Parameters

NameTypeDefault value
plaintextstringundefined
compressbooleantrue

Returns

string

a base64-encoded and gzip-compressed version of the given plaintext

Defined in

packages/core/src/util/gzip.ts:24


cwd

Const cwd(): string

Returns

string

Defined in

packages/core/src/util/home.ts:49


decodeBase64PlusGzip

decodeBase64PlusGzip(data, compressed?): Buffer

Parameters

NameTypeDefault value
datastringundefined
compressedbooleantrue

Returns

Buffer

the reverse of base64PlusGzip

Defined in

packages/core/src/util/gzip.ts:33


expandHomeDir

Const expandHomeDir(path): string

Parameters

NameType
pathstring

Returns

string

Defined in

packages/core/src/util/home.ts:24


fallbackCWD

fallbackCWD(cwd?): string

In case of error, e.g. removed CWD, this is our fallback plan

Parameters

NameType
cwd?string

Returns

string

Defined in

packages/core/src/util/home.ts:41


flatten

flatten<T>(arrays): T[]

flatten an array of arrays

Type parameters

Name
T

Parameters

NameType
arraysT[][]

Returns

T[]

Defined in

packages/core/src/core/utility.ts:72


isHTML

isHTML(message): message is HTMLElement

Parameters

NameType
messageNode | Entity<void, Row, ResourceWithMetadata<void>> | MessageWithUsageModel

Returns

message is HTMLElement

Defined in

packages/core/src/util/types.ts:21


isPromise

isPromise<T, U>(content): content is Promise<T>

Type parameters

Name
T
U

Parameters

NameType
contentU | Promise<T>

Returns

content is Promise<T>

Defined in

packages/core/src/util/types.ts:25


prettyPrintBytes

prettyPrintBytes(_bytes): string

Parameters

NameType
_bytesstring | number

Returns

string

pretty-printed bytes

Defined in

packages/core/src/webapp/util/bytes.ts:18


prettyPrintTime

Const prettyPrintTime(timestamp, fmt?, previousTimestamp?, execOptions?): HTMLElement

Pretty print a timestamp

Parameters

NameTypeDefault value
timestampstring | number | Dateundefined
fmt"delta" | "long" | "short" | "narrow"'long'
previousTimestamp?string | number | Dateundefined
execOptionsLanguageBearingundefined

Returns

HTMLElement

Defined in

packages/core/src/webapp/util/time.ts:36


promiseEach

promiseEach<T, R>(arr, fn): Promise<R[]>

Map a asynchronous function to an array sequentially from front to back.

Type parameters

Name
T
R

Parameters

NameType
arrT[]
fn(t: T, idx: number) => R | Promise<R>

Returns

Promise<R[]>

Defined in

packages/core/src/util/async.ts:22