From f82b343f89667d9c886d53a6a4fa64a3e07d80c6 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 19 Feb 2024 20:45:42 +0800 Subject: [PATCH] docs: add `quote` and `sleep` --- docs/plugins/utils.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/plugins/utils.md b/docs/plugins/utils.md index 0a82ad5c..4d87d4ce 100644 --- a/docs/plugins/utils.md +++ b/docs/plugins/utils.md @@ -130,6 +130,16 @@ This function is only available in the async context. Returns the target family of the current platform, `"windows"`, `"unix"`, or `"wasm"`. +### `quote(str)` + +Quote characters that may have special meaning in a shell: + +- `str`: Required, the string to be quoted, which is a string + +```lua +local handle = io.popen("ls " .. ya.quote(filename)) +``` + ### `truncate(text, max)` Truncate the text to the specified length and return it: @@ -147,6 +157,18 @@ Check whether the mime-type is valid: Returns the current timestamp, which is a float, the integer part represents the seconds, and the decimal part represents the milliseconds. +### `sleep(secs)` + +Waits until `secs` has elapsed: + +- `secs`: Required, the number of seconds to sleep, which is a positive float + +```lua +ya.sleep(0.5) -- Sleep for 500 milliseconds +``` + +This function is only available in the async context. + ### `uid()` Only available on Unix-like systems. Returns the user id of the current user, which is an integer.