formatted_file 필드와 메서드 필드는 값에 관한 단순한 정보로, 대괄호 없이 점으로 읽어요: $value.name. 메서드는 인수를 받거나 작업을 수행하며, ->로 호출하거나 $value->name(arguments)처럼 값을 파이프로 넘겨서 호출해요: $value |> name(arguments).
필드 필드 타입 설명 .extensionstring 점 없이 나타낸 원본 파일 확장자예요. .textstring 감싸진 값의 원본 텍스트예요.
KScript.Core에서 제공해요. # formatted_file ->find (text: string ) → number 문서 소스에서 리터럴이 처음 일치하는 위치의 0부터 시작하는 오프셋이며, 없으면 -1입니다.
예시
.kscript XML 복사
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->find('before') }</echo>.kscript XML 복사
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->find('before')# formatted_file ->insert (content , at?: int ) → formatted_file 같은 형식의 텍스트나 원본을 0부터 시작하는 오프셋 위치에 넣은 복사본을 반환해요. 오프셋을 생략하면 끝에 추가해요.
매개변수 받는 값 content 필수 모든 값 at 선택 int
인수는 이름을 붙여 전달할 수 있습니다: ->insert(…, at: …).
예시
.kscript XML 복사
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->insert('# Example ', at: 0).text }</echo>.kscript XML 복사
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->insert('# Example ', at: 0).text# formatted_file ->replace (search: string , replacement: string ) → formatted_file 리터럴 일치 항목을 모두 바꾼 복사본을 반환해요.
인수는 이름을 붙여 전달할 수 있습니다: ->replace(…, replacement: …).
예시
.kscript XML 복사
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->replace('before', 'after').text }</echo>.kscript XML 복사
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->replace('before', 'after').text# formatted_file ->save (path: string )소스를 파일로 써요. 경로에 확장자가 없으면 fence 확장자를 붙여요.
예시
.kscript XML 복사
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<do>$source_file->save('example.ps1')</do>.kscript XML 복사
$source_file = ```ps1
Write-Output 'before'
```
$source_file->save('example.ps1')any의 메서드