Skip to content

k.utils ​

KScript 工具集:按子模块划分的辅助 API

概述 ​

k.utils 聚合站点脚本常用的工具方法与子对象。除下文列出的根方法外,每个子模块对应独立文档页(路径与脚本属性名一致,便于按字母检索)。

根方法 ​

方法说明
sleep(ms)阻塞当前线程指定毫秒
bytesToString(bytes, encoding)字节数组按编码转字符串
stringToBytes(content, encoding)字符串按编码转字节数组
参数类型必填说明
msnumber是暂停毫秒数
bytesnumber[]是要转换的字节数组
contentstring是要转换的文本
encodingstring是字符编码,如 utf-8
方法返回
sleep(ms)void
bytesToString(bytes, encoding)string
stringToBytes(content, encoding)number[]
ts
k.utils.sleep(100)

编码转换常用于处理远程下载、压缩包或文本文件的字节数组:

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 }

子模块(按字母序) ​

子模块文档
CDNcdn
clientJSclientJS
communitycommunity
compressioncompression
converterconverter
CRMcrm
datedate
domdom
imageimage
inlineHtmlinlineHtml
mimemime
ninjibleninjible
officeoffice
puppeteerpuppeteer
screenShotscreenShot
sitemapsitemap
smssms
stringstring
templatetemplate
uriuri
xmlxml

相关文档 ​

  • k.net — IP、Ping、SSH、SFTP 与 Telnet
  • k.google — PageSpeed/Lighthouse 与 Firebase
  • k.file — 站点文件读写