Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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!');
}
}
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) {
} 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();
}
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;
}
function _saveConfig() {
ls.setItem('locally-config', lzstring.compressToUTF16( JSON.stringify(_config)) );
return true;
}
function compress(value) {
return typePrefix + 'lz-s|' + lzs.compressToUTF16(value);
}
function save(data) {
for(var key in data) {
localStorage[key] = lzString.compressToUTF16(JSON.stringify(data[key]));
}
}
compress (input: string): string {
return lzString.compressToUTF16(input)
}
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()
}
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');
}
};