• Finds and replaces content in a single file

    Parameters

    • filePath: string

      Path to the file

    • searchPattern: string | RegExp

      Pattern to search for

    • replacement: string

      Replacement string

    • options: FindReplaceOptions = {}

      Find and replace options

    Returns Promise<OperationResult<FindReplaceResult>>

    OperationResult containing FindReplaceResult

    const result = await findAndReplaceInFile('/path/to/file.txt', 'oldText', 'newText', {
    preview: false,
    createBackups: true
    });
    if (result.success) {
    console.log(`Made ${result.data.replacements} replacements`);
    }