• Replace with Contents of a File

    Type Parameters

    • Options extends {
          async?: boolean;
      }

    Parameters

    • file: PathLike
    • search: string | RegExp
    • replace: string
    • Optional options: Options

    Returns Options["async"] extends false
        ? string
        : Promise<string>

    Example

    import { filesystem } from "@rjweb/utils"
    import fs from "fs"

    await fs.promises.writeFile('./file.txt', 'Hello World sir')
    console.log(await fs.promises.readFile('./file.txt', 'utf8')) // Hello World sir

    await filesystem.replace('./file.txt', 'Hello World', 'Bye World', { async: true }) // Bye World sir

    console.log(await fs.promises.readFile('./file.txt', 'utf8')) // Bye World sir

    Since

    1.12.20

    Supports

    nodejs