Utils#
Singleton with utility methods. More...
import Script
Methods#
Name | |
---|---|
addScriptPath(string path, bool projectOnly) | |
string | convertCase(string str, Case from, Case to) |
string | copyToClipboard(string text) |
string | cppKeywords() |
string | cppPrimitiveTypes() |
string | getEnv(string varName) |
string | getGlobal(string varName) |
string | mktemp(string pattern) |
runScript(string path, bool log) | |
setGlobal(string varName, string value) | |
sleep(int msecs) |
Detailed Description#
The Utils
singleton implements some utility methods useful for scripts.
Method Documentation#
addScriptPath(string path, bool projectOnly)#
Adds the script directory path
from another script.
Could be useful to load multiple paths at once, by creating a init.js file like this:
function main() {
Utils.addScriptPath(Dir.currentScriptPath() + "/message")
Utils.addScriptPath(Dir.currentScriptPath() + "/texteditor")
Utils.addScriptPath(Dir.currentScriptPath() + "/dialog")
Utils.addScriptPath(Dir.currentScriptPath() + "/cppeditor")
}
string convertCase(string str, Case from, Case to)#
Converts and returns the string str
with a different case pattern: from from
to to
.
The different cases are:
Utils.CamelCase
: "toCamelCase",Utils.PascalCase
: "ToPascalCase",Utils.SnakeCase
: "to_snake_case",Utils.UpperCase
: "TO_UPPER_CASE",Utils.KebabCase
: "to-kebab-case",Utils.TitleCase
: "To Title Case".
string copyToClipboard(string text)#
Copy the text to the clipboard
string cppKeywords()#
Returns a list of cpp keywords.
string cppPrimitiveTypes()#
Returns a list of cpp primitive types
string getEnv(string varName)#
Returns the value of the environment variable varName
.
string getGlobal(string varName)#
Returns the value of the global varName
. A global value is a value set by a script, and
persistent only in the current knut execution (it will disappear once closed).
For persistent settings, see Settings.
string mktemp(string pattern)#
Creates and returns the name of a temporary file based on a pattern
.
runScript(string path, bool log)#
Runs the script given by path
. If log
is true, it will also log the run of the script.
setGlobal(string varName, string value)#
Sets the global value varName
to value
. A global value is a value set by a script, and
persistent only in the current Knut execution (it will disappear once closed).
For persistent settings, see Settings.
sleep(int msecs)#
Sleeps for msecs
milliseconds.