k.utils
KScript Toolset: Helper API by submodule
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, Page / View server scripts, jobs | Varies by submodule (e.g. puppeteer, CDN, SMS, and CRM need host/account config) | Byte/string encoding, short sleeps, and navigating 21 utility submodules |
k.utils aggregates commonly used utility methods and sub-objects in site scripts. Beyond the root methods listed below, each submodule has its own dedicated reference page.
Quick Start
js
k.api.get("encode", () => {
const bytes = k.utils.stringToBytes("Hello Kooboo", "utf-8")
const text = k.utils.bytesToString(bytes, "utf-8")
k.utils.sleep(50)
return { byteCount: bytes.length, text }
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
sleep(millisecondsTimeout) | Pause the current script thread for the specified milliseconds | void |
bytesToString(bytes, encoding) | Decode a byte array into a string using the specified encoding | string |
stringToBytes(content, encoding) | Encode a string into a byte array using the specified encoding | number[] |
Root Methods
| Method | Description |
|---|---|
sleep(millisecondsTimeout) | 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 |
|---|---|---|---|
millisecondsTimeout | 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 |
Returns: sleep() returns void; bytesToString() returns string; stringToBytes() returns number[].
js
k.utils.sleep(100)Encoding conversion is useful when you work with downloaded files, ZIP entries, or text stored as bytes:
js
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 | Doc |
|---|---|
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 |
TypeScript Definitions
ts
interface KUtils {
xml: Xml;
uri: KUri;
clientJS: ClientJs;
community: KCommunity;
compression: Compression;
converter: Converter;
date: KDate;
mime: KMime;
dom: DocumentObjectModel;
sms: SMS;
office: Office;
sitemap: KSitemap;
screenShot: ScreenShot;
inlineHtml: KInlineHTML;
image: KImageUtility;
template: KTemplateEngine;
ninjible: Ninjible;
CRM: KCRM;
CDN: CDNUtility;
puppeteer: KPuppeteer;
string: KText;
sleep(millisecondsTimeout: number): void;
bytesToString(bytes: number[], encoding: string): string;
stringToBytes(content: string, encoding: string): number[];
}