New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

natty-storage

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

natty-storage - npm Package Compare versions

Comparing version 1.0.0-rc2 to 1.0.0-rc3

71

dist/natty-db.node.js

@@ -75,3 +75,3 @@ (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap

var VERSION = undefined;
(VERSION = "1.0.0-rc2");
(VERSION = "1.0.0-rc3");

@@ -99,6 +99,6 @@ var support = {

// 存到浏览器缓存中使用的键
key: '',
key: EMPTY,
// 版本号
tag: '',
tag: EMPTY,

@@ -145,4 +145,4 @@ // 有效期长, 单位ms

t._CHECK_KEY = 'natty-storage-check-' + t.config.key;
t._DATA_KEY = 'natty-storage-data-' + t.config.key;
t._CHECK_KEY = 'NattyStorageCheck:' + t.config.key;
t._DATA_KEY = 'NattyStorageData:' + t.config.key;
t._placeholderUsed = FALSE;

@@ -296,2 +296,8 @@

}
/**
* 返回指定的路径是否有值
* @param path {String} optional 要查询的路径
* @returns {Promise}
*/
}, {

@@ -304,23 +310,23 @@ key: 'has',

var has = undefined;
if (!t._data) {
t._lazyInit();
}
if (!t._placeholderUsed) {
// 如果有数据 且 没有使用内置`placeholder`, 说明是使用`path`方式设置的值
if (!t._placeholderUsed && !isEmptyPlainObject(t._data)) {
if (!path) {
throw new Error('a `path` argument should be passed into the `has` method');
}
has = hasValueByPath(path, t._data);
resolve(hasValueByPath(path, t._data) ? {
has: true,
value: getValueByPath(path, t._data)
} : {});
} else {
has = t._data.hasOwnProperty(PLACEHOLDER);
resolve(t._data.hasOwnProperty(PLACEHOLDER) ? {
has: true,
value: t._data[PLACEHOLDER]
} : {});
}
var data = {
has: has
};
if (has) {
data.value = getValueByPath(path, t._data);
}
resolve(data);
} catch (e) {

@@ -451,3 +457,3 @@ reject(e);

function reserveString(str) {
return str.split('').reverse().join('');
return str.split(EMPTY).reverse().join(EMPTY);
}

@@ -530,20 +536,2 @@

// TODO 移到单测里
// let aa = {
// bb: {
// cc: {}
// },
// dd: 'dd',
// ee: {
// cc: 0
// }
// }
//
// console.log('has key: bb.cc', hasValueByPath('bb.cc', aa));
// console.log('has key: bb.dd', hasValueByPath('bb.dd', aa));
// console.log('has key: dd.cc', hasValueByPath('dd.cc', aa));
// console.log('has key: dd.length', hasValueByPath('dd.length', aa));
// console.log('has key: ee.cc', hasValueByPath('ee.cc', aa));
// console.log('has key: ee.dd', hasValueByPath('ee.dd', aa));
function removeKeyAndValueByPath(path, data) {

@@ -564,2 +552,11 @@ var keys = splitPathToKeys(path);

function isEmptyPlainObject(v) {
var ret = TRUE;
for (var i in v) {
ret = FALSE;
break;
}
return ret;
}
module.exports = NattyStorage;

@@ -566,0 +563,0 @@

@@ -85,3 +85,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

var VERSION = undefined;
(VERSION = "1.0.0-rc2");
(VERSION = "1.0.0-rc3");

@@ -109,6 +109,6 @@ var support = {

// 存到浏览器缓存中使用的键
key: '',
key: EMPTY,
// 版本号
tag: '',
tag: EMPTY,

@@ -155,4 +155,4 @@ // 有效期长, 单位ms

t._CHECK_KEY = 'natty-storage-check-' + t.config.key;
t._DATA_KEY = 'natty-storage-data-' + t.config.key;
t._CHECK_KEY = 'NattyStorageCheck:' + t.config.key;
t._DATA_KEY = 'NattyStorageData:' + t.config.key;
t._placeholderUsed = FALSE;

@@ -306,2 +306,8 @@

}
/**
* 返回指定的路径是否有值
* @param path {String} optional 要查询的路径
* @returns {Promise}
*/
}, {

@@ -314,23 +320,23 @@ key: 'has',

var has = undefined;
if (!t._data) {
t._lazyInit();
}
if (!t._placeholderUsed) {
// 如果有数据 且 没有使用内置`placeholder`, 说明是使用`path`方式设置的值
if (!t._placeholderUsed && !isEmptyPlainObject(t._data)) {
if (!path) {
throw new Error('a `path` argument should be passed into the `has` method');
}
has = hasValueByPath(path, t._data);
resolve(hasValueByPath(path, t._data) ? {
has: true,
value: getValueByPath(path, t._data)
} : {});
} else {
has = t._data.hasOwnProperty(PLACEHOLDER);
resolve(t._data.hasOwnProperty(PLACEHOLDER) ? {
has: true,
value: t._data[PLACEHOLDER]
} : {});
}
var data = {
has: has
};
if (has) {
data.value = getValueByPath(path, t._data);
}
resolve(data);
} catch (e) {

@@ -461,3 +467,3 @@ reject(e);

function reserveString(str) {
return str.split('').reverse().join('');
return str.split(EMPTY).reverse().join(EMPTY);
}

@@ -540,20 +546,2 @@

// TODO 移到单测里
// let aa = {
// bb: {
// cc: {}
// },
// dd: 'dd',
// ee: {
// cc: 0
// }
// }
//
// console.log('has key: bb.cc', hasValueByPath('bb.cc', aa));
// console.log('has key: bb.dd', hasValueByPath('bb.dd', aa));
// console.log('has key: dd.cc', hasValueByPath('dd.cc', aa));
// console.log('has key: dd.length', hasValueByPath('dd.length', aa));
// console.log('has key: ee.cc', hasValueByPath('ee.cc', aa));
// console.log('has key: ee.dd', hasValueByPath('ee.dd', aa));
function removeKeyAndValueByPath(path, data) {

@@ -574,2 +562,11 @@ var keys = splitPathToKeys(path);

function isEmptyPlainObject(v) {
var ret = TRUE;
for (var i in v) {
ret = FALSE;
break;
}
return ret;
}
module.exports = NattyStorage;

@@ -576,0 +573,0 @@

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("NattyStorage",[],e):"object"==typeof exports?exports.NattyStorage=e():t.NattyStorage=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";t.exports=r(1)},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t){var e={x:"x"},r="natty-storage-test",n=o(t);n.set(r,e);var a=JSON.stringify(n.get(r))===JSON.stringify(e);return n.remove(r),a}function o(t){return t=p[t],{set:function(e,r){t.setItem(e,JSON.stringify(r))},get:function(e){var r=t.getItem(e);if(!r)return k;try{r=JSON.parse(r)}catch(n){}return r},remove:function(e){t.removeItem(e)}}}function i(){var t=D._variable;return{set:function(e,r){t[e]=r},get:function(e){return e in t?t[e]:k},remove:function(e){delete t[e]}}}function c(t){return t.split("").reverse().join("")}function s(t){var e;if(-1===t.indexOf("\\."))e=t.split(".");else{e=c(t).split(/\.(?!\\)/).reverse();for(var r=0,n=e.length;n>r;r++)e[r]=c(e[r].replace(/\.\\/g,"."))}return e}function u(t,e,r){for(var n=s(t),a=r;n.length;){var o=n.shift();if(n.length)a[o]=a[o]||{},a=a[o];else{if(!h(a))throw new Error("Cannot create property `"+o+"` on non-object value, path:`"+t+"`");a[o]=e}}return r}function f(t,e,r){if(r=r||!1,r===!0||-1===t.indexOf("."))return e[t];for(var n=s(t);n.length;){var a=n.shift();if(e=f(a,e,!0),"object"!=typeof e||void 0===e){n.length&&(e=void 0);break}}return e}function l(t,e,r){if(r=r||-1===t.indexOf("."))return e.hasOwnProperty(t);for(var n=s(t);n.length;){var a=n.shift(),o=e.hasOwnProperty(a);if(!o||!n.length)return o;if(e=f(a,e,!0),!h(e))return w}}function d(t,e){for(var r=s(t),n=e;r.length;){var a=r.shift();r.length?(n[a]=n[a]||{},n=n[a]):delete n[a]}return e}var g=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),_=r(2),v=_.extend,h=_.isPlainObject,p=window,y="undefined"!=typeof p,k=null,m=!0,w=!m,S="_placeholder",b=void 0;b="1.0.0-rc2";var O={localStorage:y&&!!p.localStorage&&a("localStorage"),sessionStorage:y&&!!p.sessionStorage&&a("sessionStorage")},x={type:"localStorage",key:"",tag:"",duration:0,until:0},E=v({},x),D=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];n(this,t);var r=this;if(r.config=v({},E,e),!r.config.key)throw new Error("`key` is missing, please check the options passed in `NattyStorage` constructor.");r._storage=O[r.config.type]?o(r.config.type):i(),r._CHECK_KEY="natty-storage-check-"+r.config.key,r._DATA_KEY="natty-storage-data-"+r.config.key,r._placeholderUsed=w,r._createStamp=+new Date}return g(t,[{key:"_lazyInit",value:function(){var t=this;t._checkData=t._storage.get(t._CHECK_KEY),t._isNew=t._checkData===k,t._isNew||t.isOutdated()?t._storage.set(t._DATA_KEY,t._data={}):(t._data=t._storage.get(t._DATA_KEY),t._data===k&&t._storage.set(t._DATA_KEY,t._data={})),t._storage.set(t._CHECK_KEY,t._checkData={tag:t.config.tag,lastUpdate:t._createStamp,duration:t.config.duration,until:t.config.until})}},{key:"isOutdated",value:function(){var t=this;if(t.config.tag&&t.config.tag!==t._checkData.tag)return m;var e=+new Date;return t._checkData.duration&&e-t._checkData.lastUpdate>t._checkData.duration?m:t._checkData.until&&e>t._checkData.until?m:w}},{key:"set",value:function(t,e){var r=this,n=arguments.length;return new Promise(function(a,o){try{r._data||r._lazyInit(),1===n?h(t)?r._data=t:(r._data[S]=t,r._placeholderUsed=m):u(t,e,r._data),r._storage.set(r._DATA_KEY,r._data),a()}catch(i){o(i)}})}},{key:"get",value:function(t){var e=this;return new Promise(function(r,n){try{var a=void 0;e._data||e._lazyInit(),a=t?f(t,e._data):e._placeholderUsed?e._data[S]:e._data,r(a)}catch(o){n(o)}})}},{key:"has",value:function(t){var e=this;return new Promise(function(r,n){try{var a=void 0;if(e._data||e._lazyInit(),e._placeholderUsed)a=e._data.hasOwnProperty(S);else{if(!t)throw new Error("a `path` argument should be passed into the `has` method");a=l(t,e._data)}var o={has:a};a&&(o.value=f(t,e._data)),r(o)}catch(i){n(i)}})}},{key:"remove",value:function(t){var e=this;return new Promise(function(r,n){try{e._data||e._lazyInit(),t?(d(t,e._data),e._storage.set(e._DATA_KEY,e._data)):e.set({}),r()}catch(a){n(a)}})}},{key:"destroy",value:function(){var t=this;t._storage.remove(t._CHECK_KEY),t._storage.remove(t._DATA_KEY)}},{key:"dump",value:function(){JSON&&console&&console.log(JSON.stringify(this._data,k,4))}}]),t}();D.version=b,D.support={},D.support.localStorage=O.localStorage,D.support.sessionStorage=O.sessionStorage,D._variable={},D.setGlobal=function(t){E=v({},x,t)},D.getGlobal=function(t){return t?E[t]:E},t.exports=D},function(t,e,r){"use strict";var n=null,a=function(t){return function(){for(var e=arguments,r=t(e[0],e[1]),n=2,a=e.length;a>n;n++)r=t(r,e[n]);return r}},o="object",i=function(t){return typeof t===o},c=function(t){return t!==n&&t===t.window},s=function(t){return t!==n&&i(t)&&!c(t)&&Object.getPrototypeOf(t)===Object.prototype},u=Array.isArray,f=function l(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];for(var r in e)e.hasOwnProperty(r)&&void 0!==e[r]&&(u(e[r])?t[r]=[].concat(e[r]):s(e[r])?t[r]=l({},e[r]):t[r]=e[r]);return t};t.exports={extend:a(f),isPlainObject:s}}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("NattyStorage",[],e):"object"==typeof exports?exports.NattyStorage=e():t.NattyStorage=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";t.exports=r(1)},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t){var e={x:"x"},r="natty-storage-test",n=o(t);n.set(r,e);var a=JSON.stringify(n.get(r))===JSON.stringify(e);return n.remove(r),a}function o(t){return t=y[t],{set:function(e,r){t.setItem(e,JSON.stringify(r))},get:function(e){var r=t.getItem(e);if(!r)return m;try{r=JSON.parse(r)}catch(n){}return r},remove:function(e){t.removeItem(e)}}}function i(){var t=K._variable;return{set:function(e,r){t[e]=r},get:function(e){return e in t?t[e]:m},remove:function(e){delete t[e]}}}function c(t){return t.split(w).reverse().join(w)}function s(t){var e;if(-1===t.indexOf("\\."))e=t.split(".");else{e=c(t).split(/\.(?!\\)/).reverse();for(var r=0,n=e.length;n>r;r++)e[r]=c(e[r].replace(/\.\\/g,"."))}return e}function u(t,e,r){for(var n=s(t),a=r;n.length;){var o=n.shift();if(n.length)a[o]=a[o]||{},a=a[o];else{if(!p(a))throw new Error("Cannot create property `"+o+"` on non-object value, path:`"+t+"`");a[o]=e}}return r}function f(t,e,r){if(r=r||!1,r===!0||-1===t.indexOf("."))return e[t];for(var n=s(t);n.length;){var a=n.shift();if(e=f(a,e,!0),"object"!=typeof e||void 0===e){n.length&&(e=void 0);break}}return e}function l(t,e,r){if(r=r||-1===t.indexOf("."))return e.hasOwnProperty(t);for(var n=s(t);n.length;){var a=n.shift(),o=e.hasOwnProperty(a);if(!o||!n.length)return o;if(e=f(a,e,!0),!p(e))return b}}function d(t,e){for(var r=s(t),n=e;r.length;){var a=r.shift();r.length?(n[a]=n[a]||{},n=n[a]):delete n[a]}return e}function _(t){var e=S;for(var r in t){e=b;break}return e}var g=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),h=r(2),v=h.extend,p=h.isPlainObject,y=window,k="undefined"!=typeof y,m=null,w="",S=!0,b=!S,O="_placeholder",x=void 0;x="1.0.0-rc3";var D={localStorage:k&&!!y.localStorage&&a("localStorage"),sessionStorage:k&&!!y.sessionStorage&&a("sessionStorage")},E={type:"localStorage",key:w,tag:w,duration:0,until:0},A=v({},E),K=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];n(this,t);var r=this;if(r.config=v({},A,e),!r.config.key)throw new Error("`key` is missing, please check the options passed in `NattyStorage` constructor.");r._storage=D[r.config.type]?o(r.config.type):i(),r._CHECK_KEY="NattyStorageCheck:"+r.config.key,r._DATA_KEY="NattyStorageData:"+r.config.key,r._placeholderUsed=b,r._createStamp=+new Date}return g(t,[{key:"_lazyInit",value:function(){var t=this;t._checkData=t._storage.get(t._CHECK_KEY),t._isNew=t._checkData===m,t._isNew||t.isOutdated()?t._storage.set(t._DATA_KEY,t._data={}):(t._data=t._storage.get(t._DATA_KEY),t._data===m&&t._storage.set(t._DATA_KEY,t._data={})),t._storage.set(t._CHECK_KEY,t._checkData={tag:t.config.tag,lastUpdate:t._createStamp,duration:t.config.duration,until:t.config.until})}},{key:"isOutdated",value:function(){var t=this;if(t.config.tag&&t.config.tag!==t._checkData.tag)return S;var e=+new Date;return t._checkData.duration&&e-t._checkData.lastUpdate>t._checkData.duration?S:t._checkData.until&&e>t._checkData.until?S:b}},{key:"set",value:function(t,e){var r=this,n=arguments.length;return new Promise(function(a,o){try{r._data||r._lazyInit(),1===n?p(t)?r._data=t:(r._data[O]=t,r._placeholderUsed=S):u(t,e,r._data),r._storage.set(r._DATA_KEY,r._data),a()}catch(i){o(i)}})}},{key:"get",value:function(t){var e=this;return new Promise(function(r,n){try{var a=void 0;e._data||e._lazyInit(),a=t?f(t,e._data):e._placeholderUsed?e._data[O]:e._data,r(a)}catch(o){n(o)}})}},{key:"has",value:function(t){var e=this;return new Promise(function(r,n){try{if(e._data||e._lazyInit(),e._placeholderUsed||_(e._data))r(e._data.hasOwnProperty(O)?{has:!0,value:e._data[O]}:{});else{if(!t)throw new Error("a `path` argument should be passed into the `has` method");r(l(t,e._data)?{has:!0,value:f(t,e._data)}:{})}}catch(a){n(a)}})}},{key:"remove",value:function(t){var e=this;return new Promise(function(r,n){try{e._data||e._lazyInit(),t?(d(t,e._data),e._storage.set(e._DATA_KEY,e._data)):e.set({}),r()}catch(a){n(a)}})}},{key:"destroy",value:function(){var t=this;t._storage.remove(t._CHECK_KEY),t._storage.remove(t._DATA_KEY)}},{key:"dump",value:function(){JSON&&console&&console.log(JSON.stringify(this._data,m,4))}}]),t}();K.version=x,K.support={},K.support.localStorage=D.localStorage,K.support.sessionStorage=D.sessionStorage,K._variable={},K.setGlobal=function(t){A=v({},E,t)},K.getGlobal=function(t){return t?A[t]:A},t.exports=K},function(t,e,r){"use strict";var n=null,a=function(t){return function(){for(var e=arguments,r=t(e[0],e[1]),n=2,a=e.length;a>n;n++)r=t(r,e[n]);return r}},o="object",i=function(t){return typeof t===o},c=function(t){return t!==n&&t===t.window},s=function(t){return t!==n&&i(t)&&!c(t)&&Object.getPrototypeOf(t)===Object.prototype},u=Array.isArray,f=function l(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];for(var r in e)e.hasOwnProperty(r)&&void 0!==e[r]&&(u(e[r])?t[r]=[].concat(e[r]):s(e[r])?t[r]=l({},e[r]):t[r]=e[r]);return t};t.exports={extend:a(f),isPlainObject:s}}])});
{
"name": "natty-storage",
"version": "1.0.0-rc2",
"version": "1.0.0-rc3",
"description": "",

@@ -5,0 +5,0 @@ "repository": "https://github.com/Jias/natty-storage.git",

@@ -31,3 +31,3 @@ "use strict";

// 全局默认配置
const defaultGlobalConfig = {
let defaultGlobalConfig = {
// localStorage, sessionStorage, variable

@@ -37,6 +37,6 @@ type: 'localStorage',

// 存到浏览器缓存中使用的键
key: '',
key: EMPTY,
// 版本号
tag: '',
tag: EMPTY,

@@ -77,4 +77,4 @@ // 有效期长, 单位ms

t._CHECK_KEY = 'natty-storage-check-' + t.config.key;
t._DATA_KEY = 'natty-storage-data-' + t.config.key;
t._CHECK_KEY = 'NattyStorageCheck:' + t.config.key;
t._DATA_KEY = 'NattyStorageData:' + t.config.key;
t._placeholderUsed = FALSE;

@@ -220,2 +220,7 @@

/**
* 返回指定的路径是否有值
* @param path {String} optional 要查询的路径
* @returns {Promise}
*/
has(path) {

@@ -226,23 +231,23 @@ let t = this;

let has;
if (!t._data) {
t._lazyInit();
}
if (!t._placeholderUsed) {
// 如果有数据 且 没有使用内置`placeholder`, 说明是使用`path`方式设置的值
if (!t._placeholderUsed && !isEmptyPlainObject(t._data)) {
if (!path) {
throw new Error('a `path` argument should be passed into the `has` method');
}
has = hasValueByPath(path, t._data);
resolve(hasValueByPath(path, t._data) ? {
has: true,
value: getValueByPath(path, t._data)
}: {});
} else {
has = t._data.hasOwnProperty(PLACEHOLDER);
resolve(t._data.hasOwnProperty(PLACEHOLDER) ? {
has: true,
value: t._data[PLACEHOLDER]
} : {});
}
let data = {
has: has
};
if (has) {
data.value = getValueByPath(path, t._data);
}
resolve(data);
} catch (e) {

@@ -367,3 +372,3 @@ reject(e);

function reserveString (str) {
return str.split('').reverse().join('');
return str.split(EMPTY).reverse().join(EMPTY);
}

@@ -446,20 +451,2 @@

// TODO 移到单测里
// let aa = {
// bb: {
// cc: {}
// },
// dd: 'dd',
// ee: {
// cc: 0
// }
// }
//
// console.log('has key: bb.cc', hasValueByPath('bb.cc', aa));
// console.log('has key: bb.dd', hasValueByPath('bb.dd', aa));
// console.log('has key: dd.cc', hasValueByPath('dd.cc', aa));
// console.log('has key: dd.length', hasValueByPath('dd.length', aa));
// console.log('has key: ee.cc', hasValueByPath('ee.cc', aa));
// console.log('has key: ee.dd', hasValueByPath('ee.dd', aa));
function removeKeyAndValueByPath(path, data) {

@@ -480,2 +467,11 @@ let keys = splitPathToKeys(path);

module.exports = NattyStorage;
function isEmptyPlainObject(v) {
let ret = TRUE;
for (let i in v) {
ret = FALSE;
break;
}
return ret;
}
module.exports = NattyStorage;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc