#<break>break
break.Self-closing.A statement on its own.
<for each="n" in="1..100">
<if $n gt 3>
<break />
</if>
<echo>$n</echo>
</for>for n in 1..100 {
if $n > 3 {
break
}
echo $n
}The language itself: variables, branches, loops, functions, errors, imports and echo. Always imported.
KScript.Core is the language itself. Every script and page has it, so there is nothing to import.
<break>breakbreak.Self-closing.A statement on its own.
<for each="n" in="1..100">
<if $n gt 3>
<break />
</if>
<echo>$n</echo>
</for>for n in 1..100 {
if $n > 3 {
break
}
echo $n
}<call>callSelf-closing.A statement on its own.
| AttributeOption | Value | Description |
|---|---|---|
fn required | a function: @name | The function (or command) to call: @greet (in XML, fn="greet"). |
args | expressions, comma separated | Arguments, comma separated. |
into | a new variable's name | A variable for the result. |
<fn name="greet" params="who: string"><echo>Hello, $who!</echo></fn>
<call fn="greet" args="'World'" />fn greet(who: string) {
echo "Hello, { $who }!"
}
@greet('World')<case>value => …is, or when when is true (with both, the value must match and when must be true). In a .kscript file a branch is an arm: 1, 2 => ..., _ when $n > 9 => ....A branch of match: runs when the value equals one of is, or when when is true (with both, the value must match and when must be true). In a .kscript file a branch is an arm: 1, 2 => ..., _ when $n > 9 => ....0 => 'zero', or _ => 'other' for the fallback.Holds statements.Holds statements in { }. Goes inside <match>match.
| Attribute | Value | Description |
|---|---|---|
is | expressions, comma separated | Values to compare with, comma separated. |
when | expression | A condition. |
<let name="n" value="12" />
<match $n>
<case is="1, 2"><echo>a couple</echo></case>
<case when="$n gt 9"><echo>lots</echo></case>
<default><echo>a few</echo></default>
</match>$n = 12
match $n {
1, 2 => echo 'a couple'
_ when $n > 9 => echo 'lots'
_ => echo 'a few'
}<catch>catch err@load() catch Validation => $err.message for a fallback value or append catch Validation { return $err.message } to a declaration. Omit the type to catch any error.Holds statements.Holds statements in { }. Goes inside <try>try or <fn>fn or <type>type or <model>model.
| Attribute | Value | Description |
|---|---|---|
as | a new variable's name | A variable for the error. Defaults to err. |
when | expression | Only handle errors for which this is true, such as $err.status == 404. |
type | an error type | Only handle errors of these types, or types that extend them: NotFound, [IO, Network]. Error catches everything. |
<try>
<throw type="NotFound" message="No such order" />
<catch type="NotFound" as="e">
<echo>{ $e.type } ({ $e.status }): { $e.message }</echo>
</catch>
</try>try {
throw NotFound "No such order"
} catch NotFound as e {
echo "{ $e.type } ({ $e.status }): { $e.message }"
}<collection>collectionHolds statements.Holds statements in { }. Holds only <item>item.
| AttributeOption | Value | Description |
|---|---|---|
name required | a new variable's name | The variable to declare. |
const | true or false | true makes a later <set> an error.true makes a later $name += value an error. |
<collection name="person">
<item key="name">Joan</item>
<item key="age">82</item>
</collection>collection(name: person) {
item(key: 'name') "Joan"
item(key: 'age') "82"
}<config>configinto, it changes $config.Self-closing.A statement on its own. Scripts only.
| AttributeOption | Value | Description |
|---|---|---|
env | a string with { } | The environment, such as staging or production. Its files (kscript.staging.json, .env.staging) are layered over the base files. Default: kscript --env, or KSCRIPT_ENV. |
files | a string with { } | Other files to read, as a list: ['settings.json', 'secrets.kscript?', '.env?'] (in XML, settings.json, secrets.kscript?, .env?). JSON files hold settings, a .kscript file defines configure(environment), and .env files feed @env(). A name without an extension means its .json file. End a name with ? if it may be missing. |
prefix | a string | Environment variables with this prefix override the files: with prefix="APP_", APP_DATABASE__HOST sets database.host. |
root | a file path | The folder the files are in. Default: the script's folder. |
defaults | expression | A map of settings used when no file sets them. |
require | a list of names: [a, b] | Settings that must be set, as a list: ['database.host', 'api.key'] (in XML, database.host, api.key). |
user | true or false | true also reads the person's own settings: config.json in the app's config folder (see KScript.Storage), layered over the other files. |
export_env | true or false | no stops values in .env files becoming environment variables (they always do for @env() unless this is no). |
into | a new variable's name | Store the settings in this variable instead of changing $config. |
<config env="staging" prefix="APP_" require="database.host" defaults="{ server: { port: 8080 }, database: { host: 'localhost' } }" />
<echo>{$config.database.host}:{$config.server.port}</echo>config(env: 'staging', prefix: 'APP_', require: 'database.host', defaults: { server: { port: 8080 }, database: { host: 'localhost' } })
echo "{$config.database.host}:{$config.server.port}"<const>const $name = valueconst limit = 10.Its text is one expression.
| Attribute | Value | Description |
|---|---|---|
name required | a new variable's name | The constant to declare. |
value | expression | Its value. Can be written as the element's text instead. |
type | string | int | float | number | bool | list | set | map | fn | date | markdown | latex | formatted_file | document | email | password | handle | uuid | regex | url | domain | ip | cidr | mac | port | slug | slash_path | file_path | semver | mime | hex | base64 | jwt | json | csv | phone | country | currency | locale | timezone | duration | date_format | cron | color | iban | card | money | any | Convert the value to this type, or fail early: a built-in such as int, an <enum>, a <type>, T[] for a list, T? to allow null.Convert the value to this type, or fail early: a built-in such as int, an enum, a type, T[] for a list, T? to allow null. |
description | a string | What the constant is for, shown on hover. |
<const name="max_size" value="10 * 1024" />const $max_size = 10 * 1024<construct>constructPoint(x: 1) or as a component's attributes, and every other field of the type is the value's own state. The statements run once when a value is made, with the fields as variables they can set. In a .kscript file: construct({ x: number, y: number = 0 }) { ... }.Holds statements.Holds statements in { }. Goes inside <type>type.
| AttributeOption | Value | Description |
|---|---|---|
description | a string | What the constructor does, shown on hover. |
<type name="Point">
<construct>
<field name="x" type="number" />
<field name="y" type="number" default="0" />
<set name="sum" value="$x + $y" />
</construct>
<field name="sum" type="number" />
</type>
<echo>{ Point(x: 3, y: 4).sum }</echo>type Point {
construct({ x: number, y: number = 0 }) {
.sum = .x + .y
}
sum: number
}
echo Point(x: 3, y: 4).sum<continue>continuecontinue.Self-closing.A statement on its own.
<for each="n" in="1..6">
<if $n % 2 eq 0>
<continue />
</if>
<echo>$n</echo>
</for>for n in 1..6 {
if $n % 2 == 0 {
continue
}
echo $n
}<default>_ => …_ => ....The branch of match that runs when no case matched. In a .kscript file it is the arm _ => ....0 => 'zero', or _ => 'other' for the fallback.Holds statements.Holds statements in { }. Goes inside <match>match.
<let name="day" value="'Tuesday'" />
<match $day>
<case is="'Saturday', 'Sunday'"><echo>Weekend</echo></case>
<default><echo>Weekday</echo></default>
</match>$day = 'Tuesday'
match $day {
'Saturday', 'Sunday' => echo 'Weekend'
_ => echo 'Weekday'
}<do>$name = value; …;. A call that names a statement, such as locale(set: 'fr'), runs that statement, as the same line does in a .kscript file.$total = 10 or a standalone call such as @save($total).Its text is assignments separated by ;.
<let name="total" value="10" />
<do>$total += 5; $total *= 2</do>
<echo>$total</echo>$total = 10
$total += 5
$total *= 2
echo $total<echo>echo{ expr } inserts a value; $name and $name->method() work directly.Holds text with { } values.
| AttributeOption | Value | Description |
|---|---|---|
value | expression | Print this value instead of the text. |
format | text| | How to print: text (the default), json (indented and, in a terminal, coloured), or markdown (with KScript.Terminal). A map or nested list on its own is printed as json. |
newline | true or false | no leaves the cursor at the end of the line. |
<let name="name" value="'Joan'" />
<let name="items" value="['tea', 'cake']" />
<echo>Hello, $name! You have { $items->count() } items.</echo>$name = 'Joan'
$items = ['tea', 'cake']
echo "Hello, { $name }! You have { $items->count() } items."<elif>elifelif $ready { ... }, or elif $ready => @start() for one statement.Holds statements.Holds statements in { }. Follows <if>if or <elif>elif.
| Attribute | Value | Description |
|---|---|---|
test required | expression | The condition, for example $n < 10 and $name != '' (in an XML attribute, $n lt 10 and $name ne ''). |
<let name="n" value="7" />
<if $n lt 5>
<echo>small</echo>
</if>
<elif $n lt 10>
<echo>medium</echo>
</elif>
<else>
<echo>large</echo>
</else>$n = 7
if $n < 5 {
echo 'small'
} elif $n < 10 {
echo 'medium'
} else {
echo 'large'
}<else>elseelse { ... } after an if, elif, or for block, or else => @stop() for one statement.Holds statements.Holds statements in { }. Follows <if>if or <elif>elif or <for>for item in list.
<let name="names" value="[]" />
<for each="name" in="$names">
<echo>$name</echo>
</for>
<else>
<echo>Nobody here</echo>
</else>$names = []
for name in $names {
echo $name
} else {
echo 'Nobody here'
}<enum>enumSize.small is 'small', and a parameter typed with it (params="size: Size") only takes those values, which calls can write bare: @pack(large).enum Size { small, large }.Self-closing.A statement on its own.
| Attribute | Value | Description |
|---|---|---|
name required | a new variable's name | The enum's name, used as a parameter type and as Name (Size.small). |
values required | a list of names: [a, b] | The values, as a list: [small, medium, large] (in XML, small, medium, large). |
description | a string | What the enum is for, shown on hover. |
<enum name="Size" values="small, medium, large" />
<fn name="pack" params="size: Size" value="'Packing ' + $size" />
<echo>{ @pack(large) }</echo>enum Size { small, medium, large }
fn pack(size: Size) => 'Packing ' + $size
echo @pack(large)<error>errorthrow NotFound(id: 42) raises one, catch NotFound as e catches it and the error types that extend it, and $e.id reads its fields. A status (its own or a parent's) is the HTTP status a KScript.Http route answers with when nothing catches it.error InvalidAge extends Validation { age: int }, then throw InvalidAge(age: $age).Holds statements.Holds statements in { }.
| Attribute | Value | Description |
|---|---|---|
name required | a new variable's name | The error type's name, starting with a capital letter: NotFound, PaymentFailed. |
extends | an error type | The error type it is a kind of, such as Validation or another <error>. catch of that type catches this one too, and it inherits its fields, message and status. Defaults to Error.The error type it is a kind of, such as Validation or another error. catch of that type catches this one too, and it inherits its fields, message and status. Defaults to Error. |
message | a string with { } | The message, with the fields as variables: No {$kind} with id {$id}. throw NotFound(id: 1, message: '...') gives one instead. |
status | a string | The HTTP status a KScript.Http route answers with, such as 404. Inherited from the type it extends. |
fields | fields | The fields on one line, like fn params: id: int, kind: string = 'item'. |
description | a string | What the error means, shown on hover. |
| Option | Value | Description |
|---|---|---|
message | a string with { } | The message, with the fields as variables: No {$kind} with id {$id}. throw NotFound(id: 1, message: '...') gives one instead. |
status | a string | The HTTP status a KScript.Http route answers with, such as 404. Inherited from the type it extends. |
description | a string | What the error means, shown on hover. |
<error name="PersonNotFound" extends="NotFound" fields="id: int" message="No person with id {$id}" />
<try>
<throw value="PersonNotFound(id: 42)" />
<catch type="NotFound" as="e">
<echo>{ $e.message } ({ $e.status })</echo>
</catch>
</try>error PersonNotFound(fields: id: int, message: "No person with id {$id}") extends NotFound
try {
throw PersonNotFound(id: 42)
} catch NotFound as e {
echo "{ $e.message } ({ $e.status })"
}<exit>exitexit 3 to set the process exit status or exit for status zero.Self-closing.A statement on its own.
| Attribute | Value | Description |
|---|---|---|
code | expression | The exit code. Defaults to 0. |
<exit code="1" />exit 1<extend>extendextend date { fn api_date() => $this->format('yyyy-MM-dd') } makes @today()->api_date() work. Scripts that import the file get the methods too, and in a project every file in the extensions folder applies everywhere.Adds methods to a type: a built-in one such as date, string or list, a package's (file, response), or a type. Each fn inside becomes a method, with the value it is called on as $this: extend date { fn api_date() => $this->format('yyyy-MM-dd') } makes @today()->api_date() work. Scripts that import the file get the methods too, and in a project every file in the extensions folder applies everywhere.extend string { fn example() => $this }.Holds statements.Holds statements in { }.
| Attribute | Value | Description |
|---|---|---|
type required | a string | The type to add methods to: date, string, number, bool, list, map, fn, email, handle, uuid, regex, password, a package's type such as file or response, or a <type>'s name.The type to add methods to: date, string, number, bool, list, map, fn, email, handle, uuid, regex, password, a package's type such as file or response, or a type's name. |
description | a string | What the methods are for, shown on hover. |
<extend type="date">
<fn name="is_payday" value="$this.day == 25" />
</extend>
<echo>{ @today()->is_payday() }</echo>extend date {
fn is_payday() => $this.day == 25
}
echo @today()->is_payday()<field>name: typestars: int from stargazers_count.One field of a type, error, model or job: in a .kscript file, one line of the block, stars: int from stargazers_count.name: string or due?: date.Self-closing.A statement on its own. Goes inside <type>type or <error>error or <model>model or <job>job or <event>event or <construct>construct.
| Attribute | Value | Description |
|---|---|---|
name required | a string | The field's name. End it with ? to make it optional. |
type | string | int | float | number | bool | list | set | map | fn | date | markdown | latex | formatted_file | document | email | password | handle | uuid | regex | url | domain | ip | cidr | mac | port | slug | slash_path | file_path | semver | mime | hex | base64 | jwt | json | csv | phone | country | currency | locale | timezone | duration | date_format | cron | color | iban | card | money | any | The field's type: a built-in such as string or int, an <enum>, another <type>, T[] for a list, T? to allow null. Defaults to any.The field's type: a built-in such as string or int, an enum, another type, T[] for a list, T? to allow null. Defaults to any. |
from | a string | Where to read the value, when it isn't the field's name: stargazers_count, owner.login, items[0].name. |
default | expression | The value when the data has none (makes the field optional). |
optional | true or false | true lets the value be missing or null. |
value | expression | Works the field out from the others (they are $name) instead of reading it: $first + ' ' + $last. |
min | a string | The smallest value allowed: a number, a date, or the length of text or a list. |
max | a string | The largest value allowed: a number, a date, or the length of text or a list. |
pattern | a string | A regular expression the value's text must match. |
one_of | a string | The only values allowed: gb, ie or ['gb', 'ie']. |
not | a string | Values that aren't allowed, such as reserved names. |
description | a string | What the field holds, shown on hover and completion. |
private | true or false | true keeps the field to the type's own methods: other code can't read, set or pass it. In a .kscript file, private count: int. |
<type name="Repo">
<field name="name" type="string" />
<field name="stars" type="int(min: 0)" from="stargazers_count" />
<field name="topics" type="string[]" default="[]" />
</type>
<let name="repo" value="Repo({ name: 'kscript', stargazers_count: 42 })" />
<echo>{ $repo.name } has { $repo.stars } stars and { $repo.topics->count() } topics</echo>type Repo {
name: string
stars: int(min: 0) from stargazers_count
topics: string[] = []
}
$repo = Repo({ name: 'kscript', stargazers_count: 42 })
echo "{ $repo.name } has { $repo.stars } stars and { $repo.topics->count() } topics"<finally>finallyfinally { ... } after the preceding block.Holds statements.Holds statements in { }. Goes inside <try>try.
<try>
<echo>working</echo>
<throw message="Oops" />
<catch as="err"><echo>caught: { $err.message }</echo></catch>
<finally><echo>cleaned up</echo></finally>
</try>try {
echo 'working'
throw "Oops"
} catch err {
echo "caught: { $err.message }"
} finally {
echo 'cleaned up'
}<fn>fn@name(args), or piped: $x |> @name() . Functions can be called before the line that declares them.fn greet(name: string) => "Hi {$name}" or give it a statement body with braces. Call it with @greet('Joan').Holds statements.Holds statements in { }.
| Attribute | Value | Description |
|---|---|---|
name required | a function name | The function's name. |
params | parameters | Parameters, with optional types and defaults: who, greeting = 'Hello' or count: int = 1. |
value | expression | For one-line functions: the result, instead of a body. |
returns | a string | The declared return type. |
signature | a string | Declares a method signature without an implementation. |
optional | a string | The method may be omitted by a type implementing this signature. |
surface | page| | For a component's render: where it draws, when its content doesn't show it. |
private | true or false | Inside a <type> or <model>: true keeps the method to the type's own methods. In a .kscript file, private fn tally().Inside a type or model: true keeps the method to the type's own methods. In a .kscript file, private fn tally(). |
override | true or false | Inside <extend>: true replaces the type's built-in method of the same name. Without it, reusing a built-in method's name is an error.Inside extend: true replaces the type's built-in method of the same name. Without it, reusing a built-in method's name is an error. |
description | a string | What the function does. Shown in hover, and to a model when used as an <llm> tool.What the function does. Shown in hover, and to a model when used as an llm tool. |
<fn name="greet" params="who: string, greeting = 'Hello'">
<return value="$greeting + ', ' + $who + '!'" />
</fn>
<echo>@greet('World')</echo>fn greet(who: string, greeting = 'Hello') {
return $greeting + ', ' + $who + '!'
}
echo @greet('World')<for>for item in list$loop holds index, first, last and count.for item in $items { ... }.Holds statements.Holds statements in { }. A loop: <break /> and <continue /> work inside.A loop: break and continue work inside.
| Attribute | Value | Description |
|---|---|---|
each required | new variable names | The loop variable, or key, value for a map. |
in required | expression | What to loop over: a list, a map, a range, a number (0 up to it) or text (its characters). |
at | a new variable's name | A variable for the position, from 0. |
<let name="people" value="[{ name: 'Joan' }, { name: 'Sam' }]" />
<for each="p" in="$people">
<echo>{$p.name}</echo>
</for>
<for each="i" in="0..10"><echo>$i</echo></for>
<let name="settings" value="{ host: 'localhost', port: 8080 }" />
<for each="key, value" in="$settings"><echo>$key = $value</echo></for>$people = [{ name: 'Joan' }, { name: 'Sam' }]
for p in $people {
echo $p.name
}
for i in 0..10 {
echo $i
}
$settings = { host: 'localhost', port: 8080 }
for key, value in $settings {
echo "{ $key } = { $value }"
}<guard>guardguard $ready else { return }. The failure block leaves with return, throw, break, continue or exit.Holds statements.Holds statements in { }.
| Attribute | Value | Description |
|---|---|---|
test required | expression | The condition, for example $n < 10 and $name != '' (in an XML attribute, $n lt 10 and $name ne ''). |
<fn name="half" params="n: number">
<guard test="$n ge 0">
<return value="0" />
</guard>
<return value="$n / 2" />
</fn>
<echo>{ @half(10) } { @half(-4) }</echo>fn half(n: number) {
guard $n >= 0 else {
return 0
}
return $n / 2
}
echo "{ @half(10) } { @half(-4) }"<if>ifif $ready { ... }, or if $ready => @start() for one statement on the same line, followed by optional elif condition { ... } and else { ... } branches.Holds statements.Holds statements in { }.
| Attribute | Value | Description |
|---|---|---|
test required | expression | The condition, for example $n < 10 and $name != '' (in an XML attribute, $n lt 10 and $name ne ''). |
<let name="score" value="80" />
<if $score ge 90>
<echo>A</echo>
</if>
<elif $score ge 75>
<echo>B</echo>
</elif>
<else>
<echo>C</echo>
</else>$score = 80
if $score >= 90 {
echo 'A'
} elif $score >= 75 {
echo 'B'
} else {
echo 'C'
}<import>importpackage="KScript.Terminal"), or the top-level <fn> functions and <let const> values of another script (path). Goes at the top of the script.Imports a package (package="KScript.Terminal"), or the top-level fn functions and <let const> values of another script (path). Goes at the top of the script.import KScript.IO, or another script with import "./helpers.kscript".Self-closing.A statement on its own.
| Attribute | Value | Description |
|---|---|---|
package | a string | A package such as KScript.Terminal, KScript.Math, KScript.IO or KScript.Net. |
path | a file path | A script to import, relative to this file. |
as | a new variable's name | Use the import under a prefix: @math.sqrt(2), str.slugify(). |
names | a list of functions: [a, b] | Import only these names from a script, callable directly: @slugify(). |
<import package="KScript.Terminal" />
<import package="KScript.Math" as="math" />
<import path="lib/strings.ks.xml" as="str" />import KScript.Terminal
import KScript.Math as math
import "lib/strings.ks.xml" as str<item>itemkey it is a map entry, without it a list item. Its text is the value (numbers become numbers); nested items make a list or map.An entry of collection. With key it is a map entry, without it a list item. Its text is the value (numbers become numbers); nested items make a list or map.Holds text with { } values. Goes inside <collection>collection or <item>item.
| AttributeOption | Value | Description |
|---|---|---|
key | a string | The key in the enclosing map. |
value | expression | The value as an expression, instead of text. |
<collection name="order">
<item key="id">42</item>
<item key="lines">
<item>Tea</item>
<item>Cake</item>
</item>
</collection>
<echo>{ $order.id }: { $order.lines }</echo>collection(name: order) {
item(key: 'id') "42"
item(key: 'lines') {
item "Tea"
item "Cake"
}
}
echo "{ $order.id }: { $order.lines }"<kscript>a .kscript fileHolds statements.Holds statements in { }. Scripts only.
<kscript>
<echo>Hello!</echo>
</kscript>echo 'Hello!'<let>$name = valuevalue, or in the element text for longer values. Without name, the text is assignment statements such as $x = 3.$total = 10 or a standalone call such as @save($total).Its text is one expression.
| Attribute | Value | Description |
|---|---|---|
name | a new variable's name | The variable to declare. |
value | expression | The initial value. Can be written as the element's text instead. |
type | string | int | float | number | bool | list | set | map | fn | date | markdown | latex | formatted_file | document | email | password | handle | uuid | regex | url | domain | ip | cidr | mac | port | slug | slash_path | file_path | semver | mime | hex | base64 | jwt | json | csv | phone | country | currency | locale | timezone | duration | date_format | cron | color | iban | card | money | any | Convert the value to this type, or fail early: a built-in such as int, an <enum>, a <type>, T[] for a list, T? to allow null.Convert the value to this type, or fail early: a built-in such as int, an enum, a type, T[] for a list, T? to allow null. |
const | true or false | true makes a later <set> an error.true makes a later $name += value an error. |
<let name="count" value="0" />
<let name="people">[{ name: 'Joan', age: 82 }]</let>
<let>$x = 3</let>$count = 0
$people = [{ name: 'Joan', age: 82 }]
$x = 3<locale>localeset, picks the best available locale from from (a list of wishes, such as an Accept-Language header).Self-closing.A statement on its own.
| AttributeOption | Value | Description |
|---|---|---|
set | a string with { } | The locale, such as fr or en-GB. |
from | expression | Wishes in order, as a list or an Accept-Language header: the best available locale is used. |
<locale set="fr" />
<locale from="['fr-CA', 'en']" />locale(set: 'fr')
locale(from: ['fr-CA', 'en'])<log>logHolds text with { } values.
| AttributeOption | Value | Description |
|---|---|---|
level | trace| | How serious it is (default info). |
message | a string with { } | The message, instead of the element's text. |
category | a string with { } | Where it comes from, such as db or payments. |
fields | expression | A map of extra values, such as { order: $order.id, total: $total }. |
<let name="id" value="42" />
<let name="customer" value="{ name: 'Joan' }" />
<log level="warn" category="payments" fields="{ order: $id }">Card declined for {$customer.name}</log>$id = 42
$customer = { name: 'Joan' }
log(level: warn, category: 'payments', fields: { order: $id }) "Card declined for {$customer.name}"<log_provider>log_providerSelf-closing.A statement on its own. Scripts only.
| AttributeOption | Value | Description |
|---|---|---|
type | a string | console, file, memory, or a type from an imported package such as http. Leave it out when using fn. |
fn | a function: @name | A function called with each entry (a map of time, level, category, message, fields, script and line): @alert (in XML, fn="alert"). |
level | trace| | The lowest level this provider writes (default: all that logging lets through). |
format | text| | text or json (console and file). |
path | a string with { } | The file to append to (file). |
roll | never| | daily starts a new file each day: app-2026-11-20.log (file). |
stream | stderr| | Where console entries go (default stderr). |
color | true or false | Colour console entries by level (default: when at a terminal). |
time | a string | The console's time format, such as HH:mm:ss.fff (default HH:mm:ss). Empty leaves the time out. |
url | a string with { } | Where entries are sent (http, from KScript.Net). |
headers | expression | A map of request headers (http). |
batch | expression | How many entries to send at once (http, default 20). |
name | a string | A name for the provider, used in error messages. |
replace | true or false | true removes the providers already set up, including the default console one. |
<log_provider type="file" path="logs/app.log" format="json" level="debug" />
<fn name="alert" params="entry: map"><echo>ALERT: {$entry.message}</echo></fn>
<log_provider fn="alert" level="error" />log_provider(type: 'file', path: 'logs/app.log', format: json, level: debug)
fn alert(entry: map) {
echo "ALERT: {$entry.message}"
}
log_provider(fn: @alert, level: error)<match>match$it is the value.match $n { 0 => 'zero', _ => 'other' }.Holds statements.Holds statements in { }.
| Attribute | Value | Description |
|---|---|---|
value required | expression | The value to compare. |
<let name="choice" value="'other'" />
<match $choice>
<case is="1"><echo>One</echo></case>
<case is="2, 3"><echo>Two or three</echo></case>
<case when="$choice gt 9"><echo>Big</echo></case>
<default><echo>Unknown</echo></default>
</match>$choice = 'other'
match $choice {
1 => echo 'One'
2, 3 => echo 'Two or three'
_ when $choice > 9 => echo 'Big'
_ => echo 'Unknown'
}<normalize>normalize$value; the result is converted to the type again.Cleans up a value before a type's rules check it, such as trimming or lower-casing. The value is $value; the result is converted to the type again.Self-closing.A statement on its own. Goes inside <type>type.
| AttributeOption | Value | Description |
|---|---|---|
value required | expression | The cleaned-up value: $value->trim()->lower(). |
<type name="Slug" with="string" pattern="^[a-z0-9-]+$">
<normalize value="$value->trim()->lower()" />
</type>
<echo>{ Slug(' Hello-World ') }</echo>type Slug with [string] {
pattern: "^[a-z0-9-]+$"
normalize: $value->trim()->lower()
}
echo Slug(' Hello-World ')<return>returnreturn $result to send a value to the caller, or return to return null.Self-closing.A statement on its own. Goes inside <fn>fn.
| Attribute | Value | Description |
|---|---|---|
value | expression | The result. Without it the function returns null. |
<fn name="area" params="w: number, h: number">
<return value="$w * $h" />
</fn>
<echo>{ @area(3, 4) }</echo>fn area(w: number, h: number) {
return $w * $h
}
echo @area(3, 4)<set>$name += valuename, the text is assignment statements.$total = 10 or a standalone call such as @save($total).Its text is one expression.
| Attribute | Value | Description |
|---|---|---|
name | a variable's name | The variable to change. |
value | expression | The new value. Can be written as the element's text instead. |
op | '='| | Update instead of replace: op="+=" value="1". |
type | string | int | float | number | bool | list | set | map | fn | date | markdown | latex | formatted_file | document | email | password | handle | uuid | regex | url | domain | ip | cidr | mac | port | slug | slash_path | file_path | semver | mime | hex | base64 | jwt | json | csv | phone | country | currency | locale | timezone | duration | date_format | cron | color | iban | card | money | any | Convert the value to this type, or fail: a built-in such as int, an <enum>, a <type>, T[] for a list, T? to allow null.Convert the value to this type, or fail: a built-in such as int, an enum, a type, T[] for a list, T? to allow null. |
<let name="total" value="0" />
<let name="count" value="0" />
<set name="total" value="$total + 2.50 * 3" />
<set>$count += 1</set>
<echo>$count item, $total</echo>$total = 0
$count = 0
$total = $total + 2.50 * 3
$count += 1
echo "{ $count } item, { $total }"<slot>slotSelf-closing.A statement on its own.
| AttributeOption | Value | Description |
|---|---|---|
name | a string | A named slot, in a page's layout or component. |
<type name="Panel" extends="Component">
<field name="title" type="string" />
<fn name="render">
<echo>{$title}</echo>
<slot />
</fn>
</type>
<Panel title="Notes">
<echo>Buy milk</echo>
</Panel>type Panel extends Component {
title: string
fn render() {
echo .title
slot
}
}
Panel(title: 'Notes') {
echo 'Buy milk'
}<spawn>spawnSelf-closing.A statement on its own.
| AttributeOption | Value | Description |
|---|---|---|
fn required | a function: @name | The function to run: @count_to (in XML, fn="count_to"). |
args | expressions, comma separated | Arguments, comma separated. |
<fn name="count_to" params="n: int"><echo>Counted to { @range(1, $n + 1)->last() }</echo></fn>
<spawn fn="count_to" args="1000" />
<echo>Started counting</echo>fn count_to(n: int) {
echo "Counted to { @range(1, $n + 1)->last() }"
}
spawn(fn: @count_to, args: 1000)
echo 'Started counting'<throw>throwvalue throws an error made from a type (NotFound(id: 42)) or a caught one again; a bare <throw /> inside a <catch> rethrows the error it is handling.Raises an error, which a catch err can handle. Without a try, the script stops with the message. value throws an error made from a type (NotFound(id: 42)) or a caught one again; a bare throw inside a catch err rethrows the error it is handling.throw Validation "Invalid age" for a message, or throw Error(message: 'Oops', value: $age, cause: $original) for named fields. To throw a payload map, write throw $payload. Inside a catch, bare throw rethrows the current error. Use throw if condition { ... } for a conditional throw.Holds text with { } values.
| Attribute | Value | Description |
|---|---|---|
type | an error type | The error type, such as Validation or an <error>. Defaults to Error.The error type, such as Validation or an error. Defaults to Error. |
message | a string with { } | What went wrong. Can be written as the element's text instead. |
value | expression | The error to throw: NotFound(id: 42), Validation('Too short'), or a caught $err. |
cause | expression | The error that led to this one, such as the $err of the <catch> around it. It is $e.cause on the new error.The error that led to this one, such as the $err of the catch err around it. It is $e.cause on the new error. |
<let name="age" value="-1" />
<try>
<throw type="Validation" message="Age must be positive, got {$age}" />
<catch as="err"><echo>{ $err.type }: { $err.message }</echo></catch>
</try>$age = -1
try {
throw Validation "Age must be positive, got {$age}"
} catch err {
echo "{ $err.type }: { $err.message }"
}<translations>translationsSelf-closing.A statement on its own.
| AttributeOption | Value | Description |
|---|---|---|
folder | a string with { } | The folder of translation files (default locales): locales/en.json, locales/fr.yaml, or locales/fr/*.json. |
default | a string with { } | The locale used when a translation is missing (default en). |
<translations folder="lang" default="en-GB" />translations(folder: 'lang', default: 'en-GB')<try>trytry { ... } catch Validation as err { ... }.Holds statements.Holds statements in { }.
<let name="text" value="'not json'" />
<try>
<let name="data" value="$text->convert(from: json)" />
<catch as="err" when="$err.type eq 'Json'">
<echo>That isn't JSON: {$err.message}</echo>
</catch>
<finally><echo>done</echo></finally>
</try>$text = 'not json'
try {
$data = $text->convert(from: json)
} catch err when $err.type == 'Json' {
echo "That isn't JSON: {$err.message}"
} finally {
echo 'done'
}<type>type->convert(from: json, as: Repo), Repo($data), <let type="Repo"> and repo: Repo parameters check data against it and turn it into a record: a map whose fields the editor knows. Every problem is reported at once, with its JSON path.type Person { name: string } for a record, or type Key with [string] { min: 3 } for a refinement.Holds statements.Holds statements in { }.
| Attribute | Value | For | Description |
|---|---|---|---|
name required | a new variable's name | any type | The type's name, used as type="Repo", as: Repo and Repo. |
fields | fields | types with fields | A short type's fields on one line, like fn params: login: string, id: int, avatar_url?: string. Bigger types list their fields one per line instead (<field> elements).A short type's fields on one line, like fn params: login: string, id: int, avatar_url?: string. Bigger types list their fields one per line instead (name: type elements). |
path | a file path | types with fields | A JSON file holding a sample of the data. Its keys become fields; <field> elements and fields replace the ones they name.A JSON file holding a sample of the data. Its keys become fields; name: type elements and fields replace the ones they name. |
extra | drop| | types with fields | Keys in the data that the type doesn't list: drop them (the default), keep them, or make them an error. Written in brackets after the type's name: type Repo(extra: error) { name: string }. |
extends | a string | types with fields | A type whose required method signatures this type implements. |
with | string | int | float | number | bool | list | set | map | fn | date | markdown | latex | formatted_file | document | email | password | handle | uuid | regex | url | domain | ip | cidr | mac | port | slug | slash_path | file_path | semver | mime | hex | base64 | jwt | json | csv | phone | country | currency | locale | timezone | duration | date_format | cron | color | iban | card | money | any | any type | Other types this one is made from. Types with fields are joined: with="User, Auditable" has all their fields and rules, and fits wherever they do. One built-in type, such as with="int" or with="handle", makes a type with rules instead of fields: min, max, pattern, one_of, not, <validate> and <normalize>.Other types this one is made from. Types with fields are joined: with="User, Auditable" has all their fields and rules, and fits wherever they do. One built-in type, such as with="int" or with="handle", makes a type with rules instead of fields: min, max, pattern, one_of, not, validate and normalize. |
min | a number, a date, a length or a count | types made from one built-in type | The smallest value allowed, read by the base type: a number for int and float, a date for date, a length for text (a handle's name without its @), and a count for lists. type Age with [int] { min: 0 }. |
max | a number, a date, a length or a count | types made from one built-in type | The largest value allowed, read by the base type: a number for int and float, a date for date, a length for text, and a count for lists. type Age with [int] { max: 150 }. |
pattern | a regular expression: /^[a-z]+$/ | any type | A regular expression the value's text must match: /^[a-z0-9-]+$/. On a type made from a number, the text is its digits, so a pattern of letters is an error. On a type with fields, its named groups fill the fields of the same name, so the type can be made from text. |
parse | expression | types with fields | On a type with fields: an expression that turns text into a map of the fields, with the text as $value and the pattern's match (if any) as $match. |
one_of | a list of values of the base type: [a, b] | types made from one built-in type | The only values allowed, each a value of the base type: [gb, ie] for a country, [1, 2, 3] for an int. Compared after converting and normalising. |
not | a list of values of the base type: [a, b] | types made from one built-in type | Values that aren't allowed, each a value of the base type, such as reserved names: [@admin, @root] for a handle. |
description | a string | any type | What the type is, shown on hover. |
| Option | Value | For | Description |
|---|---|---|---|
path | a file path | types with fields | A JSON file holding a sample of the data. Its keys become fields; <field> elements and fields replace the ones they name.A JSON file holding a sample of the data. Its keys become fields; name: type elements and fields replace the ones they name. |
extra | drop| | types with fields | Keys in the data that the type doesn't list: drop them (the default), keep them, or make them an error. Written in brackets after the type's name: type Repo(extra: error) { name: string }. |
min | a number, a date, a length or a count | types made from one built-in type | The smallest value allowed, read by the base type: a number for int and float, a date for date, a length for text (a handle's name without its @), and a count for lists. type Age with [int] { min: 0 }. |
max | a number, a date, a length or a count | types made from one built-in type | The largest value allowed, read by the base type: a number for int and float, a date for date, a length for text, and a count for lists. type Age with [int] { max: 150 }. |
pattern | a regular expression: /^[a-z]+$/ | any type | A regular expression the value's text must match: /^[a-z0-9-]+$/. On a type made from a number, the text is its digits, so a pattern of letters is an error. On a type with fields, its named groups fill the fields of the same name, so the type can be made from text. |
parse | expression | types with fields | On a type with fields: an expression that turns text into a map of the fields, with the text as $value and the pattern's match (if any) as $match. |
one_of | a list of values of the base type: [a, b] | types made from one built-in type | The only values allowed, each a value of the base type: [gb, ie] for a country, [1, 2, 3] for an int. Compared after converting and normalising. |
not | a list of values of the base type: [a, b] | types made from one built-in type | Values that aren't allowed, each a value of the base type, such as reserved names: [@admin, @root] for a handle. |
description | a string | any type | What the type is, shown on hover. |
<type name="User">
<field name="login" type="string" />
<field name="id" type="int" />
</type>
<type name="Repo">
<field name="name" type="string" />
<field name="stars" type="int" from="stargazers_count" />
<field name="owner" type="User" />
</type>
<let name="repo" value="Repo({ name: 'kscript', stargazers_count: 12, owner: { login: 'kyle', id: 1 } })" />
<echo>$repo.name has $repo.stars stars</echo>type User {
login: string
id: int
}
type Repo {
name: string
stars: int from stargazers_count
owner: User
}
$repo = Repo({ name: 'kscript', stargazers_count: 12, owner: { login: 'kyle', id: 1 } })
echo "{ $repo.name } has { $repo.stars } stars"<validate>validate$value. In a type with fields, each field is a variable ($end > $start). Every rule that fails is reported, with its message.A rule a type checks: the test must be true. In a type made from one other type, the value is $value. In a type with fields, each field is a variable ($end > $start). Every rule that fails is reported, with its message.Self-closing.A statement on its own. Goes inside <type>type or <model>model.
| AttributeOption | Value | Description |
|---|---|---|
test required | expression | What must be true: $value % 5 == 0, $end > $start. |
message | a string | What to say when it isn't, such as must end after it starts. |
<type name="Even" with="int">
<validate test="$value % 2 == 0" message="must be even" />
</type>
<echo>{ Even(4) }</echo>type Even with [int] {
validate: $value % 2 == 0, 'must be even'
}
echo Even(4)<wait>waitSelf-closing.A statement on its own.
| AttributeOption | Value | Description |
|---|---|---|
duration required | expression | How long to wait: 500ms, 2s, 1m30s. A plain number is seconds. |
<wait duration="1.5s" />wait(duration: 1.5s)<while>whiletest="true" loops until <break/>.Loops while the test is true. test="true" loops until break.while $remaining > 0 { ... }.Holds statements.Holds statements in { }. A loop: <break /> and <continue /> work inside.A loop: break and continue work inside.
| Attribute | Value | Description |
|---|---|---|
test required | expression | The condition, for example $n < 10 and $name != '' (in an XML attribute, $n lt 10 and $name ne ''). |
<let name="n" value="0" />
<while $n lt 3>
<set name="n" value="$n + 1" />
</while>
<echo>$n</echo>$n = 0
while $n < 3 {
$n = $n + 1
}
echo $nCommands are called with @, in any expression: @name(arguments).
@char_of(code: number) → string| Parameter | Takes |
|---|---|
code required | number |
<echo>{ @char_of(75) + @char_of(83) }</echo>echo @char_of(75) + @char_of(83)@decrypt(text) → any<echo>{ @decrypt(@encrypt('hello')) }</echo>echo @decrypt(@encrypt('hello'))@encrypt(value) → string<let name="secret" value="@encrypt({ token: 'abc' })" />
<echo>{ @decrypt($secret).token }</echo>$secret = @encrypt({ token: 'abc' })
echo @decrypt($secret).token@env(name, default?) → stringArguments can be named: @env(…, default: …).
<echo>{ @env('KSCRIPT_DOCS_EXAMPLE', 'not set') }</echo>echo @env('KSCRIPT_DOCS_EXAMPLE', 'not set')@escape_regex(text: string) → string| Parameter | Takes |
|---|---|
text required | string |
<echo>{ 'Price: $5 (each)'->matches(@escape_regex('$5 (')) }</echo>echo 'Price: $5 (each)'->matches(@escape_regex('$5 ('))@format_bytes(bytes: number, binary?: bool, locale?) → string| Parameter | Takes |
|---|---|
bytes required | number |
binary optional | a flag: binary or not binary |
locale optional | any value |
Arguments can be named: @format_bytes(…, binary: …, locale: …).
<echo>{ @format_bytes(1400000) }</echo>echo @format_bytes(1400000)@format_currency(amount, currency, locale?) → stringArguments can be named: @format_currency(…, currency: …, locale: …).
<echo>{ @format_currency(19.99, currency: 'EUR', locale: 'fr') }</echo>echo @format_currency(19.99, currency: 'EUR', locale: 'fr')@format_date(date: date, style?, locale?) → string| Parameter | Takes |
|---|---|
date required | date |
style optional | any value |
locale optional | any value |
Arguments can be named: @format_date(…, style: …, locale: …).
<echo>{ @format_date('2026-11-19'->to_date(), style: 'long') }</echo>echo @format_date('2026-11-19'->to_date(), style: 'long')@format_duration(duration: duration, locale?) → string| Parameter | Takes |
|---|---|
duration required | duration |
locale optional | any value |
Arguments can be named: @format_duration(…, locale: …).
<echo>{ @format_duration(1h30m) }</echo>echo @format_duration(1h30m)@format_list(items: list, style?: and|or, locale?) → string| Parameter | Takes |
|---|---|
items required | list |
style optional | one of these words: and|or |
locale optional | any value |
Arguments can be named: @format_list(…, style: …, locale: …).
<echo>{ @format_list(['tea', 'coffee', 'milk']) }</echo>echo @format_list(['tea', 'coffee', 'milk'])@format_number(number, decimals?, locale?) → stringArguments can be named: @format_number(…, decimals: …, locale: …).
<echo>{ @format_number(1234567.891, decimals: 2) }</echo>echo @format_number(1234567.891, decimals: 2)@format_ordinal(number: number, locale?) → string| Parameter | Takes |
|---|---|
number required | number |
locale optional | any value |
Arguments can be named: @format_ordinal(…, locale: …).
<echo>{ @format_ordinal(23) }</echo>echo @format_ordinal(23)@format_percent(fraction, decimals?, locale?) → stringArguments can be named: @format_percent(…, decimals: …, locale: …).
<echo>{ @format_percent(0.256, decimals: 1) }</echo>echo @format_percent(0.256, decimals: 1)@format_relative(date: date, from?: date, locale?) → stringArguments can be named: @format_relative(…, from: …, locale: …).
<echo>{ @format_relative('2026-11-19 09:00'->to_date(), from: '2026-11-19 12:00'->to_date()) }</echo>echo @format_relative('2026-11-19 09:00'->to_date(), from: '2026-11-19 12:00'->to_date())@has_t(key, locale?) → boolArguments can be named: @has_t(…, locale: …).
<echo>{ @has_t('cart.items') }</echo>echo @has_t('cart.items')@inject(model?, from?, can?) → anyArguments can be named: @inject(…, from: …, can: …).
<import package="KScript.Data" /><model name="Post"><field name="title" type="string" /></model><type name="PostCard"><construct><field name="post" type="Post" default="@inject()" /></construct></type>import KScript.Data
model Post {
title: string
}
type PostCard {
construct({ post: Post = @inject() })
}@locale() → string<echo>{ @locale() }</echo>echo @locale()@locales() → list<echo>{ @locales() }</echo>echo @locales()@locale_path(path, locale?) → stringArguments can be named: @locale_path(…, locale: …).
<a href="{ @locale_path($request.path, 'fr') }">Français</a>a(href: @locale_path($request.path, 'fr')) "Français"@max(values...) → any<echo>{ @max(4, 9, 2) }</echo>echo @max(4, 9, 2)@min(values...) → any<echo>{ @min(4, 9, 2) }</echo>echo @min(4, 9, 2)@now() → date<echo>{ @now()->format('d MMMM yyyy') }</echo>echo @now()->format('d MMMM yyyy')@parse_env(text) → map<echo>{ @parse_env('PORT=8080').PORT }</echo>echo @parse_env('PORT=8080').PORT@plural(count, locale?) → stringArguments can be named: @plural(…, locale: …).
<echo>{ [0, 1, 5]->map(fn(n) => @plural($n)) }</echo>echo [0, 1, 5]->map(fn(n) => @plural($n))@range(start, end?, step?) → listArguments can be named: @range(…, end: …, step: …).
<echo>{ @range(1, 10, step: 3) }</echo>echo @range(1, 10, step: 3)@retry(times: number, work: fn, backoff?: duration, when?: fn) → any@retry(3, fn() => @api($url), backoff: 1s, when: fn(err) => $err.type == 'Timeout'). Work is given the attempt, 1 for the first.Arguments can be named: @retry(…, work: …, backoff: …).
<fn name="flaky" params="attempt: int">
<if test="$attempt lt 3"><throw message="busy" type="Timeout" /></if>
<return value="'worked on try ' + $attempt" />
</fn>
<echo>{ @retry(3, @flaky) }</echo>fn flaky(attempt: int) {
if $attempt < 3 {
throw Timeout "busy"
}
return 'worked on try ' + $attempt
}
echo @retry(3, @flaky)@secure_equals(a: string, b: string) → boolArguments can be named: @secure_equals(…, b: …).
<echo>{ @secure_equals('payload'->hmac('secret'), 'payload'->hmac('secret')) }</echo>echo @secure_equals('payload'->hmac('secret'), 'payload'->hmac('secret'))@set_exchange_rate(from: currency, to: currency, rate: number)Arguments can be named: @set_exchange_rate(…, to: …, rate: …).
<echo>{ @set_exchange_rate(from: 'EUR', to: 'GBP', rate: 0.80) }</echo>echo @set_exchange_rate(from: 'EUR', to: 'GBP', rate: 0.80)@slugify(text: string) → slug| Parameter | Takes |
|---|---|
text required | string |
<echo>{ @slugify('Crème Brûlée recipes!') }</echo>echo @slugify('Crème Brûlée recipes!')@t(key, values?, locale?) → stringArguments can be named: @t(…, values: …, locale: …).
<let name="items" value="[1, 2, 3]" />
<echo>{ @t('cart.items', { count: $items->count() }) }</echo>$items = [1, 2, 3]
echo @t('cart.items', { count: $items->count() })@today() → date<echo>{ @today()->format('yyyy-MM-dd HH:mm') }</echo>echo @today()->format('yyyy-MM-dd HH:mm')@uuid(v?: int, name?: string, namespace?: string) → uuidArguments can be named: @uuid(…, name: …, namespace: …).
<echo>{ @uuid().version }</echo>echo @uuid().versionOn string values: ->upper(), ->lower(), ->trim(), ->count(), ->count_of(), ->is_empty(), ->is_blank(), ->contains(), ->starts_with(), ->ends_with(), ->strip(), ->normalize_unicode(), ->replace(), ->split(), ->lines(), ->chars(), ->index_of(), ->repeat(), ->reverse(), ->first(), ->last(), ->slice(), ->truncate(), ->pad(), ->capitalize(), ->title(), ->escape(), ->url_encode(), ->url_decode(), ->to_number(), ->to_int(), ->to_bool(), ->to_date(), ->to_base64(), ->from_base64(), ->md5(), ->sha256(), ->sha1(), ->sha512(), ->hmac(), ->case(), ->before(), ->after(), ->squish(), ->words(), ->wrap(), ->mask(), ->is_numeric(), ->matches(), ->find_all(), ->numbers(), ->blocks(), ->grid(), ->shapes()
On number values: ->round(), ->floor(), ->ceil(), ->abs(), ->min(), ->max(), ->bits(), ->clamp(), ->to_date(), ->to_number(), ->to_int(), ->format(), ->increment(), ->decrement(), ->is_even(), ->is_odd(), ->times()
On list values: ->count(), ->count_of(), ->is_empty(), ->first(), ->last(), ->at(), ->filter(), ->reject(), ->map(), ->flat_map(), ->partition(), ->pluck(), ->find(), ->any(), ->all(), ->each(), ->reduce(), ->sort(), ->max(), ->min(), ->sum(), ->average(), ->group_by(), ->reverse(), ->join(), ->contains(), ->index_of(), ->slice(), ->take(), ->skip(), ->unique(), ->push(), ->prepend(), ->insert(), ->pop(), ->remove(), ->remove_at(), ->flatten(), ->chunk(), ->zip(), ->to_map(), ->difference(), ->intersect(), ->union(), ->count_by(), ->common(), ->take_while(), ->skip_while(), ->window(), ->split(), ->replace_at(), ->only(), ->without(), ->numbers(), ->product(), ->combinations(), ->permutations(), ->scan(), ->cells(), ->positions_of(), ->rotate(), ->shapes()
On map values: ->keys(), ->values(), ->entries(), ->has(), ->get(), ->set(), ->remove(), ->merge(), ->pick(), ->omit(), ->deep_merge(), ->count(), ->is_empty(), ->map(), ->filter(), ->reject(), ->any(), ->all(), ->find(), ->reduce(), ->map_keys(), ->sort()
On date values: ->format(), ->add(), ->subtract(), ->date(), ->iso(), ->timestamp(), ->start_of(), ->end_of(), ->since(), ->is_same()
On any values: ->convert(), ->from(), ->to(), ->type(), ->to_string(), ->is_null(), ->or(), ->is_a()
On type values: ->check(), ->is(), ->schema()
On config values: ->get(), ->has(), ->require(), ->environment(), ->all(), ->sources(), ->reload()
On logger values: ->trace(), ->debug(), ->info(), ->warn(), ->error(), ->fatal(), ->log(), ->with(), ->named(), ->is_enabled(), ->entries(), ->flush()
On error values: ->is(), ->chain()
On password values: ->hash(), ->verify(), ->needs_rehash(), ->strength(), ->is_strong(), ->reveal()
On regex values: ->test(), ->match(), ->match_all(), ->replace(), ->split()
On url values: ->with(), ->without(), ->join()
On domain values: ->is_subdomain_of(), ->ascii()
On cidr values: ->contains()
On slash_path values: ->join(), ->is_within()
On semver values: ->compare(), ->satisfies(), ->bump()
On semver[] values: ->latest()
On hex values: ->to_number()
On base64 values: ->decode()
On csv values: ->cells(), ->save()
On currency values: ->format()
On locale values: ->format()
On timezone values: ->offset(), ->now(), ->convert(), ->is_dst()
On duration values: ->iso(), ->after(), ->before(), ->add(), ->subtract()
On date_format values: ->format(), ->parse()
On cron values: ->next(), ->next_times()
On color values: ->rgb(), ->hex(), ->css(), ->mix(), ->lighten(), ->darken(), ->contrast_ratio()
On iban values: ->formatted()
On card values: ->reveal()
On money values: ->add(), ->subtract(), ->format(), ->split(), ->allocate()
On set values: ->count(), ->is_empty(), ->contains(), ->add(), ->remove(), ->union(), ->intersect(), ->difference(), ->is_subset(), ->overlaps(), ->all(), ->any(), ->average(), ->count_by(), ->each(), ->filter(), ->find(), ->group_by(), ->join(), ->map(), ->max(), ->min(), ->reduce(), ->reject(), ->sort(), ->sum()
On formatted_file values: ->find(), ->replace(), ->insert(), ->save()
| Variable | Type | Description |
|---|---|---|
$args | list | The command line arguments after the script path. |
$config | config | The project's settings: the "config" section of kscript.json, with kscript.<env>.json and config.kscript laid over it: $config.database.host. |
$env | map | Environment variables: $env.HOME, $env['PATH']. |
$event | map | The event a handler runs for, in on-* attributes and <on> blocks: $event.value, $event.key, $event.data... Its fields depend on the handler. |
$log | logger | The script's logger: $log->info('Saved', { id: $id }), $log->named('db')->debug(...). Providers and levels come from $config.logging. |
$os | map | The computer: $os.name (windows, macos or linux), $os.user, $os.machine, $os.home, $os.temp, $os.separator, $os.newline. |
$script | map | This script: $script.path, $script.dir, $script.name. |