-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-storage.min.js
8 lines (8 loc) · 942 Bytes
/
simple-storage.min.js
1
2
3
4
5
6
7
8
/*!
* simple-storage.js - v1.0.0
* 1k auto-casting localStorage helper
* https://github.com/john-doherty/simple-storage
* @author John Doherty <www.johndoherty.info>
* @license MIT
*/
!function(e){var t=localStorage,r={get:function(e){var r=String(t.getItem(e));if("null"===r)return null;if("undefined"!==r){if(/^[0-9.]+$/.test(r))return parseFloat(r);if(/^[-0-9]+$/.test(r))return parseInt(r,10);if("true"===r||"false"===r)return"true"===r;if("{"===r[0]||"["===r[0])try{var n=JSON.parse(r);if("object"==typeof n||Array.isArray(n))return n}catch(e){}return r}},set:function(e,r){if("string"!=typeof e)throw new TypeError("localStorage: Key must be a string");("object"==typeof r||Array.isArray(r))&&(r=JSON.stringify(r)),t.setItem(e,r)},exists:function(e){return Object.prototype.hasOwnProperty.call(t,e)},remove:function(e){t.removeItem(e)},clear:function(){t.clear()}};module&&module.exports?module.exports=r:e.simpleStorage=r}(this);