This repository has been archived by the owner on May 16, 2024. It is now read-only.
forked from marcuswestin/store.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.only.local-storage.min.js
2 lines (2 loc) · 5.5 KB
/
store.only.local-storage.min.js
1
2
/* store.js - Copyright (c) 2010-2017 Marcus Westin */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.store=e()}}(function(){return function(){function e(n,t,r){function i(u,a){if(!t[u]){if(!n[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(o)return o(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var f=t[u]={exports:{}};n[u][0].call(f.exports,function(e){var t=n[u][1][e];return i(t||e)},f,f.exports,e,n,t,r)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}return e}()({1:[function(e,n,t){"use strict";var r=e("../src/store-engine"),i=[e("../storages/localStorage")],o=[];n.exports=r.createStore(i,o)},{"../src/store-engine":2,"../storages/localStorage":4}],2:[function(e,n,t){"use strict";function r(){var e="undefined"==typeof console?null:console;if(e){(e.warn?e.warn:e.log).apply(e,arguments)}}function i(e,n,t){t||(t=""),e&&!l(e)&&(e=[e]),n&&!l(n)&&(n=[n]);var i=t?"__storejs_"+t+"_":"",o=t?new RegExp("^"+i):null;if(!/^[a-zA-Z0-9_\-]*$/.test(t))throw new Error("store.js namespaces can only have alphanumerics + underscores and dashes");var h={_namespacePrefix:i,_namespaceRegexp:o,_testStorage:function(e){try{var n="__storejs__test__";e.write(n,n);var t=e.read(n)===n;return e.remove(n),t}catch(r){return!1}},_assignPluginFnProp:function(e,n){var t=this[n];this[n]=function(){function n(){if(t)return s(arguments,function(e,n){r[n]=e}),t.apply(i,r)}var r=u(arguments,0),i=this,o=[n].concat(r);return e.apply(i,o)}},_serialize:function(e){return JSON.stringify(e)},_deserialize:function(e,n){if(!e)return n;var t="";try{t=JSON.parse(e)}catch(r){t=e}return t!==undefined?t:n},_addStorage:function(e){this.enabled||this._testStorage(e)&&(this.storage=e,this.enabled=!0)},_addPlugin:function(e){var n=this;if(l(e))return void s(e,function(e){n._addPlugin(e)});if(!a(this.plugins,function(n){return e===n})){if(this.plugins.push(e),!p(e))throw new Error("Plugins must be function values that return objects");var t=e.call(this);if(!d(t))throw new Error("Plugins must return an object of function properties");s(t,function(t,r){if(!p(t))throw new Error("Bad plugin property: "+r+" from plugin "+e.name+". Plugins should only return functions.");n._assignPluginFnProp(t,r)})}},addStorage:function(e){r("store.addStorage(storage) is deprecated. Use createStore([storages])"),this._addStorage(e)}},v=f(h,g,{plugins:[]});return v.raw={},s(v,function(e,n){p(e)&&(v.raw[n]=c(v,e))}),s(e,function(e){v._addStorage(e)}),s(n,function(e){v._addPlugin(e)}),v}var o=e("./util"),u=o.slice,a=o.pluck,s=o.each,c=o.bind,f=o.create,l=o.isList,p=o.isFunction,d=o.isObject;n.exports={createStore:i};var g={version:"2.0.12",enabled:!1,get:function(e,n){var t=this.storage.read(this._namespacePrefix+e);return this._deserialize(t,n)},set:function(e,n){return n===undefined?this.remove(e):(this.storage.write(this._namespacePrefix+e,this._serialize(n)),n)},remove:function(e){this.storage.remove(this._namespacePrefix+e)},each:function(e){var n=this;this.storage.each(function(t,r){e.call(n,n._deserialize(t),(r||"").replace(n._namespaceRegexp,""))})},clearAll:function(){this.storage.clearAll()},hasNamespace:function(e){return this._namespacePrefix=="__storejs_"+e+"_"},createStore:function(){return i.apply(this,arguments)},addPlugin:function(e){this._addPlugin(e)},namespace:function(e){return i(this.storage,this.plugins,e)}}},{"./util":3}],3:[function(e,n,t){(function(e){"use strict";function t(e,n){return function(){return n.apply(e,Array.prototype.slice.call(arguments,0))}}function r(e,n){return Array.prototype.slice.call(e,n||0)}function i(e,n){u(e,function(e,t){return n(e,t),!1})}function o(e,n){var t=a(e)?[]:{};return u(e,function(e,r){return t[r]=n(e,r),!1}),t}function u(e,n){if(a(e)){for(var t=0;t<e.length;t++)if(n(e[t],t))return e[t]}else for(var r in e)if(e.hasOwnProperty(r)&&n(e[r],r))return e[r]}function a(e){return null!=e&&"function"!=typeof e&&"number"==typeof e.length}function s(e){return e&&"[object Function]"==={}.toString.call(e)}function c(e){return e&&"[object Object]"==={}.toString.call(e)}var f=function(){return Object.assign?Object.assign:function(e,n,t,r){for(var o=1;o<arguments.length;o++)i(Object(arguments[o]),function(n,t){e[t]=n});return e}}(),l=function(){if(Object.create)return function(e,n,t,i){var o=r(arguments,1);return f.apply(this,[Object.create(e)].concat(o))};var e=function(){};return function(n,t,i,o){var u=r(arguments,1);return e.prototype=n,f.apply(this,[new e].concat(u))}}(),p=function(){return String.prototype.trim?function(e){return String.prototype.trim.call(e)}:function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}}(),d="undefined"!=typeof window?window:e;n.exports={assign:f,create:l,trim:p,bind:t,slice:r,each:i,map:o,pluck:u,isList:a,isFunction:s,isObject:c,Global:d}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,n,t){"use strict";function r(){return f.localStorage}function i(e){return r().getItem(e)}function o(e,n){return r().setItem(e,n)}function u(e){for(var n=r().length-1;n>=0;n--){var t=r().key(n);e(i(t),t)}}function a(e){return r().removeItem(e)}function s(){return r().clear()}var c=e("../src/util"),f=c.Global;n.exports={name:"localStorage",read:i,write:o,each:u,remove:a,clearAll:s}},{"../src/util":3}]},{},[1])(1)});