formatted_file fields and methods A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).
Fields Field Type Description .extensionstring The source file extension without the dot. .textstring The source text of the fenced value.
From KScript.Core # formatted_file ->find (text: string ) → number The zero-based source offset of the first literal match, or -1.
Parameter Takes text required string
Example
.kscript XML Copy
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->find('before') }</echo>.kscript XML Copy
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->find('before')# formatted_file ->insert (content , at?: int ) → formatted_file Returns a copy with text or source of the same format inserted at a zero-based offset. With no offset, appends.
Parameter Takes content required any value at optional int
Arguments can be named: ->insert(…, at: …).
Example
.kscript XML Copy
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->insert('# Example ', at: 0).text }</echo>.kscript XML Copy
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->insert('# Example ', at: 0).text# formatted_file ->replace (search: string , replacement: string ) → formatted_file Returns a copy with every literal match replaced.
Parameter Takes search required string replacement required string
Arguments can be named: ->replace(…, replacement: …).
Example
.kscript XML Copy
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->replace('before', 'after').text }</echo>.kscript XML Copy
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->replace('before', 'after').text# formatted_file ->save (path: string )Writes the source to a file. Adds the fence extension when the path has no extension.
Parameter Takes path required string
Example
.kscript XML Copy
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<do>$source_file->save('example.ps1')</do>.kscript XML Copy
$source_file = ```ps1
Write-Output 'before'
```
$source_file->save('example.ps1')Methods from any