Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

localstorage-ttl

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-ttl - npm Package Compare versions

Comparing version 2.0.9 to 2.0.10

40

dist/index.js
function set(variable, value, ttl_ms) {
let data = {
value: value,
};
if (ttl_ms) {
data.expires_at = Date.now() + ttl_ms;
if (localStorage) {
let data = {
value: value,
};
if (ttl_ms) {
data.expires_at = Date.now() + ttl_ms;
}
localStorage.setItem(variable, JSON.stringify(data));
}
localStorage.setItem(variable, JSON.stringify(data));
}
function remove(variable) {
localStorage.removeItem(variable);
if (localStorage) {
localStorage.removeItem(variable);
}
}
function get(variable) {
const item = localStorage.getItem(variable);
if (item) {
try {
const data = JSON.parse(item);
if (data.expires_at && data.expires_at < Date.now()) {
if (localStorage) {
const item = localStorage.getItem(variable);
if (item) {
try {
const data = JSON.parse(item);
if (data.expires_at && data.expires_at < Date.now()) {
localStorage.removeItem(variable);
return null;
} else {
return data.value;
}
} catch (e) {
localStorage.removeItem(variable);
return null;
} else {
return data.value;
}
} catch (e) {
localStorage.removeItem(variable);
}

@@ -27,0 +33,0 @@ }

{
"name": "localstorage-ttl",
"version": "2.0.9",
"version": "2.0.10",
"description": "TS module to save data to localstorage with time to live. Data will expire after set time.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc