KScript 문서
KO

언어

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

any 필드와 메서드

모든 값이 가진 메서드예요.

필드는 값에 관한 단순한 정보로, 대괄호 없이 점으로 읽어요: $value.name. 메서드는 인수를 받거나 작업을 수행하며, ->로 호출하거나 $value->name(arguments)처럼 값을 파이프로 넘겨서 호출해요: $value |> name(arguments).

KScript.Core에서 제공해요.

#any->convert(from?: 'json'|yaml|'csv'|'markdown'|'latex', to?: 'json'|yaml|'csv'|html|'markdown'|'latex', header?: bool, as?: type, headers?: list, indented?: bool) → any

값의 형식을 바꿔요. from: 은 특정 형식(json, yaml, csv, markdown 또는 latex)으로 작성된 텍스트를 읽고, to: 는 값을 한 형식(json, yaml, csv, 문서용 html, markdown, latex)으로 써요. 둘 다 지정하면 한 형식을 다른 형식으로 바꿔요. 헤더 줄이 없는 csv를 읽을 때는 not header을 사용해요. json, yaml, csv를 읽을 때 as: 는 형식으로 데이터를 검사해 레코드로 바꿔요. csv를 쓸 때 headers: 는 열을 골라 순서를 정해요. json을 쓸 때 indented 는 여러 줄로 나눠 써요. ->from(type:)과 ->to(type:)은 각각 from:과 to:를 단독으로 쓰는 축약형이에요.
매개변수받는 값
from 선택다음 단어 중 하나: 'json'|yaml|'csv'|'markdown'|'latex'
to 선택 사항다음 단어 중 하나: 'json'|yaml|'csv'|html|'markdown'|'latex'
header 선택 사항플래그: header 또는 not header
as 선택type
headers 선택list
indented 선택 사항플래그: indented 또는 not indented

인수는 이름을 붙여 지정할 수 있어요: ->convert(…, to: …, header: …).

예시
<!-- 'apple': the json text is read into a list of maps -->
<echo>{ '[{"fruit": "apple"}]'->convert(from: json)->first().fruit }</echo>
<let name="prices" value="[{ fruit: 'apple', price: 3 }, { fruit: 'plum', price: 5 }]" />
<!-- fruit,price on the first line, then one line a row: the maps' keys name the columns -->
<echo>{ $prices->convert(to: csv) }</echo>
<!-- 'apple: 3': yaml read, then written as json -->
<echo>{ 'apple: 3'->convert(from: yaml, to: json) }</echo>
// 'apple': the json text is read into a list of maps
echo '[{"fruit": "apple"}]'->convert(from: json)->first().fruit
$prices = [{ fruit: 'apple', price: 3 }, { fruit: 'plum', price: 5 }]
// fruit,price on the first line, then one line a row: the maps' keys name the columns
echo $prices->convert(to: csv)
// 'apple: 3': yaml read, then written as json
echo 'apple: 3'->convert(from: yaml, to: json)

#any->from(type: 'json'|yaml|'csv'|'markdown'|'latex', header?: bool, as?: type) → any

특정 형식으로 작성된 텍스트를 읽어요. ->convert(from: type)의 축약형이에요. ->from(type: csv, not header)는 헤더 줄이 없는 csv를 읽고, as: 는 형식으로 데이터를 검사해 레코드로 바꿔요.
매개변수받는 값
type 필수다음 단어 중 하나: 'json'|yaml|'csv'|'markdown'|'latex'
header 선택 사항플래그: header 또는 not header
as 선택type

인수는 이름을 붙여 지정할 수 있어요: ->from(…, header: …, as: …).

예시
<!-- 3: the yaml text read into a map -->
<echo>{ 'apple: 3'->from(type: yaml).apple }</echo>
// 3: the yaml text read into a map
echo 'apple: 3'->from(type: yaml).apple

#any->is_a(type: word) → bool

값이 이 타입이면, 또는 텍스트가 uuid 같은 네이티브 타입의 검증을 통과하면 True입니다.
매개변수받는 값
type 필수word
예시
<echo>{ 1h->is_a(duration) }</echo>
echo 1h->is_a(duration)

#any->is_null() → bool

값이 null이면 참이에요.
예시
<echo>{ null->is_null() }</echo>
echo null->is_null()

#any->or(fallback) → any

값이 참이면 그 값을, 아니면 fallback을 반환합니다.
예시
<echo>{ ''->or('nobody') }</echo>
echo ''->or('nobody')

#any->to(type: 'json'|yaml|'csv'|html|'markdown'|'latex', headers?: list, indented?: bool) → any

값을 특정 형식으로 써요. ->convert(to: type)의 축약형이에요. headers: 는 csv 열을 골라 순서를 정하고, indented 는 json을 여러 줄로 나눠 써요.
매개변수받는 값
type 필수다음 단어 중 하나: 'json'|yaml|'csv'|html|'markdown'|'latex'
headers 선택list
indented 선택 사항플래그: indented 또는 not indented

인수는 이름을 붙여 지정할 수 있어요: ->to(…, headers: …, indented: …).

예시
<let name="prices" value="[{ fruit: 'apple', price: 3 }, { fruit: 'plum', price: 5 }]" />
<!-- the list written as json text -->
<echo>{ $prices->to(type: json) }</echo>
$prices = [{ fruit: 'apple', price: 3 }, { fruit: 'plum', price: 5 }]
// the list written as json text
echo $prices->to(type: json)

#any->to_string() → string

값을 텍스트로 나타냅니다.
예시
<echo>{ 42->to_string() + '!' }</echo>
echo 42->to_string() + '!'

#any->type() → string

값의 타입 이름을 반환해요. 원소 타입이 하나인 list는 그 타입 뒤에 []을 붙인 이름을 반환하며, 예를 들어 number[]처럼 나와요. 타입이 섞였거나 비어 있는 타입 없는 list는 any[]을 반환해요. record는 선언된 타입 이름을 반환해요.
예시
<echo>{ [1, 2]->type() }</echo>
echo [1, 2]->type()