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.1 to 2.0.2

4

dist/index.d.ts

@@ -1,2 +0,3 @@

declare function set<T>(variable: string, value: T, ttl_ms: number): void;
declare function set<T>(variable: string, value: T, ttl_ms?: number): void;
declare function remove(variable: string): void;
declare function get<T>(variable: string): T | null;

@@ -6,3 +7,4 @@ export declare const ls: {

get: typeof get;
remove: typeof remove;
};
export default ls;

@@ -5,8 +5,13 @@ "use strict";

function set(variable, value, ttl_ms) {
const data = {
let data = {
value: value,
expires_at: Date.now() + ttl_ms,
};
if (ttl_ms) {
data.expires_at = Date.now() + ttl_ms;
}
localStorage.setItem(variable, JSON.stringify(data));
}
function remove(variable) {
localStorage.removeItem(variable);
}
function get(variable) {

@@ -31,3 +36,3 @@ const item = localStorage.getItem(variable);

}
exports.ls = { set, get };
exports.ls = { set, get, remove };
exports.default = exports.ls;
interface StoredData<T> {
value: T;
expires_at: number;
expires_at?: number;
}
function set<T>(variable: string, value: T, ttl_ms: number): void {
const data: StoredData<T> = {
function set<T>(variable: string, value: T, ttl_ms?: number): void {
let data: StoredData<T> = {
value: value,
expires_at: Date.now() + ttl_ms,
};
if (ttl_ms) {
data.expires_at = Date.now() + ttl_ms;
}
localStorage.setItem(variable, JSON.stringify(data));
}
function remove(variable: string): void {
localStorage.removeItem(variable);
}
function get<T>(variable: string): T | null {

@@ -32,3 +38,3 @@ const item = localStorage.getItem(variable);

export const ls = { set, get };
export const ls = { set, get, remove };
export default ls;
{
"name": "localstorage-ttl",
"version": "2.0.1",
"version": "2.0.2",
"description": "TS module to save data to localstorage with time to live. Data will expire after set time.",

@@ -5,0 +5,0 @@ "main": "index.ts",

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

>Version 1.x is JavaScript, version 2.x is Typescript
Updated to TS (v2) after 9yr of JS (v1) 🎉

@@ -22,11 +22,10 @@ # Install:

ls.get(variable);
ls.remove(variable);
```
to remove, just use plain js. It works in all usable browsers. http://caniuse.com/#search=localstorage
```
localStorage.removeItem(variable);
```
* ttl_ms = time to live time in ms.
if **ttl_ms** is not set it will be **without expire date** and will be there till user deletes or your other js deletes it.
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