Text mit einer eigenen Bedeutung
| Typ | Inhalt | Aufgeräumt | Methoden |
|---|---|---|---|
email |
Eine Adresse wie joan@example.com. |
Leerzeichen werden entfernt und die Domain wird in Kleinbuchstaben umgewandelt. | .local, .domain |
handle |
@ gefolgt von Buchstaben, Ziffern, _, . oder -, bis zu 30 davon. |
In Kleinbuchstaben. | .name (ohne @) |
uuid |
Eine UUID, Versionen 1 bis 8, sowie die Nil- und Max-UUIDs. | Wird in Kleinbuchstaben umgewandelt zu 8-4-4-4-12. urn:uuid:, geschweifte Klammern und 32 Hexadezimalziffern werden ebenfalls gelesen. |
.version, .timestamp |
regex |
Ein regulärer Ausdruck mit den Flags i, m, s und x. |
->test(), ->match(), ->match_all(), ->replace(), ->split(), .pattern, .flags |
|
password |
Ein Geheimnis. Es wird nie ausgegeben. | ->hash(), ->verify(), ->needs_rehash(), ->strength(), ->is_strong(), ->reveal() |
Ein nativer Wert ist trotzdem Text, und er ist nach dem Bereinigen gleich dem gleichen Text. Eine E-Mail-Adresse wird mit kleingeschriebener Domain verglichen. Sie behält die String-Methoden, die für sie sinnvoll sind, und der Editor schlägt nur diese vor:
| Typ | Zeichenkettenmethoden, die es beibehält |
|---|---|
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 |
Ein port, card oder password behält keinen. Die übrigen, etwa ->to_date() bei einer uuid, werden im Editor gemeldet und schlagen fehl, wenn das Skript läuft. Um trotzdem eine davon auf den Text anzuwenden, rufe zuerst ->to_string() auf: $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') }"Um zu prüfen, ob ein Text eine UUID ist, verwende $text->is_a(uuid). Verwende $text as uuid, um ihn umzuwandeln, und melde ungültigen Text als Fehler.
@uuid() erzeugt eine zufällige UUID der Version 4. @uuid(v: 7) erzeugt eine zeitlich sortierte UUID der Version 7, die übliche Wahl für Datenbankschlüssel, weil neue Werte nach alten einsortiert werden; ihr .timestamp ist der Zeitpunkt, zu dem sie erzeugt wurde. @uuid(v: 8) erzeugt eine UUID der Version 8, die ebenfalls zeitlich sortiert ist. Mit name: ergibt sich für denselben Namen immer dieselbe UUID, und namespace: hält Namen aus verschiedenen Bereichen auseinander.
Ein Wert in der falschen Form schlägt dort fehl, wo er erzeugt wird, mit einem Shape-Fehler, der den Grund nennt:
$email doesn't fit email: 'joan@' isn't an email: there's nothing after the @.Der Editor meldet dasselbe Problem beim Wert, während du tippst (KS5012).