텍스트는 string이에요. 따옴표로 감싼 모든 것이 텍스트예요. 'Single quotes' 입력한 그대로 유지되고, "double quotes"{ } 안에 있는 값으로 채워지므로 "Hello { $name }"는 변수를 읽어요. 여러 줄 텍스트는 ``` 사이에 텍스트 블록으로 작성하며, 작성한 대로 모든 줄바꿈이 유지돼요.
텍스트 메서드는 호출된 텍스트를 바꾸지 않아요. 각 메서드는 새 텍스트(또는 숫자, 목록, bool)를 반환하므로, 체이닝하거나 결과를 변수에 담아 사용하세요:
<let name="name" value="' ada LOVELACE '" />
<let name="tidy" value="$name->trim()->title()" />
<echo value="$tidy" /> <!-- 'Ada Lovelace' because the spaces go and each word gets a capital -->
<echo value="$name" /> <!-- ' ada LOVELACE ' because the text itself is unchanged -->
$name = ' ada LOVELACE '
$tidy = $name->trim()->title()
echo $tidy // 'Ada Lovelace' because the spaces go and each word gets a capital
echo $name // ' ada LOVELACE ' because the text itself is unchanged
위치는 0부터 세고, 음수 위치는 끝에서부터 세요. 이모지 같은 문자는 두 자리로 계산되며, 어떤 메서드도 문자를 중간에서 자르지 않아요. 비교는 ignore_case 플래그를 전달하지 않는 한 대소문자를 정확히 구분해요.
필드는 값에 관한 단순한 정보로, 대괄호 없이 점으로 읽어요: $value.name. 메서드는 인수를 받거나 작업을 수행하며, ->로 호출하거나 $value->name(arguments)처럼 값을 파이프로 넘겨서 호출해요: $value |> name(arguments).
'a.tar.gz'->after('.', last) 결과는 gz입니다. 텍스트에서 처음 나타나는 위치(또는 last를 쓰면 마지막 위치) 뒤의 텍스트를 돌려주며, 찾을 수 없으면 전체 텍스트를 돌려줍니다.
->after(text, last?)는 text가 처음 나타나는 위치 뒤의 텍스트를 돌려주고, last를 쓰면 마지막으로 나타나는 위치 뒤의 텍스트를 돌려줍니다. text가 없으면 전체 텍스트를 돌려줍니다:
<let name="file" value="'archive.tar.gz'" />
<echo value="$file->after('.')" /> <!-- 'tar.gz' because it cuts at the first dot -->
<echo value="$file->after('.', last)" /> <!-- 'gz' because it cuts at the last dot -->
<echo value="'no-at-sign'->after('@')" /> <!-- 'no-at-sign' because there is no @ to cut at -->
$file = 'archive.tar.gz'
echo $file->after('.') // 'tar.gz' because it cuts at the first dot
echo $file->after('.', last) // 'gz' because it cuts at the last dot
echo 'no-at-sign'->after('@') // 'no-at-sign' because there is no @ to cut at
'a.tar.gz'->before('.', last) 결과는 a.tar입니다. 텍스트에서 처음 나타나는 위치(또는 last를 쓰면 마지막 위치) 앞의 텍스트를 돌려주며, 찾을 수 없으면 전체 텍스트를 돌려줍니다.
->before(text, last?)는 text가 처음 나타나는 위치 앞의 텍스트를 돌려주고, last를 쓰면 마지막으로 나타나는 위치 앞의 텍스트를 돌려줍니다. text가 없으면 전체 텍스트를 돌려줍니다:
<let name="email" value="'joan@example.com'" />
<echo value="$email->before('@')" /> <!-- 'joan' -->
<echo value="'archive.tar.gz'->before('.', last)" /> <!-- 'archive.tar' because it cuts at the last dot -->
$email = 'joan@example.com'
echo $email->before('@') // 'joan'
echo 'archive.tar.gz'->before('.', last) // 'archive.tar' because it cuts at the last dot
빈 줄을 기준으로 나눈 텍스트의 각 부분이며, 앞뒤 줄바꿈은 제거됩니다: 'a\nb\n\nc'->blocks()의 결과는 ['a\nb', 'c']입니다.
->blocks()는 빈 줄에서 텍스트를 나눠 각 블록이 여러 줄의 묶음이 되게 합니다. 줄바꿈 한 번은 블록 안에 그대로 남고, 빈 줄에서만 새 블록이 시작됩니다. 각 블록은 앞뒤 줄바꿈이 제거된 상태입니다:
<let name="pantry">```text
tea
milk
flour
sugar
eggs
```</let>
<let name="shelves" value="$pantry->blocks()" />
<echo value="$shelves->count()" /> <!-- 2 because one blank line splits the text in two -->
<echo value="$shelves->map(.lines()->count())" /> <!-- [2, 3] because the first block has 2 lines and the second 3 -->
$pantry = ```text
tea
milk
flour
sugar
eggs
```
$shelves = $pantry->blocks()
echo $shelves->count() // 2 because one blank line splits the text in two
echo $shelves->map(.lines()->count()) // [2, 3] because the first block has 2 lines and the second 3
<echo value="'élan and style'->capitalize()" /> <!-- 'Élan and style' because only the first letter changes -->
<echo value="'iPhone'->capitalize()" /> <!-- 'IPhone' -->
echo 'élan and style'->capitalize() // 'Élan and style' because only the first letter changes
echo 'iPhone'->capitalize() // 'IPhone'
하나의 스타일로 된 식별자로서의 텍스트: 'User ID'->case(snake)의 결과는 user_id이고, kebab은 user-id, camel은 userId, pascal은 UserId를 돌려줍니다.
->case(style)는 텍스트를 하나의 스타일로 된 이름으로 바꿉니다: snake(user_id), kebab(user-id), camel(userId), pascal(UserId). 공백, 구분자, 대소문자 변화 어디서든 단어를 찾으므로 어떤 스타일에서든 다른 스타일로 바꿀 수 있습니다:
->chars()는 문자들을 하나의 텍스트씩 담은 목록으로 돌려줍니다. 이모지 같은 문자는 어떻게 저장되어 있든 한 항목으로 취급됩니다:
<echo value="'tea'->chars()" /> <!-- ['t', 'e', 'a'] -->
<echo value="'👍🏽x'->chars()->count()" /> <!-- 2 because the thumb and its skin tone are one character -->
echo 'tea'->chars() // ['t', 'e', 'a']
echo '👍🏽x'->chars()->count() // 2 because the thumb and its skin tone are one character
텍스트를 문자들의 행으로 나눈 것으로, 한 줄이 한 목록이 되며 지도나 미로에 씁니다: '#.\n.#'->grid()의 결과는 [['#', '.'], ['.', '#']]입니다. 끝의 줄바꿈은 빈 행을 추가하지 않습니다. $grid[row][column]으로 칸을 읽고, ->cells(rows) 또는 ->cells(columns)로 행이나 열을 순회합니다.
->grid()는 문자 줄을 한 글자씩 담은 행으로 바꿉니다. 따라서 $grid[row][column]는 한 글자입니다. 0행은 맨 위 줄이고 0열은 첫 글자입니다. 끝의 줄바꿈은 빈 행을 추가하지 않습니다:
<let name="garden">```text
#.#
..#
```</let>
<let name="plot" value="$garden->grid()" />
<echo value="$plot" /> <!-- [['#', '.', '#'], ['.', '.', '#']] -->
<echo value="$plot[0][1]" /> <!-- '.' because row 0 is #.# and column 1 is its middle -->
<echo value="$plot[1][2]" /> <!-- '#' because row 1 is ..# and column 2 is its last -->
$garden = ```text
#.#
..#
```
$plot = $garden->grid()
echo $plot // [['#', '.', '#'], ['.', '.', '#']]
echo $plot[0][1] // '.' because row 0 is #.# and column 1 is its middle
echo $plot[1][2] // '#' because row 1 is ..# and column 2 is its last
비밀 키로 텍스트의 HMAC을 계산해 16진수로 돌려줍니다(기본값은 SHA-256). 웹훅 서명을 만들 때 쓰는 방식입니다. 서명을 비교할 때는 @secure_equals()를 쓰세요.
->hmac(key, algorithm?)는 비밀 키로 텍스트에 서명하고 그 서명을 16진수로 돌려줍니다. sha1 또는 sha512를 전달하지 않으면 SHA-256을 씁니다. 웹훅이 메시지의 출처를 증명하는 데 쓰는 방식입니다. 서명을 비교할 때는 @secure_equals()를 쓰세요. 두 값이 얼마나 일치하든 같은 시간이 걸립니다:
<let name="body" value="'{"id": 1}'" />
<let name="signature" value="$body->hmac('whsec_test')" />
<echo value="$signature->count()" /> <!-- 64 because SHA-256 in hex is 64 characters -->
<echo value="@secure_equals($signature, $body->hmac('whsec_test'))" /> <!-- true because the same key signs the same text the same way -->
$body = '{"id": 1}'
$signature = $body->hmac('whsec_test')
echo $signature->count() // 64 because SHA-256 in hex is 64 characters
echo @secure_equals($signature, $body->hmac('whsec_test')) // true because the same key signs the same text the same way
매개변수
받는 값
key필수
모든 값
algorithm선택
다음 단어 중 하나: sha256|sha1|sha512
인수는 이름을 붙여 지정할 수 있습니다: ->hmac(…, algorithm: …).
예시
<echo>{ '{"id": 1}'->hmac('whsec_test') }</echo>
echo '{"id": 1}'->hmac('whsec_test')
#string->index_of(text, ignore_case?: bool, last?: bool)→ number
텍스트가 처음 나타나는 위치, 또는 last를 쓰면 마지막으로 나타나는 위치입니다. 찾을 수 없으면 -1입니다. ignore_case를 쓰면 대소문자를 구분하지 않습니다.
->index_of(text, ignore_case?, last?)는 text가 처음 나타나는 위치를, last를 사용하면 마지막으로 나타나는 위치를 알려줘요. text가 없으면 -1를 반환해요:
정수 또는 소수 형태(예: '42', '-3.5', '1e3')만으로 이루어진 텍스트이면 참입니다. 앞뒤 공백은 허용됩니다.
->is_numeric()는 '42', '-3.5', '1e3'처럼 텍스트 전체가 숫자이면 참입니다. 앞뒤 공백은 허용됩니다:
<echo value="'42'->is_numeric()" /> <!-- true -->
<echo value="' -3.5 '->is_numeric()" /> <!-- true because the spaces around it are fine -->
<echo value="'42 cats'->is_numeric()" /> <!-- false because cats isn't part of a number -->
echo '42'->is_numeric() // true
echo ' -3.5 '->is_numeric() // true because the spaces around it are fine
echo '42 cats'->is_numeric() // false because cats isn't part of a number
->lines()는 줄마다 하나의 텍스트를 반환합니다. 빈 줄은 빈 텍스트가 되므로 그룹 사이의 구분을 찾을 수 있습니다:
<let name="note">```text
tea
milk
juice
```</let>
<echo value="$note->lines()" /> <!-- ['tea', 'milk', '', 'juice'] -->
<echo value="$note->lines()->count()" /> <!-- 4 because the blank line is a line too -->
$note = ```text
tea
milk
juice
```
echo $note->lines() // ['tea', 'milk', '', 'juice']
echo $note->lines()->count() // 4 because the blank line is a line too
각 문자를 char(기본값 *)로 바꾼 텍스트를 반환하되, 마지막 keep_end개 문자는 그대로 둡니다. ->mask('*', keep_end: 4)는 마지막 네 글자만 보여 줍니다.
->mask(char?, keep_end?)는 텍스트를 문자 하나로 가리되, 다른 문자를 주지 않으면 *를 사용하고, 독자가 알아볼 수 있도록 마지막 keep_end개 문자는 남겨 둡니다:
<echo value="'4242424242424242'->mask('*', keep_end: 4)" /> <!-- '************4242' because only the last 4 show -->
<echo value="'secret'->mask()" /> <!-- '******' -->
echo '4242424242424242'->mask('*', keep_end: 4) // '************4242' because only the last 4 show
echo 'secret'->mask() // '******'
텍스트가 정규 표현식과 일치하면 true입니다: ->matches(/^[a-z]+$/i).
->matches(pattern)는 정규 표현식이 텍스트에서 일치하는 부분을 찾으면 참입니다. 전체 텍스트를 검사하려면 ^와 $로 고정하세요:
<echo value="'Tea'->matches(/^[a-z]+$/i)" /> <!-- true because i ignores case -->
<echo value="'Tea2'->matches(/^[a-z]+$/i)" /> <!-- false because 2 isn't a letter -->
echo 'Tea'->matches(/^[a-z]+$/i) // true because i ignores case
echo 'Tea2'->matches(/^[a-z]+$/i) // false because 2 isn't a letter
->normalize_unicode(form?)는 모양이 같아 보이는 텍스트가 같게 비교되도록 합니다. é는 한 글자로 저장되거나 e와 악센트 결합으로 저장될 수 있습니다. NFC(기본값)는 이들을 합치고, NFD는 나눕니다:
<echo value="'café'->normalize_unicode(NFD)->count()" /> <!-- 5 because NFD stores é as e and an accent -->
<echo value="'café'->normalize_unicode()->count()" /> <!-- 4 -->
echo 'café'->normalize_unicode(NFD)->count() // 5 because NFD stores é as e and an accent
echo 'café'->normalize_unicode()->count() // 4
텍스트에 적힌 모든 숫자를 순서대로 숫자 값으로 반환합니다: 'x=-3, y=12'->numbers()는 [-3, 12]입니다. 바로 왼쪽에 문자나 숫자가 붙어 있지 않은 마이너스는 음수로 봅니다. 따라서 '1-3'->numbers()는 [1, 3]입니다.
->numbers()는 텍스트에 적힌 모든 숫자를 순서대로 숫자 값으로 반환합니다. 왼쪽에 붙은 것이 없는 마이너스는 x=-3처럼 부호로 취급하고, 1-3처럼 두 숫자 사이에 있으면 줄표로 취급합니다:
<echo value="'move 3 boxes from -1 to 12'->numbers()" /> <!-- [3, -1, 12] because -1 has a space before its minus -->
<echo value="'pages 4-9'->numbers()" /> <!-- [4, 9] because the minus joins 4 and 9, so it is a dash -->
<echo value="'price 2.50, qty 4'->numbers()" /> <!-- [2.5, 4] -->
echo 'move 3 boxes from -1 to 12'->numbers() // [3, -1, 12] because -1 has a space before its minus
echo 'pages 4-9'->numbers() // [4, 9] because the minus joins 4 and 9, so it is a dash
echo 'price 2.50, qty 4'->numbers() // [2.5, 4]
텍스트 끝을 width에 맞춰 채운 결과를 반환합니다. start를 주면 앞에서 채웁니다: '7'->pad(3, '0', start)는 007입니다.
->pad(width, char?, start?)는 텍스트가 width자가 될 때까지 문자를 추가합니다. 다른 문자를 주지 않으면 공백을 사용합니다. 기본적으로 끝에 채우고, start를 지정하면 앞에 채웁니다. 이미 그 길이 이상인 텍스트는 그대로 둡니다:
<echo value="'7'->pad(3, '0', start)" /> <!-- '007' because two zeros go in front -->
<echo value="'tea'->pad(5, '.')" /> <!-- 'tea..' -->
<echo value="'teapot'->pad(3)" /> <!-- 'teapot' because it is already longer than 3 -->
echo '7'->pad(3, '0', start) // '007' because two zeros go in front
echo 'tea'->pad(5, '.') // 'tea..'
echo 'teapot'->pad(3) // 'teapot' because it is already longer than 3
The text with every old replaced by new. old can be a regex: ->replace(/\s+/, ' '), and new can use its groups as $1 or $. With ignore_case, plain text matches in any case.
->replace(old, new, ignore_case?)는 모든 old를 new로 바꿉니다. old에는 정규 표현식을 쓸 수 있으며, 이때 new에서는 일치한 그룹을 $1 또는 ${name}로 참조할 수 있습니다:
<echo value="'banana'->replace('a', 'o')" /> <!-- 'bonono' because every a changes -->
<echo value="'Tea'->replace('t', 'p', ignore_case)" /> <!-- 'pea' because T matches t -->
<echo value="'too many spaces'->replace(/\s+/, ' ')" /> <!-- 'too many spaces' -->
<echo value="'2026-12-01'->replace(/(\d+)-(\d+)-(\d+)/, '$3/$2/$1')" /> <!-- '01/12/2026' because the groups swap places -->
echo 'banana'->replace('a', 'o') // 'bonono' because every a changes
echo 'Tea'->replace('t', 'p', ignore_case) // 'pea' because T matches t
echo 'too many spaces'->replace(/\s+/, ' ') // 'too many spaces'
echo '2026-12-01'->replace(/(\d+)-(\d+)-(\d+)/, '$3/$2/$1') // '01/12/2026' because the groups swap places
매개변수
받는 값
old필수
모든 값
new필수
모든 값
ignore_caseoptional
플래그: ignore_case 또는 not ignore_case
인수는 이름으로 지정할 수 있습니다: ->replace(…, new: …, ignore_case: …).
->sha256()는 텍스트의 SHA-256 해시를 64자의 16진수로 반환합니다. 같은 텍스트는 항상 같은 해시를 만들고, 조금이라도 바뀌면 다른 해시가 됩니다:
<echo value="'tea'->sha256()->count()" /> <!-- 64 -->
<echo value="'tea'->sha256() == 'tea'->sha256()" /> <!-- true because the same text gives the same hash -->
<echo value="'tea'->sha256() == 'Tea'->sha256()" /> <!-- false because one letter changed -->
echo 'tea'->sha256()->count() // 64
echo 'tea'->sha256() == 'tea'->sha256() // true because the same text gives the same hash
echo 'tea'->sha256() == 'Tea'->sha256() // false because one letter changed
Every place a mask fits (->shapes(Tree), or ->shapes([Block, Ell]) for several), and every square, rectangle, line or circle (name one or several: ->shapes(square, circle, of: '#')) made by the cells that hold of: (a value, or a regex). It looks through text (each line a row, each character a cell, a blank line between layers), a list of values (one row), a grid ($grid[row][column]) or a 3D list ($cube[layer][row][column]); the built-in shapes also take a list of points { row, column }. A mask is a type that extends Mask: its layout is a picture, one character a cell, and each character matches a cell holding the same character, unless its symbols say otherwise (a value, a regex, a fn(cell), or any for a cell that isn't part of the shape). Each match is { kind, points }: kind is the mask's name or the shape, and each point is { row, column, value } (with symbol for a mask, and layer in 3D). With rotated, a mask is tried turned every way the input allows (back to front in a row, the four quarter turns in a grid, all 24 ways round in 3D), and squares, rectangles and lines may lean. A line needs size:, and a circle radius: and distance: straight (the default), steps or moves.
->shapes(mask?, square?, rectangle?, line?, circle?, of?, rotated?, size?, radius?, distance?) finds shapes drawn in text. Each line is a row and each character a cell, so the text doesn't need ->grid() first, and a blank line starts the next layer of a 3D input. It works as the list method does: name a mask first (a type that extends Mask, or a list of them), or one of the built-in shapes with of: to say which cells make it. Each match comes back as { kind, points }, and each point says its row, column, value and the mask's symbol drawn over it. See list ->shapes() for every argument.
<let name="orchard">```text
#.#.#
.#...
#.#.#
```</let>
<type name="Tree" extends="Mask">
<field name="layout" default="```text
#.#
.#.
```" />
<field name="symbols" default="{ '.': any }" />
</type>
<echo value="$orchard->shapes(Tree)->count()" /> <!-- 1 because the V of three trees fits only at the top left -->
<echo value="$orchard->shapes(Tree, rotated)->count()" /> <!-- 4 because turned upside down and on its sides it fits three more places -->
<echo value="$orchard->shapes(Tree)->first().points->map(.column)" /> <!-- [0, 2, 1] because the points come in reading order: the top two, then the middle -->
$orchard = ```text
#.#.#
.#...
#.#.#
```
type Tree extends Mask {
layout: ```text
#.#
.#.
```
symbols: { '.': any }
}
echo $orchard->shapes(Tree)->count() // 1 because the V of three trees fits only at the top left
echo $orchard->shapes(Tree, rotated)->count() // 4 because turned upside down and on its sides it fits three more places
echo $orchard->shapes(Tree)->first().points->map(.column) // [0, 2, 1] because the points come in reading order: the top two, then the middle
->slice(start, end?)는 위치 start에서부터 end 앞까지, 또는 텍스트의 끝까지의 문자를 반환해요. 음수 위치는 끝에서부터 셉니다:
<let name="word" value="'teapot'" />
<echo value="$word->slice(0, 3)" /> <!-- 'tea' because it stops before position 3 -->
<echo value="$word->slice(3)" /> <!-- 'pot' -->
<echo value="$word->slice(-3)" /> <!-- 'pot' because -3 is three from the end -->
$word = 'teapot'
echo $word->slice(0, 3) // 'tea' because it stops before position 3
echo $word->slice(3) // 'pot'
echo $word->slice(-3) // 'pot' because -3 is three from the end
각 구분자(또는 공백) 사이의 부분을 목록으로 반환합니다. 구분자에는 정규 표현식을 쓸 수 있습니다: ->split(/\s*,\s*/).
->split(separator?)는 구분자마다 텍스트를 나누고 그 부분들을 목록으로 반환합니다. 구분자를 주지 않으면 공백에서 나눕니다. 구분자에는 정규 표현식을 쓸 수 있습니다:
<echo value="'tea,milk,juice'->split(',')" /> <!-- ['tea', 'milk', 'juice'] -->
<echo value="'tea milk'->split()" /> <!-- ['tea', 'milk'] -->
<echo value="'a, b,c'->split(/\s*,\s*/)" /> <!-- ['a', 'b', 'c'] because the spaces around each comma go too -->
echo 'tea,milk,juice'->split(',') // ['tea', 'milk', 'juice']
echo 'tea milk'->split() // ['tea', 'milk']
echo 'a, b,c'->split(/\s*,\s*/) // ['a', 'b', 'c'] because the spaces around each comma go too
정확히 일치하는 접두사, 접미사 또는 둘 다를 있는 경우에 한해 제거한 텍스트예요: 'v1.2'->strip(prefix: 'v'), 'a.txt'->strip(suffix: '.txt').
->strip(prefix?, suffix?)는 정확히 일치하는 접두사, 접미사 또는 둘 다를 있는 경우에 한해 한 번 제거해요. ->trim()와 달리 글자마다가 아니라 전체 조각을 한 번 제거해요:
<echo value="'v1.2'->strip(prefix: 'v')" /> <!-- '1.2' -->
<echo value="'notes.txt'->strip(suffix: '.txt')" /> <!-- 'notes' -->
<echo value="'[tea]'->strip(prefix: '[', suffix: ']')" /> <!-- 'tea' -->
<echo value="'tea'->strip(prefix: 'x')" /> <!-- 'tea' because there is no x to take off -->
echo 'v1.2'->strip(prefix: 'v') // '1.2'
echo 'notes.txt'->strip(suffix: '.txt') // 'notes'
echo '[tea]'->strip(prefix: '[', suffix: ']') // 'tea'
echo 'tea'->strip(prefix: 'x') // 'tea' because there is no x to take off
텍스트를 base64로 인코딩합니다. url: true이면 패딩 없는 URL 안전 base64를 사용합니다.
->to_base64(url?)는 텍스트를 base64로 인코딩해요. base64는 문자, 숫자, +, /, =만 사용하므로 HTTP 헤더처럼 다른 문자를 쓸 수 없는 곳에서도 전달할 수 있어요. url를 주면 대신 -와 _를 쓰고 = 패딩을 생략하므로 URL에 넣기 좋아요. 결과는 base64 값이며, 그 ->decode()는 원래 텍스트를 돌려줘요:
<echo value="'tea'->to_base64()" /> <!-- 'dGVh' -->
<echo value="'tea?'->to_base64()" /> <!-- 'dGVhPw==' -->
<echo value="'tea?'->to_base64(url)" /> <!-- 'dGVhPw' because url leaves off the padding -->
<echo value="'tea'->to_base64()->decode()" /> <!-- 'tea' because the base64 value decodes back to the text -->
echo 'tea'->to_base64() // 'dGVh'
echo 'tea?'->to_base64() // 'dGVhPw=='
echo 'tea?'->to_base64(url) // 'dGVhPw' because url leaves off the padding
echo 'tea'->to_base64()->decode() // 'tea' because the base64 value decodes back to the text
텍스트를 날짜로 읽어요: '2026-11-22'->to_date(), 또는 표기 방식이 다르면 '22-11-2026'->to_date(dd-MM-yyyy).
->to_date(format?)는 텍스트를 날짜로 읽어요. '2026-11-22'나 '2026-11-22 14:30'처럼 ISO 방식으로 쓴 날짜는 형식을 지정할 필요가 없어요. 다른 방식이라면 그 텍스트가 쓰인 형식 패턴을 알려 주세요:
<let name="day" value="'2026-11-22'->to_date()" />
<echo value="$day.year" /> <!-- 2026 -->
<echo value="'22-11-2026'->to_date(dd-MM-yyyy).month" /> <!-- 11 because the pattern says the month is in the middle -->
$day = '2026-11-22'->to_date()
echo $day.year // 2026
echo '22-11-2026'->to_date(dd-MM-yyyy).month // 11 because the pattern says the month is in the middle
->to_int(default?)는 텍스트를 정수로 읽어요. 소수점 이하는 버려요. 텍스트가 숫자가 아니면 default를 얻어요. 기본값이 없으면 타입 오류가 나므로, 확신이 없는 텍스트에는 기본값을 넘기세요:
<echo value="'42'->to_int()" /> <!-- 42 -->
<echo value="'3.7'->to_int()" /> <!-- 3 because the .7 is dropped -->
<echo value="'abc'->to_int(-1)" /> <!-- -1 because abc isn't a number -->
echo '42'->to_int() // 42
echo '3.7'->to_int() // 3 because the .7 is dropped
echo 'abc'->to_int(-1) // -1 because abc isn't a number
->to_number(default?)는 텍스트를 소수점까지 포함한 숫자로 읽어요. 텍스트가 숫자가 아니면 default를 얻어요. 기본값이 없으면 그 사실을 알려 주는 타입 오류가 나요:
<echo value="'3.7'->to_number()" /> <!-- 3.7 -->
<echo value="'x'->to_number(0)" /> <!-- 0 because x isn't a number, so the default is used -->
<echo value="'x'->to_number(null)" /> <!-- null -->
echo '3.7'->to_number() // 3.7
echo 'x'->to_number(0) // 0 because x isn't a number, so the default is used
echo 'x'->to_number(null) // null
텍스트에 있는 단어들을 목록으로 돌려줘요. 공백과 구두점은 제외해요. 모든 문자 체계의 글자를 셀 수 있고, don't나 well-known은 한 단어로 봐요.
->words()는 텍스트에서 단어를 가져와요. 단어 사이의 공백과 구두점은 빼요. 모든 문자 체계의 글자를 셀 수 있고, don't나 well-known는 한 단어로 유지해요:
<echo value="'Hello, world!'->words()" /> <!-- ['Hello', 'world'] -->
<echo value=""Don't stop"->words()->count()" /> <!-- 2 because don't is one word -->
echo 'Hello, world!'->words() // ['Hello', 'world']
echo "Don't stop"->words()->count() // 2 because don't is one word
예시
<echo>{ 'Hello, world! A well-known phrase.'->words() }</echo>
echo 'Hello, world! A well-known phrase.'->words()
단어 사이에 줄바꿈을 넣어, width보다 긴 줄이 없도록 한 텍스트예요(단어 하나가 더 길면 예외). @terminal_width()와 함께 쓰면 좋아요.
->wrap(width)는 단어 사이에 줄바꿈을 넣어 어떤 줄도 width보다 길지 않게 해요. 단어 하나가 그보다 길면 예외예요. @terminal_width() 너비의 터미널에 맞는 텍스트에 알맞아요:
<let name="lines" value="'Ann went home early'->wrap(width: 9)->lines()" />
<echo value="$lines" /> <!-- ['Ann went', 'home', 'early'] because home early would be 10 characters -->
$lines = 'Ann went home early'->wrap(width: 9)->lines()
echo $lines // ['Ann went', 'home', 'early'] because home early would be 10 characters
코드를 강조 표시된 HTML로 돌려줘요. <pre>에 넣어 쓸 수 있어요. VS Code 확장 프로그램이 쓰는 문법으로 색을 입혀요. 각 토큰은 스타일시트에서 색을 입힐 수 있도록 <span class="hl-kw"> 안에 들어가요(hl-com, hl-str, hl-num, hl-kw, hl-op, hl-fn, hl-type, hl-var, hl-tag, hl-attr, hl-expr, hl-re). lang은 kscript(기본값), ks.xml, html(페이지), ks.css, text, 또는 VS Code가 아는 언어(css, js, ts, json, sql, sh, yaml, python...)예요.