forked from marcuswestin/store.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.modern.min.js
2 lines (2 loc) · 7.26 KB
/
store.modern.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 t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.store=e()}}(function(){return function e(t,r,n){function o(a,s){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[a]={exports:{}};t[a][0].call(f.exports,function(e){var r=t[a][1][e];return o(r?r:e)},f,f.exports,e,t,r,n)}return r[a].exports}for(var i="function"==typeof require&&require,a=0;a<n.length;a++)o(n[a]);return o}({1:[function(e,t,r){"use strict";var n=e("../src/store-engine"),o=[e("../storages/localStorage"),e("../storages/sessionStorage"),e("../storages/cookieStorage"),e("../storages/memoryStorage")],i=[];t.exports=n.createStore(o,i)},{"../src/store-engine":2,"../storages/cookieStorage":4,"../storages/localStorage":5,"../storages/memoryStorage":6,"../storages/sessionStorage":7}],2:[function(e,t,r){"use strict";function n(e,t){var r={_seenPlugins:[],_namespacePrefix:"",_namespaceRegexp:null,_legalNamespace:/^[a-zA-Z0-9_\-]+$/,_storage:function(){if(!this.enabled)throw new Error("store.js: No supported storage has been added! Add one (e.g store.addStorage(require('store/storages/cookieStorage')) or use a build with more built-in storages (e.g https://github.com/marcuswestin/store.js/tree/master/dist/store.legacy.min.js)");return this._storage.resolved},_testStorage:function(e){try{var t="__storejs__test__";e.write(t,t);var r=e.read(t)===t;return e.remove(t),r}catch(n){return!1}},_assignPluginFnProp:function(e,t){var r=this[t];this[t]=function(){function t(){if(r){var e=r.apply(o,t.args);return delete t.args,e}}var n=Array.prototype.slice.call(arguments,0),o=this,i=[t].concat(n);return t.args=n,e.apply(o,i)}},_serialize:function(e){return JSON.stringify(e)},_deserialize:function(e,t){if(!e)return t;var r="";try{r=JSON.parse(e)}catch(n){r=e}return void 0!==r?r:t}},n=s(r,l);return a(e,function(e){n.addStorage(e)}),a(t,function(e){n.addPlugin(e)}),n}var o=e("./util"),i=o.pluck,a=o.each,s=o.create,u=o.isList,c=o.isFunction,f=o.isObject;t.exports={createStore:n};var l={version:"2.0.3",enabled:!1,storage:null,addStorage:function(e){this.enabled||this._testStorage(e)&&(this._storage.resolved=e,this.enabled=!0,this.storage=e.name)},addPlugin:function(e){var t=this;if(u(e))return void a(e,function(e){t.addPlugin(e)});var r=i(this._seenPlugins,function(t){return e===t});if(!r){if(this._seenPlugins.push(e),!c(e))throw new Error("Plugins must be function values that return objects");var n=e.call(this);if(!f(n))throw new Error("Plugins must return an object of function properties");a(n,function(r,n){if(!c(r))throw new Error("Bad plugin property: "+n+" from plugin "+e.name+". Plugins should only return functions.");t._assignPluginFnProp(r,n)})}},get:function(e,t){var r=this._storage().read(this._namespacePrefix+e);return this._deserialize(r,t)},set:function(e,t){return void 0===t?this.remove(e):(this._storage().write(this._namespacePrefix+e,this._serialize(t)),t)},remove:function(e){this._storage().remove(this._namespacePrefix+e)},each:function(e){var t=this;this._storage().each(function(r,n){e(t._deserialize(r),n.replace(t._namespaceRegexp,""))})},clearAll:function(){this._storage().clearAll()},hasNamespace:function(e){return this._namespacePrefix=="__storejs_"+e+"_"},namespace:function(e){if(!this._legalNamespace.test(e))throw new Error("store.js namespaces can only have alhpanumerics + underscores and dashes");var t="__storejs_"+e+"_";return s(this,{_namespacePrefix:t,_namespaceRegexp:t?new RegExp("^"+t):null})},createStore:function(e,t){return n(e,t)}}},{"./util":3}],3:[function(e,t,r){(function(e){"use strict";function r(){return Object.assign?Object.assign:function(e,t,r,n){for(var o=1;o<arguments.length;o++)s(Object(arguments[o]),function(t,r){e[r]=t});return e}}function n(){if(Object.create)return function(e,t,r,n){var o=a(arguments,1);return g.apply(this,[Object.create(e)].concat(o))};var e=function(){};return function(t,r,n,o){var i=a(arguments,1);return e.prototype=t,g.apply(this,[new e].concat(i))}}function o(){return String.prototype.trim?function(e){return String.prototype.trim.call(e)}:function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}}function i(e,t){return function(){return t.apply(e,Array.prototype.slice.call(arguments,0))}}function a(e,t){return Array.prototype.slice.call(e,t||0)}function s(e,t){c(e,function(e,r){return t(e,r),!1})}function u(e,t){var r=f(e)?[]:{};return c(e,function(e,n){return r[n]=t(e,n),!1}),r}function c(e,t){if(f(e)){for(var r=0;r<e.length;r++)if(t(e[r],r))return e[r]}else for(var n in e)if(e.hasOwnProperty(n)&&t(e[n],n))return e[n]}function f(e){return null!=e&&"function"!=typeof e&&"number"==typeof e.length}function l(e){return e&&"[object Function]"==={}.toString.call(e)}function p(e){return e&&"[object Object]"==={}.toString.call(e)}var g=r(),d=n(),h=o(),m="undefined"!=typeof window?window:e;t.exports={assign:g,create:d,trim:h,bind:i,slice:a,each:s,map:u,pluck:c,isList:f,isFunction:l,isObject:p,Global:m}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,r){"use strict";function n(e){if(!e||!u(e))return null;var t="(?:^|.*;\\s*)"+escape(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(p.cookie.replace(new RegExp(t),"$1"))}function o(e){for(var t=p.cookie.split(/; ?/g),r=t.length-1;r>=0;r--)if(l(t[r])){var n=t[r].split("="),o=unescape(n[0]),i=unescape(n[1]);e(i,o)}}function i(e,t){e&&(p.cookie=escape(e)+"="+escape(t)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/")}function a(e){e&&u(e)&&(p.cookie=escape(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function s(){o(function(e,t){a(t)})}function u(e){return new RegExp("(?:^|;\\s*)"+escape(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(p.cookie)}var c=e("../src/util"),f=c.Global,l=c.trim;t.exports={name:"cookieStorage",read:n,write:i,each:o,remove:a,clearAll:s};var p=f.document},{"../src/util":3}],5:[function(e,t,r){"use strict";function n(){return f.localStorage}function o(e){return n().getItem(e)}function i(e,t){return n().setItem(e,t)}function a(e){for(var t=n().length-1;t>=0;t--){var r=n().key(t);e(o(r),r)}}function s(e){return n().removeItem(e)}function u(){return n().clear()}var c=e("../src/util"),f=c.Global;t.exports={name:"localStorage",read:o,write:i,each:a,remove:s,clearAll:u}},{"../src/util":3}],6:[function(e,t,r){"use strict";function n(e){return u[e]}function o(e,t){u[e]=t}function i(e){for(var t in u)u.hasOwnProperty(t)&&e(u[t],t)}function a(e){delete u[e]}function s(e){u={}}t.exports={name:"memoryStorage",read:n,write:o,each:i,remove:a,clearAll:s};var u={}},{}],7:[function(e,t,r){"use strict";function n(){return f.sessionStorage}function o(e){return n().getItem(e)}function i(e,t){return n().setItem(e,t)}function a(e){for(var t=n().length-1;t>=0;t--){var r=n().key(t);e(o(r),r)}}function s(e){return n().removeItem(e)}function u(){return n().clear()}var c=e("../src/util"),f=c.Global;t.exports={name:"sessionStorage",read:o,write:i,each:a,remove:s,clearAll:u}},{"../src/util":3}]},{},[1])(1)});