KScript docs
EN

KScript.Storage

App folders for config, data, cache, state and logs, in the right place on each platform.

Import it at the top of a script:

<import package="KScript.Storage" />
import KScript.Storage

It brings KScript.IO with it.

KScript.Storage writes to your app's own folders, so its examples can't run inside the docs. Copy one into a .ks.xml file and run it with kscript.

Commands

Commands are called with @, in any expression: @name(arguments).

#@app_folders(app?) → map

Every folder of the app, by kind: .

Example
<echo>{ @app_folders(app: 'Notes').cache }</echo>
echo @app_folders(app: 'Notes').cache

#@app_name() → string

The name the app's folders are named after: app.name in kscript.json, else name, else the script's name.
Example
<echo>{ @app_name() }</echo>
echo @app_name()

#@storage(kind?: config|data|cache|state|logs, app?) → storage

One of the app's folders, in the right place for this platform: config (settings), data (the app's files), cache (files that can be made again), state (history, recent files) or logs. The default is data. The app is app.name in kscript.json, else the script's name.
ParameterTakes
kind optionalone of these words: config|data|cache|state|logs
app optionalany value

Arguments can be named: @storage(…, app: …).

Example
<do>@storage(config)->write_json('settings.json', { theme: 'dark' })</do>
<echo>{ @storage(config)->read_json('settings.json').theme }</echo>
@storage(config)->write_json('settings.json', { theme: 'dark' })
echo @storage(config)->read_json('settings.json').theme

Methods

On storage values: ->path_of(), ->exists(), ->read(), ->read_json(), ->read_bytes(), ->write_bytes(), ->file(), ->move(), ->copy(), ->write(), ->append(), ->write_json(), ->delete(), ->list(), ->folder(), ->clear()