Function updateFileSafe

  • Updates a text file based on a provided update function. The update function takes the file's current source string as a parameter and should return a string. If the file does not exist or cannot be read, the defaultContent will be used instead.

    Parameters

    • filepath: string

      The path to the file to update.

    • update: ((src) => string | Promise<string>)

      The function to update the file. Takes the current source string as a parameter and should return a string.

        • (src): string | Promise<string>
        • Parameters

          • src: string

          Returns string | Promise<string>

    • defaultContent: string = ''

      The default string to use if the file cannot be read.

    • encoding: BufferEncoding = 'utf8'

      The encoding to use when reading and writing the file.

    Returns Promise<void>

Generated using TypeDoc