KScript Dokumentation
DE

Sprache

Automatisch aus dem Englischen übersetzt; das englische Original ist maßgeblich.

Typen und Validierung

Argumente, wo ein Typ verwendet wird

Ein Typ kann dort, wo er verwendet wird, Argumente annehmen. Dafür gelten dieselben Regeln wie für einen Verfeinerungstyp, und sie gelten nur für diese Verwendung:

<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 }"
Typ Argumente
uuid v (eine Version oder eine Liste von Versionen)
email domains (die erlaubten Domains)
password min, max, upper, lower, digit, symbol, common, not, score, algorithm
Beliebiger Typ min, max, pattern, one_of, not

Projektvorgaben in kscript.json

"types" in kscript.json legt Argumente für jede Verwendung eines eingebauten Typs im Projekt fest. Argumente, die dort geschrieben werden, wo der Typ verwendet wird, haben Vorrang:

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