-
Notifications
You must be signed in to change notification settings - Fork 6
/
rockstage.min.js
4 lines (4 loc) · 1.39 KB
/
rockstage.min.js
1
2
3
4
/*! rockstage.js - v0.0.5 - 2012-12-14
* http://layzie.github.com/rockstage_js
* Copyright (c) 2012 HIRAKI Satoru; Licensed MIT */
(function(e,t){"use strict";function n(e,n){var r=Object.prototype.toString.call(n).slice(8,-1);return n!==t&&n!==null&&r===e}function r(e,r){var i=r!=="clear()"?"2nd ":"",s;if(n("Boolean",e)||e===t)return s=e===!0||e===t?localStorage:sessionStorage,s;throw new Error("RS."+r+": "+i+"argument should be boolean")}function i(e,t){var i=r(t,"put()");if(!n("Object",e)||!!n("Array",e))throw new Error("RS.put(): 1st argument should be object");for(var s in e)e.hasOwnProperty(s)&&i.setItem(s,JSON.stringify(e[s]))}function s(e,t){var i=r(t,"get()"),s=i.getItem(e);if(n("String",e))return s?JSON.parse(s):console.log("RS.get(): This key is not in storage");throw new Error("RS.get(): 1st argument should be string")}function o(e,t){var i=r(t,"remove()"),s=i.getItem(e);n("String",e)&&(s?i.removeItem(e):console.log("RS.remove(): This key is not in storage"))}function u(e){var t=r(e,"clear()");t.clear()}function a(e,t){var i=r(t,"is()"),s=i.getItem(e);if(n("String",e))return s?!0:!1;throw new Error("RS.is(): 1st argument should be strings")}function f(e){var t=r(e,"length()");return t.length}(function(){if(!e.localStorage||!e.sessionStorage)throw new Error("RS: This browser have no storage.");n("Undefined",e.RS)&&(e.RS={}),e.RS={put:i,get:s,remove:o,clear:u,is:a,length:f}})()})(this);