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
- absolute
- base64PlusGzip
- cwd
- decodeBase64PlusGzip
- expandHomeDir
- fallbackCWD
- flatten
- isHTML
- isPromise
- prettyPrintBytes
- prettyPrintTime
- promiseEach
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
| Name | Type |
|---|---|
filepath | string |
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
| Name | Type | Default value |
|---|---|---|
plaintext | string | undefined |
compress | boolean | true |
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
| Name | Type | Default value |
|---|---|---|
data | string | undefined |
compressed | boolean | true |
Returns
Buffer
the reverse of base64PlusGzip
Defined in
packages/core/src/util/gzip.ts:33
expandHomeDir
▸ Const expandHomeDir(path): string
Parameters
| Name | Type |
|---|---|
path | string |
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
| Name | Type |
|---|---|
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
| Name | Type |
|---|---|
arrays | T[][] |
Returns
T[]
Defined in
packages/core/src/core/utility.ts:72
isHTML
▸ isHTML(message): message is HTMLElement
Parameters
| Name | Type |
|---|---|
message | Node | 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
| Name | Type |
|---|---|
content | U | Promise<T> |
Returns
content is Promise<T>
Defined in
packages/core/src/util/types.ts:25
prettyPrintBytes
▸ prettyPrintBytes(_bytes): string
Parameters
| Name | Type |
|---|---|
_bytes | string | 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
| Name | Type | Default value |
|---|---|---|
timestamp | string | number | Date | undefined |
fmt | "delta" | "long" | "short" | "narrow" | 'long' |
previousTimestamp? | string | number | Date | undefined |
execOptions | LanguageBearing | undefined |
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
| Name | Type |
|---|---|
arr | T[] |
fn | (t: T, idx: number) => R | Promise<R> |
Returns
Promise<R[]>