-
-
Save mahizsas/84ce0c565ac9939c3ce4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular.module('app') | |
.factory('Storage', [function () { | |
var fn = {}; | |
fn.has = function (key) { | |
var value = window.localStorage.getItem(key); | |
return !!value; | |
} | |
fn.get = function (key) { | |
if (!fn.has(key)) return false; | |
return JSON.parse(window.localStorage.get(key)); | |
} | |
fn.set = function (key, value) { | |
var v = (typeof value === 'object') ? JSON.stringify(value) : value; | |
window.localStorage.set(key, v); | |
} | |
return fn; | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment