Function mapping

  • mapping<T>(file: string, fallback?: T, write_cb?: ((data: T, changes: number) => void)): T
  • Mapping a file.

    Returns

    The mapped value.

    Example

    import { mapping } from "file-mapping";

    const data = mapping("./data.json", {});

    data.name = "Jacob";
    data.age = 19;

    // Then, the file should be write automatically and only once.

    Type Parameters

    • T

    Parameters

    • file: string

      The path to the file.

    • Optional fallback: T

      The fallback value to use if the file is not existing at the beginning.

    • Optional write_cb: ((data: T, changes: number) => void)

      The callback to trigger when the file is written.

        • (data: T, changes: number): void
        • Parameters

          • data: T
          • changes: number

          Returns void

    Returns T

Generated using TypeDoc