Class AbstractJsonFileSection<Val>Abstract

A class that represents a section of the JSON file used as a simple database.

Type Parameters

Hierarchy

Constructors

Properties

defaultValues: Record<string, Val> = {}

The default values for the section.

The parent JsonFile instance.

isInitialized: boolean = false

Indicates whether the section has been initialized.

keysAreFixed: boolean

Indicates whether the keys in the section are fixed.

name: string

The name of the section.

prefixBaseString: string

The base string used as a prefix for the section.

Accessors

Methods

  • Deletes the value associated with the specified key.

    Parameters

    • key: string

      The key to delete.

    • save: boolean = true

      Indicates whether to save the section after deleting the value.

    Returns void

  • Edits the values in the section using a text editor.

    Parameters

    • Optional editor: string

      The text editor to use. If not specified, the default text editor command will be used.

    Returns void

  • Gets the value associated with the specified key.

    Type Parameters

    • T = Val

    Parameters

    • key: string

      The key to get the value for.

    Returns T

    The value associated with the key.

  • Initializes the section.

    Parameters

    • Optional save: boolean

      Indicates whether to save the section after initialization.

    Returns string | void

    A string if an error occurred during initialization, otherwise void.

  • Gets the object path prefix as dot-separated keys for this section of the JSON file database.

    Parameters

    • Optional key: string

      An optional key to append to the prefix path.

    Returns string

    The object path prefix.

    Throws

    An error if the keys are fixed and the specified key does not exist in the default values.

  • Resets the value associated with the specified key to its default value.

    Parameters

    • key: string

      The key to reset.

    • save: boolean = true

      Indicates whether to save the section after resetting the value.

    Returns void

  • Resets all the values in the section to their default values.

    Parameters

    • save: boolean = true

      Indicates whether to save the section after resetting the values.

    Returns void

  • Sets the value associated with the specified key.

    Parameters

    • key: string

      The key to set the value for.

    • value: Val

      The value to set.

    • save: boolean = true

      Indicates whether to save the section after setting the value.

    Returns void

  • Sets all the values in the section.

    Parameters

    • values: Record<string, Val>

      The values to set.

    • save: boolean = true

      Indicates whether to save the section after setting the values.

    Returns void

  • Updates the value associated with the specified key.

    Parameters

    • key: string

      The key to set the value for.

    • callback: ((val, key) => Val)

      The callback function that returns the new value.

        • (val, key): Val
        • Parameters

          • val: Val
          • key: string

          Returns Val

    • save: boolean = true

      Indicates whether to save the section after setting the value.

    Returns void

Generated using TypeDoc