فهرست منبع

Add localstorage.js

Daniel Supernault 7 سال پیش
والد
کامیت
1a423ce139
1فایلهای تغییر یافته به همراه33 افزوده شده و 0 حذف شده
  1. 33 0
      resources/assets/js/components/localstorage.js

+ 33 - 0
resources/assets/js/components/localstorage.js

@@ -0,0 +1,33 @@
+window.ls = {};
+
+window.ls.get = function(key) {
+  return JSON.parse(localStorage.getItem(key));
+}
+
+
+window.ls.set = function(key, val) {
+  try {
+    localStorage.setItem(key, JSON.stringify(val));
+    return true;
+  } catch(e) {
+    return false;
+  }
+}
+
+window.ls.del = function(key) {
+  try {
+    localStorage.removeItem(key);
+    return true;
+  } catch(e) {
+    return false;
+  }
+}
+
+window.ls.clear = function() {
+  try {
+    localStorage.clear();
+    return true;
+  } catch(e) {
+    return false;
+  }
+}