Appearance
k.utils
KScript Toolset: Helper API by submodule
Overview
k.utils aggregates commonly used tool methods and sub-objects in site scripts. Except for the root methods listed below, each submodule has its own documentation page.
Root Methods
| method | illustrate |
|---|---|
sleep(ms) | Blocks the current thread for specified milliseconds |
bytesToString(bytes, encoding) | Convert byte array to string according to encoding |
stringToBytes(content, encoding) | Convert string to byte array according to encoding |
| Parameter | Type | Required | Description |
|---|---|---|---|
ms | number | Yes | Sleep duration in milliseconds |
bytes | number[] | Yes | Byte array to convert |
content | string | Yes | Text to convert |
encoding | string | Yes | Character encoding, such as utf-8 |
| Method | Return |
|---|---|
sleep(ms) | void |
bytesToString(bytes, encoding) | string |
stringToBytes(content, encoding) | number[] |
ts
k.utils.sleep(100)Encoding conversion is useful when you work with downloaded files, ZIP entries, or text stored as bytes:
ts
const bytes = k.utils.stringToBytes("Hello Kooboo", "utf-8")
k.file.writeBinary("exports/hello.txt", bytes)
const saved = k.file.readBinary("exports/hello.txt")
const text = k.utils.bytesToString(saved, "utf-8")
return { text }Submodules
| submodule | document |
|---|---|
CDN | cdn |
clientJS | clientJS |
community | community |
compression | compression |
converter | converter |
CRM | crm |
date | date |
dom | dom |
image | image |
inlineHtml | inlineHtml |
mime | mime |
ninjible | ninjible |
office | office |
puppeteer | puppeteer |
screenShot | screenShot |
sitemap | sitemap |
sms | sms |
string | string |
template | template |
uri | uri |
xml | xml |