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.8 to 2.0.9

8

dist/index.d.ts

@@ -5,7 +5,7 @@ declare function set<T>(variable: string, value: T, ttl_ms?: number): void;

export declare const ls: {
set: typeof set;
get: typeof get;
remove: typeof remove;
set: typeof set;
get: typeof get;
remove: typeof remove;
};
export default ls;
//# sourceMappingURL=index.d.ts.map
//# sourceMappingURL=index.d.ts.map
function set(variable, value, ttl_ms) {
let data = {
value: value,
};
if (ttl_ms) {
data.expires_at = Date.now() + ttl_ms;
}
localStorage.setItem(variable, JSON.stringify(data));
let data = {
value: value,
};
if (ttl_ms) {
data.expires_at = Date.now() + ttl_ms;
}
localStorage.setItem(variable, JSON.stringify(data));
}
function remove(variable) {
localStorage.removeItem(variable);
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()) {
localStorage.removeItem(variable);
return null;
}
else {
return data.value;
}
}
catch (e) {
localStorage.removeItem(variable);
}
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;
}
return null;
}
export const ls = { set, get, remove };
export default ls;
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
{
"name": "localstorage-ttl",
"version": "2.0.8",
"version": "2.0.9",
"description": "TS module to save data to localstorage with time to live. Data will expire after set time.",

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

"build": "tsc",
"prepublishOnly": "npm run build"
"check-exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
"format": "prettier --write .",
"prepublishOnly": "npm run build && npm run format"
},

@@ -27,2 +29,4 @@ "repository": {

"devDependencies": {
"@arethetypeswrong/cli": "^0.16.4",
"prettier": "^3.3.3",
"typescript": "^5.6.2"

@@ -29,0 +33,0 @@ },

@@ -6,3 +6,3 @@ # localstorage-ttl

Updated to TS (v2) after 9yr of JS (v1) 🎉
Updated to TS (v2) after 9yr of JS (v1) 🎉

@@ -25,7 +25,6 @@ # Install:

* ttl_ms = time to live time in ms.
- ttl_ms = time to live time in ms.
if **ttl_ms** is not set it will stay **without expire date** and will be there till deleted.
You may contact me here: https://lukasliesis.com/
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