Campos e métodos de formatted_file Um campo é um dado simples sobre o valor, lido com um ponto e sem colchetes: $value.name. Um método recebe argumentos ou executa alguma ação, e é chamado com ->: $value->name(arguments), ou com o valor passado por pipe: $value |> name(arguments).
Campos Campo Tipo Descrição .extensionstring A extensão do arquivo de origem, sem o ponto. .textstring O texto de origem do valor delimitado.
Do KScript.Core # formatted_file ->find (text: string ) → number O deslocamento de base zero, no código-fonte, da primeira correspondência literal, ou -1.
Parâmetro Recebe text obrigatório string
Exemplo
.kscript XML Copiar
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->find('before') }</echo>.kscript XML Copiar
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->find('before')# formatted_file ->insert (content , at?: int ) → formatted_file Retorna uma cópia com texto ou código-fonte do mesmo formato inserido em um deslocamento baseado em zero. Sem deslocamento, acrescenta ao final.
Parâmetro Recebe content obrigatório qualquer valor at opcional int
Os argumentos podem ser nomeados: ->insert(…, at: …).
Exemplo
.kscript XML Copiar
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->insert('# Example ', at: 0).text }</echo>.kscript XML Copiar
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->insert('# Example ', at: 0).text# formatted_file ->replace (search: string , replacement: string ) → formatted_file Retorna uma cópia com cada correspondência literal substituída.
Parâmetro Recebe search obrigatório string replacement obrigatório string
Os argumentos podem ser nomeados: ->replace(…, replacement: …).
Exemplo
.kscript XML Copiar
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<echo>{ $source_file->replace('before', 'after').text }</echo>.kscript XML Copiar
$source_file = ```ps1
Write-Output 'before'
```
echo $source_file->replace('before', 'after').text# formatted_file ->save (path: string )Grava a origem em um arquivo. Adiciona a extensão fence quando o caminho não tem extensão.
Parâmetro Recebe path obrigatório string
Exemplo
.kscript XML Copiar
<let name="source_file" value="```ps1
Write-Output 'before'
```" />
<do>$source_file->save('example.ps1')</do>.kscript XML Copiar
$source_file = ```ps1
Write-Output 'before'
```
$source_file->save('example.ps1')Métodos de qualquer tipo