How to use the lz-string.decompressFromUTF16 function in lz-string

To help you get started, we’ve selected a few lz-string examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrollback / scrollback / persistence / persistence-client.js View on Github external
core.on('boot', function (changes, next) {
		var entities={}, textRanges={}, texts={}, threadRanges={}, threads={}, sid, key, o;

		sid = changes.session;
		if(!sid) {
			console.error('boot@persistence: Session ID is missing.');
		}

		/* 1. Retrieve all the data from localStorage */

		for(key in localStorage) {
			if(key.indexOf(sid) !== 0) continue;
			try {
				o = JSON.parse(lzString.decompressFromUTF16(localStorage[key]));
			} catch(e) {
				console.error('Could not parse localStorage item ' + key);
				continue;
			}
			key = key.split(':');
			switch(key[1]) {
				case 'e':
					entities[o.id? o.id: o.room + '_' + o.user] = o;
					break;
				case 'T':
					(textRanges[key[2]] = textRanges[key[2]] || []).push(o);
					o.items = [];
					break;
				case 't':
					(texts[key[2]] = texts[key[2]] || []).push(o);
					break;
github SEL-Columbia / dokomoforms / dokomoforms / static / Facilities.js View on Github external
db.get(id).then(function(facilitiesDoc) {
            console.log("Get:", id);
            var facilitiesLZ = facilitiesDoc.facilities[0]; // Why an array? WHO KNOWS
            var facilities = JSON.parse(LZString.decompressFromUTF16(facilitiesLZ));
            p.fulfill(facilities);
        }).catch(function (err) {
            console.log("Failed to Get:", err);
github ozantunca / locally / src / locally.js View on Github external
while (l--) {
      _keys[l] = ls.key(l);
      _config[_keys[l]] = _config[_keys[l]] || {};

      // _compressAll is given and value is not
      // compressed then compress the value
      if (_compressAll && !_config[_keys[l]].c) {
        _config[_keys[l]].c = true;
        ls.setItem(_keys[l], lzstring.compressToUTF16( ls.getItem(_keys[l]) ));
      }
      // if the value is compressed and
      // compressAll is not given then decompress
      // current value.
      else if (!_compressAll && _config[_keys[l]].c) {
        delete _config[_keys[l]].c;
        ls.setItem(_keys[l], lzstring.decompressFromUTF16( ls.getItem(_keys[l]) ));
      }

      if (_config[_keys[l]].ttl) {
        _setTimeout(_keys[l], _config[_keys[l]].ttl - Date.now());
      }
    }

    // Exclude locally-config from _keys array
    if (_keys.indexOf('locally-config') > -1) {
      _keys.splice(_keys.indexOf('locally-config'), 1);
    }
  }
github ozantunca / locally / src / locally.js View on Github external
// custom options
    options = options || {};
    _compressAll = options.compress;

    // load current localStorage state
    _config = ls.getItem('locally-config');

    // start anew if no config
    if (!_config) {
      _config = {};

      // reads localstorage and updates config
      _rebuildConfig();
    }
    else {
      var deconfig = lzstring.decompressFromUTF16(_config);

      try {
        _config = JSON.parse(deconfig || _config);
      } catch (e) {
        if (!!deconfig) {
          try {
            _config = JSON.parse(_config);
          } catch (e) {
            throw new Error('Locally: config is corrupted');
          }
        } else throw new Error('Locally: config is corrupted');
      }

      // reads localstorage and updates config
      _rebuildConfig();
    }
github jsbin / jsbin / lib / middleware.js View on Github external
req.body.compressed.split(',').forEach(function (key) {
        req.body[key] = LZString.decompressFromUTF16(req.body[key]);
      });
    }
github channel / channel.github.io / app / src / scripts / formatting.js View on Github external
export function parseDocument(serializedDocument, format, compression) {
  if (format == 'markdown' && compression == 'lz-string-valid-utf16') {
    return marked(LZString.decompressFromUTF16(serializedDocument));
  }
  else {
    throw new Error('Invalid document');
  }
}
github marcel-dancak / bass-app / src / core / local-storage.js View on Github external
function readData (key) {
  let data = localStorage.getItem(key)
  if (data) {
    if (!data.startsWith('{')) {
      data = LZString.decompressFromUTF16(data)
    }
    return JSON.parse(data)
  }
}
github madou / armory-app / src / lib / localStorage / index.js View on Github external
export function get(key: string): ?string {
  const compressed = localStorage.getItem(makeKey(key));
  return decompressFromUTF16(compressed);
}
github aesy / reddit-comment-highlights / src / storage / CompressedStorage.ts View on Github external
private decompress(data: string | null): T | null {
        if (data === null) {
            return null;
        }

        return JSON.parse(decompressFromUTF16(data));
    }
}