-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathls.js
48 lines (46 loc) · 1.55 KB
/
ls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//Simpler localStorage v1.3.1
//Designed for npm localstorage module, nodeJS
//Only works for pre-required localStorage module
//Include this code in your main nodeJS file:
/*
if (typeof localStorage === "undefined" || localStorage === null) {
var LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./ls');
}
var ls = require("./ls");
*/
//The node-localstorage module was not designed by me
//This is merely my way of simplifying its usage
//This Simple LocalStorage module was created by me to work with node-localstorage
module.exports = {
set: function(key, value) {
return localStorage.setItem(key, value);
},
get: function(key) {
return localStorage.getItem(key);
},
setObj: function(key, obj) {
return localStorage.setItem(key, JSON.stringify(obj));
},
getObj: function(key) {
return JSON.parse(localStorage.getItem(key));
},
exist: function(key) {
if (localStorage.getItem(key)) {
return true;
}
else {
return false;
}
},
remove: function(key) {
return localStorage.removeItem(key);
},
clear: function() {
return localStorage.clear();
},
append:function(key,value){ return localStorage.setItem(key,localStorage.getItem(key)+value); },
renameKey:function(key,newk){ let value=localStorage.getItem(key);return localStorage.setItem(newk,value); }
}
//The node-localstorage module can be found at:
//https://www.npmjs.com/package/node-localstorage