local-sync
Advanced tools
Comparing version
@@ -300,8 +300,15 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
value: function _validateValue(value) { | ||
var validTypes = ['[object Array]', '[object Boolean]', '[object Null]', '[object Number]', '[object Object]', '[object String]', '[object Undefined]']; | ||
var valueType = Object.prototype.toString.call(value); | ||
if (!validTypes.some(function (type) { | ||
return valueType === type; | ||
var _arguments = arguments; | ||
var validTypes = [null, undefined, true, 0, '', [], {}]; | ||
var signature = function signature() { | ||
var _Object$prototype$toS; | ||
return (_Object$prototype$toS = Object.prototype.toString).call.apply(_Object$prototype$toS, _arguments); | ||
}; | ||
if (!validTypes.some(function (valid) { | ||
return signature(value) === signature(valid); | ||
})) { | ||
throw new Error('LocalSync cannot store "value" of type ' + valueType); | ||
throw new Error('LocalSync cannot store "value" of type ' + signature(value)); | ||
} | ||
@@ -308,0 +315,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LocalSync=t():e.LocalSync=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t){"use strict";function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},i=function(e){return localStorage.getItem(e)},u=function(e,t){return localStorage.setItem(e,t)},c=function(e){return localStorage.removeItem(e)},s=function(e){return localStorage.key(e)},l=function(){return localStorage.length},f=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(n(this,e),!(t instanceof Object))throw new Error('LocalSync "options" must be an object.');var r=t.bucket||e.BUCKET,a=t.prefix||e.PREFIX,o=t.separator||e.SEPARATOR;this._validateBucket(r),this._validatePrefix(a),this._validateSeparator(o),this._bucket=r,this._prefix=a,this._separator=o}return a(e,[{key:"_mapKeys",value:function(e){for(var t=[],r=l()-1;r>=0;--r){var n=s(r);n.startsWith(this._fullBucket())&&t.unshift(e(this._parseKey(n)))}return t}},{key:"_mapBuckets",value:function(e){for(var t=[],r=l()-1;r>=0;--r){var n=s(r);n.startsWith(this._prefix)&&t.unshift(e(this._parseBucket(n)))}return t}},{key:"_fullBucket",value:function(){return[this._prefix,this._bucket].join(this._separator)}},{key:"_fullKey",value:function(e){return[this._fullBucket(),e].join(this._separator)}},{key:"_parseBucket",value:function(e){var t=o(this._prefix),r=o(this._separator),n=new RegExp(""+t+r+"(.*)"+r),a=e.match(n);return a&&a[1]||void 0}},{key:"_parseKey",value:function(e){var t=this._fullKey("fakeKey").replace("fakeKey",""),r=new RegExp(o(t));return e.replace(r,"")}},{key:"_validatePrefix",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "prefix" must be a string.');if(e.includes(" "))throw new Error('LocalSync "prefix" cannot contain spaces.');if(e.includes(this._separator))throw new Error('LocalSync "prefix" cannot contain the separator "'+this._separator+'".')}},{key:"_validateSeparator",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "separator" must be a string.');if(1!==e.length)throw new Error('LocalSync "separator" must be a single character.')}},{key:"_validateBucket",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "bucket" must be a string.');if(e.includes(" "))throw new Error('LocalSync "bucket" cannot contain spaces.');if(e.includes(this._separator))throw new Error('LocalSync "bucket" cannot contain the separator "'+this._separator+'".')}},{key:"_validateKey",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "key" parameter must be a string.');if(e.includes(this._separator))throw new Error('LocalSync "key" cannot contain the separator "'+this._separator+'".')}},{key:"_validateValue",value:function(e){var t=["[object Array]","[object Boolean]","[object Null]","[object Number]","[object Object]","[object String]","[object Undefined]"],r=Object.prototype.toString.call(e);if(!t.some(function(e){return r===e}))throw new Error('LocalSync cannot store "value" of type '+r)}},{key:"setBucket",value:function(e){return this._validateBucket(e),this._bucket=e,this._bucket}},{key:"getBucket",value:function(){return this._bucket}},{key:"allBuckets",value:function(){return this._mapBuckets(function(e){return e})}},{key:"get",value:function(e){this._validateKey(e);var t=i(this._fullKey(e));try{return"undefined"===t?void 0:JSON.parse(t)}catch(r){throw console.error("Could not JSON.parse() value:",t),r}}},{key:"set",value:function(e,t){return this._validateKey(e),this._validateValue(t),u(this._fullKey(e),JSON.stringify(t)),this.get(e)}},{key:"put",value:function(e,t){return this._validateKey(e),this._validateValue(t),this.set(e,Object.assign(this.get(e),t))}},{key:"remove",value:function(e){this._validateKey(e);var t=this.get(e);return c(this._fullKey(e)),t}},{key:"clear",value:function(){var e=this;this.getAll().forEach(function(t){e.remove(Object.keys(t)[0])})}},{key:"keys",value:function(){return this._mapKeys(function(e){return e})}},{key:"values",value:function(){var e=this;return this._mapKeys(function(t){return e.get(t)})}},{key:"getAll",value:function(){var e=this;return this._mapKeys(function(t){return r({},t,e.get(t))})}}]),e}();f.BUCKET="default",f.PREFIX="ls",f.SEPARATOR=".",t["default"]=f,e.exports=t["default"]}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LocalSync=t():e.LocalSync=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t){"use strict";function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},i=function(e){return localStorage.getItem(e)},u=function(e,t){return localStorage.setItem(e,t)},c=function(e){return localStorage.removeItem(e)},s=function(e){return localStorage.key(e)},l=function(){return localStorage.length},f=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];if(n(this,e),!(t instanceof Object))throw new Error('LocalSync "options" must be an object.');var r=t.bucket||e.BUCKET,a=t.prefix||e.PREFIX,o=t.separator||e.SEPARATOR;this._validateBucket(r),this._validatePrefix(a),this._validateSeparator(o),this._bucket=r,this._prefix=a,this._separator=o}return a(e,[{key:"_mapKeys",value:function(e){for(var t=[],r=l()-1;r>=0;--r){var n=s(r);n.startsWith(this._fullBucket())&&t.unshift(e(this._parseKey(n)))}return t}},{key:"_mapBuckets",value:function(e){for(var t=[],r=l()-1;r>=0;--r){var n=s(r);n.startsWith(this._prefix)&&t.unshift(e(this._parseBucket(n)))}return t}},{key:"_fullBucket",value:function(){return[this._prefix,this._bucket].join(this._separator)}},{key:"_fullKey",value:function(e){return[this._fullBucket(),e].join(this._separator)}},{key:"_parseBucket",value:function(e){var t=o(this._prefix),r=o(this._separator),n=new RegExp(""+t+r+"(.*)"+r),a=e.match(n);return a&&a[1]||void 0}},{key:"_parseKey",value:function(e){var t=this._fullKey("fakeKey").replace("fakeKey",""),r=new RegExp(o(t));return e.replace(r,"")}},{key:"_validatePrefix",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "prefix" must be a string.');if(e.includes(" "))throw new Error('LocalSync "prefix" cannot contain spaces.');if(e.includes(this._separator))throw new Error('LocalSync "prefix" cannot contain the separator "'+this._separator+'".')}},{key:"_validateSeparator",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "separator" must be a string.');if(1!==e.length)throw new Error('LocalSync "separator" must be a single character.')}},{key:"_validateBucket",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "bucket" must be a string.');if(e.includes(" "))throw new Error('LocalSync "bucket" cannot contain spaces.');if(e.includes(this._separator))throw new Error('LocalSync "bucket" cannot contain the separator "'+this._separator+'".')}},{key:"_validateKey",value:function(e){if("string"!=typeof e)throw new Error('LocalSync "key" parameter must be a string.');if(e.includes(this._separator))throw new Error('LocalSync "key" cannot contain the separator "'+this._separator+'".')}},{key:"_validateValue",value:function(e){var t=arguments,r=[null,void 0,!0,0,"",[],{}],n=function(){var e;return(e=Object.prototype.toString).call.apply(e,t)};if(!r.some(function(t){return n(e)===n(t)}))throw new Error('LocalSync cannot store "value" of type '+n(e))}},{key:"setBucket",value:function(e){return this._validateBucket(e),this._bucket=e,this._bucket}},{key:"getBucket",value:function(){return this._bucket}},{key:"allBuckets",value:function(){return this._mapBuckets(function(e){return e})}},{key:"get",value:function(e){this._validateKey(e);var t=i(this._fullKey(e));try{return"undefined"===t?void 0:JSON.parse(t)}catch(r){throw console.error("Could not JSON.parse() value:",t),r}}},{key:"set",value:function(e,t){return this._validateKey(e),this._validateValue(t),u(this._fullKey(e),JSON.stringify(t)),this.get(e)}},{key:"put",value:function(e,t){return this._validateKey(e),this._validateValue(t),this.set(e,Object.assign(this.get(e),t))}},{key:"remove",value:function(e){this._validateKey(e);var t=this.get(e);return c(this._fullKey(e)),t}},{key:"clear",value:function(){var e=this;this.getAll().forEach(function(t){e.remove(Object.keys(t)[0])})}},{key:"keys",value:function(){return this._mapKeys(function(e){return e})}},{key:"values",value:function(){var e=this;return this._mapKeys(function(t){return e.get(t)})}},{key:"getAll",value:function(){var e=this;return this._mapKeys(function(t){return r({},t,e.get(t))})}}]),e}();f.BUCKET="default",f.PREFIX="ls",f.SEPARATOR=".",t["default"]=f,e.exports=t["default"]}])}); |
{ | ||
"name": "local-sync", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A friendly, tiny, synchronous, namespaced, and dependency free local storage solution.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -182,14 +182,7 @@ // -------------------------------------------------------- | ||
_validateValue(value) { | ||
const validTypes = [ | ||
'[object Array]', | ||
'[object Boolean]', | ||
'[object Null]', | ||
'[object Number]', | ||
'[object Object]', | ||
'[object String]', | ||
'[object Undefined]', | ||
] | ||
const valueType = Object.prototype.toString.call(value) | ||
if (!validTypes.some(type => valueType === type)) { | ||
throw new Error(`LocalSync cannot store "value" of type ${valueType}`) | ||
const validTypes = [null, undefined, true, 0, '', [], {}] | ||
const signature = () => Object.prototype.toString.call(...arguments) | ||
if (!validTypes.some(valid => signature(value) === signature(valid))) { | ||
throw new Error(`LocalSync cannot store "value" of type ${signature(value)}`) | ||
} | ||
@@ -196,0 +189,0 @@ } |
Sorry, the diff of this file is not supported yet
91527
-0.16%813
-0.49%