KScript docs
EN

Built-in types

Every type a field, parameter or variable can be declared as, without importing anything: age: int, email: email, tags: string[]. Add ? to allow null and [] for a list.

Rules go in brackets after the type: string(min: 1, max: 200), int(min: 0), string(pattern: /^[a-z]+$/), string(one_of: [draft, live]), handle(not: [@admin]). Every type takes min, max, pattern, one_of and not; the options column lists what a type takes as well. More in Types and validation.

Values

TypeWhat it holds
stringText. Quoted with ' (as written) or " (with $name and { } filled in).
intA whole number: 42, -7. A number with a fraction isn't an int.
floatA number that may have a fraction: 0.5, 3.14.
numberAny number, whole or not.
booltrue or false.
listA list of values: [1, 2, 3]. T[] is a list of T, such as string[].
mapNames and values: { name: 'Joan', age: 82 }.
fnA function: a lambda fn(x) => $x * 2, or a declared function passed as @name.
dateA date and time: @now(), @today(), '2026-11-19'->to_date().
markdownA Markdown document, from a text block tagged markdown. See Documents.
latexA LaTeX document, from a text block tagged latex. See Documents.
formatted_fileSource code from a text block tagged with a file type such as ps1, with .extension and .text.
documentA document built with KScript.Document, ready to save as PDF, Word, HTML or Markdown.
anyAny value. The type a field or parameter has when none is given.

Native types

Values that are text underneath, checked and tidied when they are made: an email is lower-cased and must have an @, a url must have a scheme and host. Where the type is expected you can write the value without quotes (timeout: 30s, country: GB), and each has fields and methods of its own.

TypeWhat it holdsExampleOptions
base64Base64 text (standard or URL-safe). ->decode() gives the text it holds.aGVsbG8=
cardA payment card number, checked with the Luhn digit. It prints masked apart from the last four digits.'4242 4242 4242 4242'
cidrA block of IP addresses: an address, / and a prefix length, such as 10.0.0.0/8.10.0.0.0/8
colorA colour: #rgb, #rrggbb, #rrggbbaa, rgb(...) or a CSS name. Kept as lowercase #rrggbb (#rrggbbaa with alpha).#ff8800
countryAn ISO 3166 country code. Two-letter, three-letter and English names are read; it is kept as two capitals, such as GB.GB
cronA cron schedule of five fields (minute hour day month weekday), or @daily, @hourly and the like.'*/15 9-17 * * mon-fri'
csvText that holds valid CSV, such as a ```csv block. ->cells() reads its rows, columns and cells.'name,age'
currencyAn ISO 4217 currency code, kept in capitals: GBP, USD, EUR.GBP
date_formatHow a date is written, such as dd-MM-yyyy or d MMMM yyyy, HH:mm: dd is the day, MM the month, yyyy the year, HH the hour and mm the minute. Text goes in quotes ('at' HH:mm).dd-MM-yyyy
domainA domain name such as example.com or api.example.co.uk, lowercased, without a trailing dot.example.com
durationA length of time: 1h30m, 90s, 2d, 5y10mo or ISO 8601 such as PT1H30M. Kept in its short form.1h30m
emailAn email address such as joan@example.com. Spaces are trimmed and the domain is lowercased.joan@example.comdomains
file_pathWhere a file or folder is: ./data/input.txt from the script's folder, ../shared/rates.json from the folder above, or ~/notes.md from the home folder. Quote one that is absolute or has spaces: '/var/log/app.log', 'C:\Reports\May 2026.pdf'../data/input.txt
handle@ followed by letters, digits, _, . or -: a username such as @joan. Lowercased.@joan
hexHexadecimal digits, such as a hash: a3f9c0. Lowercased; 0x is dropped.a3f9c0bytes
ibanAn international bank account number, checked with its mod-97 digits. Kept in capitals without spaces.GB82WEST12345698765432
ipAn IPv4 or IPv6 address, written the standard way: 192.168.0.1 or 2001:db8::1.192.168.0.1version
jsonText that holds valid JSON. ->convert(from: json) gives the value.'{"a": 1}'
jwtA JSON Web Token: three base64url parts. Its claims can be read; its signature isn't checked.'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.sig'
localeA language tag (BCP 47) such as en, en-GB or pt-BR, in its usual case.en-GB
macA network card's MAC address, written as six lowercase pairs: 00:1a:2b:3c:4d:5e.00:1a:2b:3c:4d:5e
mimeA media type such as text/html or application/json, lowercased, with any parameters.application/json
moneyAn amount with a currency. Write GBP9.50 directly in expressions. Typed money also accepts text such as 'GBP 9.50', '£9.50' and '$12'. Displays the code and the currency's decimal places.GBP9.50rates
passwordA secret. It prints as ********, can't be compared with ==, and is hashed to be stored.'correct horse battery staple'upper, lower, digit, symbol, common, score, algorithm
phoneA phone number in E.164: + then the country code and number, 8 to 15 digits. Spaces, dots, dashes and brackets are dropped.+447700900123countries
portA network port, a whole number from 1 to 65535.8080
regexA regular expression with flags i, m, s and x, written /.../ in code./^[a-z]+$/i
semverA semantic version such as 1.4.2, 2.0.0-beta.1 or 1.0.0+build.5. A leading v is dropped.1.4.2
slash_pathNames joined by /, such as /docs/getting-started or /My Apps/Notes: a page, menu or category path rather than a file. It always starts with /, so home is /home. Spaces around each name, empty parts, . and a trailing / are dropped, and .. goes up one./docs/getting-started
slugLowercase words joined by -, for URLs: my-first-post.my-first-post
timezoneAn IANA time zone such as Europe/London or America/New_York, or UTC.Europe/London
urlAn absolute http, https, ftp, ws or wss URL. The scheme and host are lowercased.https://example.com/docs?page=2schemes, hosts
uuidA UUID, versions 1 to 8 and the nil and max UUIDs, lowercased to 8-4-4-4-12.3f2a8c1e-9b7d-4c2a-8e1f-0a9b8c7d6e5fv