Options
All
  • Public
  • Public/Protected
  • All
Menu

Class default<T>

Type parameters

  • T: object

Hierarchy

  • default

Index

Constructors

  • new default<T>(filePath: string, defaultData?: T, options?: Options): default<T>
  • Init this class

    Type parameters

    • T: object

    Parameters

    • filePath: string

      the path of the JSON file

    • Optional defaultData: T

      the default data of the JSON file

    • Optional options: Options

      Some options of this class

    Returns default<T>

Properties

_data: T
data: T
filePath: string
options: Options

Methods

  • calcDiff(data: T, fileContent: T): T
  • To calculate the differences between the current data (saved in the JSON file) and the new data (user input)

    Parameters

    • data: T

      User input data

    • fileContent: T

    Returns T

  • dataSet(target: T, props: string | symbol, value: any, receiver: any): boolean
  • This function will run when the data update

    Parameters

    • target: T
    • props: string | symbol
    • value: any
    • receiver: any

    Returns boolean

    boolean

  • getData(): T
  • To get a copy of data

    Returns T

    a copy of data

  • getFileContent(): Promise<false | T>
  • To get the content of the JSON file

    Returns Promise<false | T>

  • getFileContentSync(): false | T
  • To get the content of the JSON file

    Returns false | T

    data or false

  • read(): Promise<boolean>
  • Update the data from JSON file manually

    Returns Promise<boolean>

    whether the update is successful

  • readSync(): boolean
  • Update the data from JSON file manually

    Returns boolean

    whether the update is successful

  • updateData(data: T): void
  • Use Proxy to rebind the data

    Parameters

    • data: T

      data

    Returns void

  • updateFile(): Promise<boolean>
  • To update the JSON file manually

    Returns Promise<boolean>

  • updateFileSync(): void
  • To update the JSON file manually

    Returns void

  • write(): Promise<boolean>
  • To update the JSON file manually

    Returns Promise<boolean>

    if this function return true, it means the data is updated successfully

  • writeSync(): void
  • To update the JSON file manually

    Returns void

Generated using TypeDoc