KScript docs
EN

Types and validation

Arguments where a type is used

A type can take arguments where it is used. They are the same rules a refinement type has, and they last only for that use:

<let name="work" type="email(domains: ['example.com'])" value="joan@example.com" />
<let name="id" type="uuid(v: 4)" value="3f2a8c1e-9b7d-4c2a-8e1f-0a9b8c7d6e5f" />
<let name="pin" type="password(min: 4, max: 8, common: false)" value="'1234'" />
<let name="title" type="string(min: 1, max: 80)" value="'Hello'" />
<echo>{ $work } { $id } { $pin } { $title }</echo>
$work: email(domains: ['example.com']) = joan@example.com
$id: uuid(v: 4) = 3f2a8c1e-9b7d-4c2a-8e1f-0a9b8c7d6e5f
$pin: password(min: 4, max: 8, common: false) = '1234'
$title: string(min: 1, max: 80) = 'Hello'
echo "{ $work } { $id } { $pin } { $title }"
Type Arguments
uuid v (a version, or a list of versions)
email domains (the domains allowed)
password min, max, upper, lower, digit, symbol, common, not, score, algorithm
Any type min, max, pattern, one_of, not

Project defaults in kscript.json

"types" in kscript.json sets arguments for every use of a built-in type in the project. Arguments written where the type is used win:

JSON
{
  "types": {
    "uuid": { "v": 4 },
    "password": { "min": 12, "symbol": true, "algorithm": "argon2id" },
    "email": { "domains": ["example.com"] }
  }
}