KScript docs
EN

url fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.fragmentstringThe part after #, without it.
.hoststringThe host name, in lower case: example.com.
.originstringThe scheme, host and any port written: https://example.com.
.pathstringThe path, starting with /: /docs/start.
.portnumberThe port: the one written, or the scheme's usual one (443 for https).
.querymapThe query string as a map: ?page=2&q=cats gives { page: '2', q: 'cats' }.
.schemestringThe scheme, in lower case: https.

From KScript.Core

#url->join(path: string) → url

The url a link to path leads to from here: ../img/a.png or /about.
ParameterTakes
path requiredstring
Example
<let name="x" type="url" value="'https://example.com:8443/docs?page=2#intro'" />
<echo>{ $x->join('../blog/') }</echo>
$x: url = 'https://example.com:8443/docs?page=2#intro'
echo $x->join('../blog/')

#url->with(path?: string, query?: map, fragment?: string) → url

The url with parts changed: a new path, query values added or replaced (null removes one), or a new fragment (empty removes it). ->with(path: '/docs', query: { page: 3 }).
ParameterTakes
path optionalstring
query optionalmap
fragment optionalstring

Arguments can be named: ->with(…, query: …, fragment: …).

Example
<let name="x" type="url" value="'https://example.com:8443/docs?page=2#intro'" />
<echo>{ $x->with(path: '/blog/', query: { page: 3 }, fragment: 'top') }</echo>
$x: url = 'https://example.com:8443/docs?page=2#intro'
echo $x->with(path: '/blog/', query: { page: 3 }, fragment: 'top')

#url->without(query?: bool|string[], fragment?: bool) → url

The url without parts: the whole query or fragment (->without(query, fragment)), or only some query values (->without(query: ['page'])).
ParameterTakes
query optionalbool|string[]
fragment optionala flag: fragment or not fragment

Arguments can be named: ->without(…, fragment: …).

Example
<let name="x" type="url" value="'https://example.com:8443/docs?page=2#intro'" />
<echo>{ $x->without(query, fragment) } { $x->without(query: ['page']) }</echo>
$x: url = 'https://example.com:8443/docs?page=2#intro'
echo "{ $x->without(query, fragment) } { $x->without(query: ['page']) }"

Methods from any

Methods from string