.import - macmcmeans/localDataStorage GitHub Wiki

localDataStorage.import( [mode] )

This method reads an exported JSON object. The overwrite mode is optional and, if specified, determines how existing data in the store will be affected by the import. When omitted, mode is defined by the value present in the export object.

The import mode can have one of two possible values: safe - imported data cannot overwrite existing keys but will create new keys as necessary (identical to using softset) unsafe - imported data will overwrite any keys with matching names and will also make new keys as necessary (identical to using set)

The import is only effective when the key prefix defined in the JSON object matches the prefix of the store in-use. You cannot import keys from a different namespaced store.

When importing data, existing keys may be overwritten. If this happens, a key's prior value cannot be retrieved.

EXAMPLES:

Import an eight-key JSON assigned as storageBackup-1 ensuring existing keys are preserved: ● localData.import( 'storageBackup-1', 'safe' ) --> Importing upto 8 keys from Sun May 29 2022 23:56:37 GMT-0400 (Eastern Daylight Time)... --> One key imported

Import an eight-key JSON assigned as storageBackup-1 ensuring the export values are authoritative: ● localData.import( 'storageBackup-1', 'unsafe' ) --> Overwriting 8 keys from Sun May 29 2022 23:56:37 GMT-0400 (Eastern Daylight Time)... --> 8 keys imported

🌐 This method may fire events allowing you to monitor key changes.

✨ The complement to this is export.