Testo con un significato proprio
| Tipo | Contenuto | Ordinato | Metodi |
|---|---|---|---|
email |
Un indirizzo come joan@example.com. |
Gli spazi vengono rimossi e il dominio viene convertito in minuscolo. | .local, .domain |
handle |
@ seguito da lettere, cifre, _, . o -, fino a 30 caratteri. |
Convertito in minuscolo. | .name (senza @) |
uuid |
Un UUID, versioni da 1 a 8, più gli UUID nil e max. | Convertito in minuscolo in 8-4-4-4-12. Vengono letti anche urn:uuid:, le parentesi graffe e le 32 cifre esadecimali. |
.version, .timestamp |
regex |
Un'espressione regolare con i flag i, m, s e x. |
->test(), ->match(), ->match_all(), ->replace(), ->split(), .pattern, .flags |
|
password |
Un segreto. Non viene mai stampato. | ->hash(), ->verify(), ->needs_rehash(), ->strength(), ->is_strong(), ->reveal() |
Un valore nativo resta testo e, una volta normalizzato, risulta uguale allo stesso testo. Un'email si confronta con il dominio in minuscolo. Mantiene i metodi di stringa che hanno senso per lui, e l'editor suggerisce solo quelli:
| Tipo | Metodi di stringa mantenuti |
|---|---|
email |
contains, starts_with, ends_with, index_of, count, lower, upper, slice, split, replace, matches, truncate, pad, escape, url_encode, markdown_escape |
handle |
contains, starts_with, ends_with, count, upper, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
uuid |
contains, starts_with, ends_with, upper, slice, split, pad, escape, url_encode, markdown_escape |
regex |
contains, starts_with, ends_with, count, escape, markdown_escape |
url |
contains, starts_with, ends_with, index_of, count, split, replace, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
domain |
contains, starts_with, ends_with, index_of, count, split, upper, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
ip |
contains, starts_with, ends_with, index_of, count, split, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
cidr |
contains, starts_with, ends_with, index_of, count, split, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
mac |
contains, starts_with, ends_with, index_of, count, split, upper, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
slug |
contains, starts_with, ends_with, index_of, count, split, upper, replace, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
file_path |
contains, starts_with, ends_with, index_of, count, split, lower, upper, replace, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
slash_path |
contains, starts_with, ends_with, index_of, count, split, lower, upper, replace, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
semver |
contains, starts_with, ends_with, index_of, count, split, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
mime |
contains, starts_with, ends_with, index_of, count, split, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
hex |
contains, starts_with, ends_with, index_of, count, upper, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
base64 |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
jwt |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
json |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
csv |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
phone |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
country |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
currency |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
locale |
contains, starts_with, ends_with, index_of, count, split, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
timezone |
contains, starts_with, ends_with, index_of, count, split, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
duration |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
date_format |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
cron |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
color |
contains, starts_with, ends_with, index_of, count, upper, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
iban |
contains, starts_with, ends_with, index_of, count, slice, matches, truncate, pad, escape, url_encode, markdown_escape |
Un port, card o password non ne mantiene nessuno. Gli altri, come ->to_date() su un uuid, vengono segnalati nell'editor e causano un errore all'esecuzione dello script. Per usarne uno comunque sul testo, chiama prima ->to_string(): $id->to_string()->to_date().
<let name="email" type="email" value="' Joan.Smith@Example.COM '" />
<echo>{ $email } { $email.local } at { $email.domain }</echo>
<echo>{ $email == 'Joan.Smith@EXAMPLE.com' }</echo>
<let name="who" type="handle" value="@Joan_S" />
<echo>{ $who } { $who.name }</echo>
<let name="id" value="@uuid()" />
<let name="key" value="@uuid(v: 8, name: 'joan@example.com')" />
<echo>{ $id.version } { $key.version } { $key == @uuid(v: 8, name: 'joan@example.com') }</echo>$email: email = ' Joan.Smith@Example.COM '
echo "{ $email } { $email.local } at { $email.domain }"
echo "{ $email == 'Joan.Smith@EXAMPLE.com' }"
$who: handle = @Joan_S
echo "{ $who } { $who.name }"
$id = @uuid()
$key = @uuid(v: 8, name: 'joan@example.com')
echo "{ $id.version } { $key.version } { $key == @uuid(v: 8, name: 'joan@example.com') }"Per verificare se un testo è un UUID, usa $text->is_a(uuid). Usa $text as uuid per convertirlo e segnalare come errore il testo non valido.
@uuid() crea un UUID casuale versione 4. @uuid(v: 7) crea un UUID versione 7 ordinato per tempo, la scelta abituale per le chiavi di database perché i nuovi valori si ordinano dopo i vecchi; il suo .timestamp è il momento in cui è stato creato. @uuid(v: 8) crea un UUID versione 8, anch'esso ordinato per tempo. Con name: è sempre lo stesso UUID per quel nome, e namespace: tiene separati i nomi di luoghi diversi.
Un valore di forma errata fallisce al momento della creazione, con un errore Shape che spiega il motivo:
$email doesn't fit email: 'joan@' isn't an email: there's nothing after the @.L'editor segnala lo stesso problema sul valore mentre digiti (KS5012).