.export - macmcmeans/localDataStorage GitHub Wiki

localDataStorage.export( [mode] )

This method lets you create a JSON object representing the state of the store, which can be saved and subsequently imported. The overwrite mode is optional and, if specified, signals how existing data should be affected when the JSON is imported. When omitted, mode is set to unsafe by default, hinting that data in the export object should be treated as authoritative.

The export 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 created JSON contains: 1 - a timestamp indicating when the export was created, 2 - a keycount, 3 - the key prefix, and 4 - an array of key value pairs

EXAMPLES:

Export all eight keys in the store under the storageBackup-1 variable and hint that existing keys should be preserved: ● storageBackup-1 = localData.export( 'safe' ) --> {ts: 1653884984216, mode: 'safe', keycount: 8, prefix: 'QUnit-test', keys: Array(8)}

Export all eight keys in the store under the storageBackup-1 variable and signal that existing keys should be overwritten by default: ● storageBackup-1 = localData.export() --> {ts: 1653884984216, mode: 'unsafe', keycount: 8, prefix: 'QUnit-test', keys: Array(8)}

✨ The complement to this is import.

📝 NOTE: While the export mode is used to signal how data should be handled, it can always be overridden during an import. Only disk-based localStorage keys can be exported, not Memory Keys.