How to use the lz-string.compressToUTF16 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 madou / armory-app / src / lib / localStorage / index.js View on Github external
export function set(key: string, value: string) {
  const compressed = compressToUTF16(value);
  try {
    localStorage.setItem(makeKey(key), compressed);
  } catch (e) {
    // TODO: How do we want to handle local storage
    // being full? We could clear everything and
    // start over - but perhaps that's not right
    // to consumers using the embeds.

    // eslint-disable-next-line
    console.error('Local storage is full!');
  }
}
github ozantunca / locally / src / locally.js View on Github external
function _rebuildConfig() {
    var l = ls.length;
    _keys = new Array(l);

    // Cache localStorage keys for faster access
    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) {
github ozantunca / locally / src / locally.js View on Github external
} else if (_config[key].ttl) {
      _clearTimeout(key);
    }

    // LocalStorage saves and returns values as strings.
    // Type of values will be saved so that values will be
    // parsed to their original type.
    var res = _getType(value);

    value = res.value;
    _config[key].t = res.type;

    // compression
    if (options.compress || _compressAll) {
      _config[key].c = 1;
      value = lzstring.compressToUTF16(value.toString());
    }

    key = String(key);
    value = String(value);

    ls.setItem(key, value);
    _saveConfig();
  }
github igorski / efflux-tracker / src / utils / storage-util.js View on Github external
function compress( string ) {
    let compressedString;
    try {
        compressedString = LZString.compressToUTF16( string );
    }
    catch ( e ) {
        return string;
    }
    /*
    console.log(
        "Compressed " + string.length + " to " + compressedString.length + " (" +
        (( compressedString.length / string.length ) * 100 ).toFixed( 2 ) + "% of original size)"
    );
    */
    return compressedString;
}
github ozantunca / locally / src / locally.js View on Github external
function _saveConfig() {
    ls.setItem('locally-config', lzstring.compressToUTF16( JSON.stringify(_config)) );
    return true;
  }
github anomalylabs / streams-platform / resources / js / utils / storage.js View on Github external
function compress(value) {
    return typePrefix + 'lz-s|' + lzs.compressToUTF16(value);
}
github scrollback / scrollback / persistence / persistence-client.js View on Github external
function save(data) {
	for(var key in data) {
		localStorage[key] = lzString.compressToUTF16(JSON.stringify(data[key]));
	}
}
github DFEAGILEDEVOPS / MTC / tslib / src / compression-service.ts View on Github external
compress (input: string): string {
    return lzString.compressToUTF16(input)
  }
github s-KaiNet / sp-rest-explorer / az-funcs / GenerateMetadata / index.ts View on Github external
publicAccessLevel: 'blob'
  })

  await createBlockBlobFromTextAsync(ContainerApiFilesName, `${Utils.generateWeekBlobName(now)}.xml`, result)
  await createBlockBlobFromTextAsync(ContainerApiFilesName, `${Utils.generateMonthBlobName(now)}.xml`, result)

  context.bindings.latestXml = result

  let parser = new MetadataParser(result)
  let parsed = await parser.parseMetadata()

  await createBlockBlobFromTextAsync(ContainerApiFilesName, `${Utils.generateWeekBlobName(now)}.json`, JSON.stringify(parsed, null, 4))
  await createBlockBlobFromTextAsync(ContainerApiFilesName, `${Utils.generateMonthBlobName(now)}.json`, JSON.stringify(parsed, null, 4))

  context.bindings.latestJson = JSON.stringify(parsed, null, 4)
  context.bindings.latestZippedJson = compressToUTF16(JSON.stringify(parsed))

  context.log.info('Finished generation')
  context.done()
}
github source-academy / cadet-frontend / src / localStorage.ts View on Github external
export const saveState = (state: IState) => {
  try {
    const stateToBeSaved: ISavedState = {
      session: {
        accessToken: state.session.accessToken,
        refreshToken: state.session.refreshToken,
        role: state.session.role,
        name: state.session.name
      },
      playgroundEditorValue: state.workspaces.playground.editorValue,
      playgroundIsEditorAutorun: state.workspaces.playground.isEditorAutorun
    };
    const serialized = compressToUTF16(JSON.stringify(stateToBeSaved));
    localStorage.setItem('storedState', serialized);
  } catch (err) {
    showWarningMessage('Error saving to local storage');
  }
};