KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

타입과 검증

고유한 의미를 가진 텍스트

타입 보관하는 내용 정리됨 메서드
email joan@example.com와 같은 주소입니다. 앞뒤 공백은 제거되고 도메인은 소문자로 바뀝니다. .local, .domain
handle @ 뒤에 문자, 숫자, _, . 또는 -가 오며, 최대 30개입니다. 소문자입니다. .name(@ 없이)
uuid 버전 1부터 8까지의 UUID, 그리고 nil 및 max UUID입니다. 8-4-4-4-12로 소문자화됩니다. urn:uuid:, 중괄호, 32자리 16진수도 읽습니다. .version, .timestamp
regex 플래그 i, m, s, x를 가진 정규 표현식입니다. ->test(), ->match(), ->match_all(), ->replace(), ->split(), .pattern, .flags
password 비밀 값입니다. 출력되지 않습니다. ->hash(), ->verify(), ->needs_rehash(), ->strength(), ->is_strong(), ->reveal()

네이티브 값도 여전히 텍스트이며, 정리 후에는 같은 텍스트와 같다고 비교됩니다. 이메일은 도메인을 소문자로 만들어 비교합니다. 의미가 있는 문자열 메서드는 그대로 유지되며, 편집기는 그것만 제안합니다:

타입 유지되는 문자열 메서드
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

port, card 또는 password는 아무것도 유지하지 않습니다. 나머지, 예를 들어 uuid에서의 ->to_date()는 편집기에서 보고되며 스크립트 실행 시 실패합니다. 그래도 텍스트에 사용하려면 먼저 ->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') }"

텍스트가 UUID인지 확인하려면 $text->is_a(uuid)를 사용하세요. 변환하면서 잘못된 텍스트를 오류로 보고하려면 $text as uuid를 사용하세요.

@uuid()는 무작위 버전 4 UUID를 만듭니다. @uuid(v: 7)는 시간순으로 정렬되는 버전 7 UUID를 만들며, 새 값이 이전 값 뒤에 정렬되므로 데이터베이스 키에 보통 쓰입니다. 그 .timestamp는 생성된 시각입니다. @uuid(v: 8)는 역시 시간순인 버전 8 UUID를 만듭니다. name:를 쓰면 그 이름에 대해 매번 같은 UUID가 되고, namespace:는 서로 다른 곳의 이름을 구분해 줍니다.

잘못된 형식의 값은 만들어지는 곳에서 실패하며, 그 이유를 말하는 Shape 오류가 발생합니다:

텍스트
$email doesn't fit email: 'joan@' isn't an email: there's nothing after the @.

편집기는 입력하는 동안 같은 문제를 값에서 보고합니다(KS5012).