KScript 문서
KO

언어

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

변경 사항

메서드와 필드

단순한 사실은 필드이며, 점(.)으로 대괄호 없이 읽습니다: $file.name, $file.size, $response.status, $date.year. 필드를 호출하면($file->name()) 그렇다고 알려 주는 오류가 발생합니다. 개수 세기는 모든 값에서 ->count()입니다.

켜짐 이전 지금
목록, 맵, 텍스트 ->length() ->count()
텍스트 공백만 있거나 비어 있는 텍스트를 허용하려면 $text->is_empty() 그 검사에는 $text->is_blank()을 사용하세요. $text->is_empty()는 이제 글자 수가 0인지 검사합니다.
목록 ->where(fn), ->append(item) ->filter(fn), ->push(item)
목록 정확히 일치하는 항목을 세려면 $items->count_of($value) 정확한 일치에는 $items->count_of(fn(x) => $x === $value)을 사용하세요. 값을 전달하면 이제 ==로 비교합니다.
숫자 ->pow(2) $n ** 2
숫자 $n->between(1, 10) 1 <= $n <= 10, 비교식의 연결
응답 ->ok() .is_ok
IP 주소 ->private(), ->loopback() .is_private, .is_loopback
JWT ->expired() .is_expired
데이터베이스 ->in_transaction() .is_in_transaction
비밀번호 ->strong() ->is_strong()
로거 ->enabled(level) ->is_enabled(level)
시간대 ->dst() ->is_dst()
캐시 ->put(key, value), ->forget(key), ->flush() ->set(key, value), ->remove(key), ->clear()
세션 ->put(key, value), ->forget(key) ->set(key, value), ->remove(key)
저장 폴더 ->path(name) ->path_of(name); .path는 폴더 자체입니다
색상 ->contrast(other) ->contrast_ratio(other)
쿼리, 모델 ->avg(column) ->average(column)
URL ->with_query(values) ->with(query: values); ->without(query, fragment)는 부분 전체를 제거합니다
날짜 ->add_years(n), ->add_months(n), ->add_days(n) ->add(years: n, months: n, days: n), weeks:도 포함; ->subtract(...)는 되돌립니다
날짜 ->add_hours(n), ->add_minutes(n) 기간: $date + 3h, $date - 45m
날짜 ->duration_since(other) $date - $other, 기간입니다
날짜 ->months_since(other), ->years_since(other) ->since(other, in: months), ->since(other, in: years)(그리고 days, weeks도)
날짜 $date + 1, $date - 1(일), $a - $b(일 수) $date + 1d 또는 ->add(days: 1); $a - $b는 이제 기간입니다
기간 ->plus(other), ->minus(other) ->add(other), ->subtract(other)
텍스트 ->trim_start(chars?), ->trim_end(chars?) ->trim(start), ->trim(chars, end)
텍스트 ->pad_left(width, char?), ->pad_right(width, char?) ->pad(width, char?, start), ->pad(width, char?)
텍스트 ->strip_prefix(text), ->strip_suffix(text) ->strip(prefix: text), ->strip(suffix: text), 또는 둘 다 한 번에
텍스트 ->before_last(text), ->after_last(text), ->last_index_of(text) ->before(text, last), ->after(text, last), ->index_of(text, last)
텍스트 ->replace_pattern(pattern, replacement) ->replace(/pattern/, replacement), 그룹에는 $1 또는 ${name}
텍스트 ->snake_case(), ->kebab_case(), ->camel_case(), ->pascal_case() ->case(snake), ->case(kebab), ->case(camel), ->case(pascal)
목록 ->find_last(fn), ->find_index(fn) ->find(fn, last), ->index_of(fn)(그리고 last도)
목록, 맵 ->sort_by(fn, desc) ->sort(by: fn, order: desc)
목록 ->max_by(fn), ->min_by(fn), ->unique_by(fn) ->max(by: fn), ->min(by: fn), ->unique(by: fn)
목록 초기값 없이 ->reduce(fn), 시작은 null 첫 번째 항목이 첫 번째 합계가 되며, ->scan()와 같습니다: [3, 5, 2]->reduce(fn(total, n) => $total + $n)는 10입니다
맵 초기값 없이 ->reduce(fn), 시작은 null 첫 번째 값이 첫 번째 합계가 되며, 목록과 같습니다: { apples: 3, pears: 5 }->reduce(fn(total, n) => $total + $n)는 8입니다
목록 ->most_common(count?) ->common(count?), 또는 가장 드문 것부터 하려면 ->common(count?, least)
숫자 -5->abs()은 -(5->abs())로 읽히며, 이는 -5입니다 숫자에 바로 붙은 마이너스는 숫자의 일부이므로 -5->abs()는 5입니다; -$x->abs()는 여전히 ->abs()의 결과를 부정합니다
JSON ->parse() ->convert(from: json)
텍스트, 응답 ->json(as?), ->yaml(), ->csv(header?, as?), ->markdown() ->convert(from: json, as?), ->convert(from: yaml), ->convert(from: csv, not header, as?), ->convert(from: markdown, to: html); ->from(type: json)는 짧은 형식입니다
모든 값 ->to_json(indented?), ->to_yaml(), 목록의 ->to_csv(headers?) ->convert(to: json, indented), ->convert(to: yaml), ->convert(to: csv, headers: [...]); ->to(type: json)는 짧은 형식입니다
문서, 마크다운, LaTeX ->html(), ->latex(), ->markdown() ->convert(to: html), ->convert(to: latex), ->convert(to: markdown)
CSV ->rows(header?, as?), ->column(at, header?, as?) ->cells(header?, as?), ->cells(column: at, header?, as?); ->cells(row: 0)는 한 행을, ->cells(columns)는 모든 열을, ->cells(row: 0, column: 'price')는 한 셀을 읽습니다. 숫자로 적힌 셀은 숫자이며, 헤더는 첫 줄에서 결정됩니다
->shapes(like:)용 마스크 layout: string = ...과 symbols: map = ...를 가진 모든 타입 type Tree extends Mask { layout: ..., symbols: { ... } }: Mask를 확장한 타입만 마스크이며, 그 멤버에는 타입이 필요 없습니다
마스크 $grid->shapes(like: Tree, rotated) $input->shapes(Tree, rotated): 마스크가 먼저 와야 하며, 텍스트, 목록, 3D 목록도 그리드처럼 동작하므로 ->grid()는 먼저 필요하지 않습니다. like:는 호출을 다시 작성하는 수정 방법이 있는 오류입니다
마스크 symbols: { '#': '#', '.': null }, 모든 문자 나열 symbols: { '.': any }: symbols에서 달리 지정하지 않으면 문자는 자기 자신과 일치하므로 바꿀 것이 없는 마스크에는 symbols가 필요 없습니다. null는 any를 작성하는 수정 방법이 있는 오류이며, '#': '#'는 제거하는 수정 방법이 있는 경고(KS6025)입니다
마스크 layout = ..., symbols = ... layout: ..., symbols: ...: 마스크의 멤버는 콜론으로 작성하며, 편집기의 수정은 =를 다시 작성합니다. 마스크에는 layout, symbols, 그리고 메서드만 들어갈 수 있습니다
목록의 목록 ->transpose() ->cells(columns)는 ->grid()나 csv처럼 읽는 모든 목록의 목록을 읽습니다: ->cells(rows), ->cells(row: 0), ->cells(column: 2), ->cells(row: 0, column: 2). 행의 길이가 달라도 됩니다. 열은 그 열에 닿지 못하는 짧은 행을 건너뜁니다