Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TadData

TadData (Library)

This is a class that allows for the saving of data persistently. The data is stored in a JSON file in the Drafts iCloud area, meaning it is accessible across devices, and persists between runs of actions.

Hierarchy

  • TadData

Index

Constructors

constructor

  • new TadData(p_strPath: string): TadData
  • Creates new instance of TadData class.

    Parameters

    • p_strPath: string

      the location of the associated JSON data file in the Drafts iCloud files area.

      // Example
      objDataStore1 = new TadData("/Library/Scripts/ds1.json");
      

    Returns TadData

Methods

TA_addition

  • TA_addition(p_strPath: string, p_numValue: number): number
  • Add a numeric value to the value of the specified key, which can be expressed as a path. Returns true if the data file was successfully written, otherwise false.

    Parameters

    • p_strPath: string

      the period separated JSON-style path that uniquely identifies a key-value pair for the data object.

    • p_numValue: number

      the number to add to the value.

      // Example
      objDataStore1.TA_addition("bar.foo", 10);
      // This wll add 10 to the value associated with the key `foo` held within root key `bar`.
      

    Returns number

TA_delete

  • TA_delete(): boolean
  • Delete a key value pair to file, where the key can be expressed as a path. The key path will interpret periods as path separators (it isn't good practice to use periods in your variable names in any case). Returns true if the data file was successfully written, otherwise false.

    Returns boolean

TA_load

  • TA_load(): Boolean
  • Load data from file. The location of the data files is specified during the class instance construction. The data is merged into the class instance, but typically this would never need to be called at any other time other than creation, and it is called as part of the construction process. Returns true if the file exists, otherwise false.

    // Example
    objDataStore1 = new TadData("/Library/Scripts/ds1.json");
    objDataStore1.TA_load();
    

    Returns Boolean

TA_prefix

  • TA_prefix(p_strPath: string, p_strPrefix: string): string
  • Add a prefix to the value of the specified key, which can be expressed as a path. Returns true if the data file was successfully written, otherwise false.

    Parameters

    • p_strPath: string

      the period separated JSON-style path that uniquely identifies a key-value pair for the data object.

    • p_strPrefix: string

      the text to add to the start of the value.

      // Example
      objDataStore1.TA_prefix("bar.foo", "baz");
      // This wll prefix the value associated with the key `foo` held within root key `bar` with "baz".
      

    Returns string

TA_save

  • TA_save(p_strPath: string, p_objValue: object): boolean
  • Save a key value pair to file, where the key can be expressed as a path. The key path will interpret periods as path separators (it isn't good practice to use periods in your variable names in any case), and can build structures automatically. Returns true if the data file was successfully written, otherwise false.

    Parameters

    • p_strPath: string

      the period separated JSON-style path that uniquely identifies a key-value pair for the data object.

    • p_objValue: object

      the value to set the property value to.

      // Example
      objDataStore1 = new TadData("/Library/Scripts/ds1.json");
      objDataStore1.TA_save("foo", "bar");
      objDataStore1.TA_save("bar.foo", "baz");
      

      The resulting JSON will then look like this:

      {
        "foo" : "bar",
        "bar" : {
          "foo" : "baz"
        },
        "dataPath" : "\/Library\/Scripts\/ds1.json"
      }
      

    Returns boolean

TA_store

  • TA_store(): Boolean
  • Store the current object properties in the instance's specified data file. The data file location is specified by the object's dataPath property, which is set at the construction stage. Returns true if the file was successfully written, otherwise false.

    // Example
    objDataStore1 = new TadData("/Library/Scripts/ds1.json");
    objDataStore1.newValue = true;
    objDataStore1.TA_store();
    

    Returns Boolean

TA_subtraction

  • TA_subtraction(p_strPath: string, p_numValue: number): number
  • Deduct a numeric value from the value of the specified key, which can be expressed as a path. Returns true if the data file was successfully written, otherwise false.

    Parameters

    • p_strPath: string

      the period separated JSON-style path that uniquely identifies a key-value pair for the data object.

    • p_numValue: number

      the number to subtract from the value.

      // Example
      objDataStore1.TA_subtraction("bar.foo", 5;
      // This wll add 10 to the value associated with the key `foo` held within root key `bar`.
      

    Returns number

TA_suffix

  • TA_suffix(p_strPath: string, p_strSuffix: string): string
  • Add a suffix to the value of the specified key, which can be expressed as a path. Returns true if the data file was successfully written, otherwise false.

    Parameters

    • p_strPath: string

      the period separated JSON-style path that uniquely identifies a key-value pair for the data object.

    • p_strSuffix: string

      the text to add to the end of the value.

      // Example
      objDataStore1.TA_suffix("bar.foo", "baz");
      // This wll sufffix the value associated with the key `foo` held within root key `bar` with "baz".
      

    Returns string

TA_value

  • TA_value(p_strPath: string): object
  • Return the value of a key, which can be expressed as a path.

    Parameters

    • p_strPath: string

      the period separated JSON-style path that uniquely identifies a key-value pair for the data object.

      // Example
      alert(objDataStore1.TA_value("bar.foo"));
      // This wll return the value associated with the key `foo` held within root key `bar`.
      

    Returns object