Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

incache

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

incache - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

5

CHANGELOG.md

@@ -7,2 +7,5 @@ # Change Log

## [5.1.0] - 2017-09-05
- Changed the default value of `nullIfNotFound` option, now is set to "false"
## [5.0.0] - 2017-09-05

@@ -41,3 +44,3 @@ - Added

## [4.1.1] - 2017-08-30
- Added alias method to `remove`: `destroy`
- Added `destroy`, alias of `remove`
- Removed unused code

@@ -44,0 +47,0 @@

17

dist/incache.js

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

// [AIV] InCache Build version: 5.0.0
// [AIV] InCache Build version: 5.1.0
var incache =

@@ -337,3 +337,3 @@ /******/ (function(modules) { // webpackBootstrap

autoRemovePeriod: 0,
nullIfNotFound: true,
nullIfNotFound: false,
global: {

@@ -393,2 +393,3 @@ silent: false,

* @see {@link constructor} for further information
* @since 3.0.0
*/

@@ -606,2 +607,3 @@

* inCache.removeFrom('myArray', 'hello'); //-> ['world'];
* @since 3.0.0
*/

@@ -640,2 +642,3 @@

* @returns {Array} expired keys
* @since 4.1.0
* @example

@@ -672,2 +675,3 @@ * inCache.set('my key 1', 'my value');

* inCache.addTo('myArray', 'ciao'); //-> ['hello', 'world', 'ciao'];
* @since 3.0.0
*/

@@ -696,2 +700,3 @@

* inCache.prependTo('myArray', 'ciao'); //-> ['ciao', 'hello', 'world'];
* @since 3.0.0
*/

@@ -723,2 +728,3 @@

* inCache.updateIn('myArray', {z: 0, x: 0}, {b: 2, c: 3}); //-> [{z: 0, x: 0}, {z: 0, x: 0}, {b: 4, e: 5}];
* @since 3.0.0
*/

@@ -918,2 +924,3 @@

* @param args
* @since 4.1.1
*/

@@ -1027,3 +1034,3 @@

/**
* Triggered when a record has been deleted. **Deprecated:** use `on('remove', callback)` instead
* Triggered when a record has been deleted. **Deprecated since 5.0.0:** use `on('remove', callback)` instead.
* @param callback {InCache~removedCallback} callback function

@@ -1051,3 +1058,3 @@ * @deprecated

/**
* Triggered when a record has been created. **Deprecated:** use `on('create', callback)` instead
* Triggered when a record has been created. **Deprecated since 5.0.0:** use `on('create', callback)` instead
* @param callback {InCache~createdCallback} callback function

@@ -1076,3 +1083,3 @@ * @deprecated

/**
* Triggered when a record has been updated. **Deprecated:** use `on('update', callback)` instead
* Triggered when a record has been updated. **Deprecated since 5.0.0:** use `on('update', callback)` instead
* @param callback {InCache~updatedCallback} callback function

@@ -1079,0 +1086,0 @@ * @deprecated

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

// [AIV] InCache Build version: 5.0.0
var incache=function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";function n(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function o(e){if(h===setTimeout)return setTimeout(e,0);if((h===n||!h)&&setTimeout)return h=setTimeout,setTimeout(e,0);try{return h(e,0)}catch(t){try{return h.call(null,e,0)}catch(t){return h.call(this,e,0)}}}function s(e){if(c===clearTimeout)return clearTimeout(e);if((c===i||!c)&&clearTimeout)return c=clearTimeout,clearTimeout(e);try{return c(e)}catch(t){try{return c.call(null,e)}catch(t){return c.call(this,e)}}}function a(){p&&d&&(p=!1,d.length?y=d.concat(y):m=-1,y.length&&u())}function u(){if(!p){var e=o(a);p=!0;for(var t=y.length;t;){for(d=y,y=[];++m<t;)d&&d[m].run();m=-1,t=y.length}d=null,p=!1,s(e)}}function l(e,t){this.fun=e,this.array=t}function f(){}var h,c,v=e.exports={};!function(){try{h="function"==typeof setTimeout?setTimeout:n}catch(e){h=n}try{c="function"==typeof clearTimeout?clearTimeout:i}catch(e){c=i}}();var d,y=[],p=!1,m=-1;v.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];y.push(new l(e,t)),1!==y.length||p||o(u)},l.prototype.run=function(){this.fun.apply(null,this.array)},v.title="browser",v.browser=!0,v.env={},v.argv=[],v.version="",v.versions={},v.on=f,v.addListener=f,v.once=f,v.off=f,v.removeListener=f,v.removeAllListeners=f,v.emit=f,v.prependListener=f,v.prependOnceListener=f,v.listeners=function(e){return[]},v.binding=function(e){throw new Error("process.binding is not supported")},v.cwd=function(){return"/"},v.chdir=function(e){throw new Error("process.chdir is not supported")},v.umask=function(){return 0}},function(e,t,r){"use strict";e.exports=r(2)},function(e,t,r){"use strict";(function(t,n){function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=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}}(),s=r(4),a=r(5),u=r(9),l=function(){function e(){var r=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,e),this._emitter=new a,this._timerExpiryCheck=null,this.GLOBAL_KEY="___InCache___storage___global___key___",this.DEFAULT_CONFIG={storeName:"",save:!0,filePath:".incache",maxAge:0,expires:null,silent:!1,share:!0,autoRemovePeriod:0,nullIfNotFound:!0,global:{silent:!1,life:0}},this._onRemoved=function(){},this._onCreated=function(){},this._onUpdated=function(){},s.isServer()&&(t.stdin.resume(),t.on("exit",function(){r._write()}),t.on("SIGINT",function(){r._write()})),this.setConfig(n)}return o(e,[{key:"_write",value:function(){var e=this._memory,t=e.config,r=e.data;if(t.save){var n=JSON.stringify(r);u.writeFileSync(t.filePath,n)}}},{key:"_read",value:function(){var e=this._memory.config;if(e.save&&u.existsSync(e.filePath)){var t=u.readFileSync(e.filePath);try{this._storage=this._memory.data=JSON.parse(t)}catch(e){this._storage=this._memory.data={}}}}},{key:"setConfig",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.global&&(s.deprecated(t.global.life,"global.life is deprecated use maxAge instead"),s.deprecated(t.global.silent,"global.silent is deprecated use silent instead")),s.defaults(t,this.DEFAULT_CONFIG),this._opts=t,this._root=t.share?s.isServer()?n:window:{},t.storeName&&(this.GLOBAL_KEY+=t.storeName),this._root[this.GLOBAL_KEY]||(this._root[this.GLOBAL_KEY]={metadata:{lastSave:null},data:{},config:this.DEFAULT_CONFIG}),this._root[this.GLOBAL_KEY].config=t,this._memory=this._root[this.GLOBAL_KEY],this._storage=this._memory.data,s.isServer()&&this._read(),this._timerExpiryCheck&&(clearInterval(this._timerExpiryCheck),this._timerExpiryCheck=null),t.autoRemovePeriod&&(this._timerExpiryCheck=setInterval(function(){var t=e.removeExpired();t.length&&e._emitter.fire("expired",t)},1e3*t.autoRemovePeriod))}},{key:"getConfig",value:function(){return this._memory.config}},{key:"set",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(r.silent||!1!==this._emitter.fireTheFirst("beforeSet",e,t)){var n={isNew:!0,createdOn:null,updatedOn:null,expiresOn:null,value:t};return r=s.defaults(r,this.DEFAULT_CONFIG),r.expires&&(s.is(r.expires,"date")||s.is(r.expires,"string"))?n.expiresOn=new Date(r.expires):r.maxAge&&s.is(r.maxAge,"number")?n.expiresOn=s.addMSToNow(r.maxAge):r.life&&s.is(r.life,"number")&&(s.deprecated(r.life,"life is deprecated use maxAge instead"),n.expiresOn=s.addSecondsToNow(r.life)),this.has(e)?(n.isNew=!1,n.createdOn=this._storage[e].createdOn,n.updatedOn=new Date,r.silent||(this._onUpdated.call(this,e,n),this._emitter.fire("update",e,n))):(n.createdOn=new Date,r.silent||(this._onCreated.call(this,e,n),this._emitter.fire("create",e,n))),this._storage[e]=n,r.silent||this._emitter.fire("set",e,n),n}}},{key:"get",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.has(e)?!this._opts.autoRemovePeriod&&this.expired(e)?(this.remove(e,!0),this._opts.nullIfNotFound?null:void 0):t?this._storage[e].value:this._storage[e]:this._opts.nullIfNotFound?null:void 0}},{key:"remove",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];(t||!1!==this._emitter.fireTheFirst("beforeRemove",e))&&(delete this._storage[e],t||(this._onRemoved.call(this,e),this._emitter.fire("remove",e)))}},{key:"removeFrom",value:function(e,t){if(!this.has(e))return null;if(s.is(t,"undefined"))throw new Error("where cannot be undefined");var r=this.get(e);if(!s.is(r,"array"))throw new Error("value must be an array");var n=r.length;for(var i in r)if(r.hasOwnProperty(i)){var o=[];for(var a in t)t.hasOwnProperty(a)&&(s.is(t,"object")?o.push(void 0!==r[i][a]&&r[i][a]===t[a]):o.push(r[i]===t));o.length&&-1===o.indexOf(!1)&&r.splice(i,1)}n!==r.length&&this.set(e,r)}},{key:"removeExpired",value:function(){var e=[];for(var t in this._storage)this._storage.hasOwnProperty(t)&&this.expired(t)&&(this.remove(t,!0),e.push(t));return e}},{key:"addTo",value:function(e,t){if(!this.has(e))return null;var r=this.get(e);if(!s.is(r,"array"))throw new Error("object must be an array");return r.push(t),this.set(e,r)}},{key:"prependTo",value:function(e,t){if(!this.has(e))return null;var r=this.get(e);if(!s.is(r,"array"))throw new Error("object must be an array");return r.unshift(t),this.set(e,r)}},{key:"updateIn",value:function(e,t,r){if(!this.has(e))return null;if(s.is(t,"undefined"))throw new Error("value cannot be undefined");if(s.is(r,"undefined"))throw new Error("where cannot be undefined");var n=this.get(e);if(!s.is(n,"array"))throw new Error("value must be an array");var i=!1;for(var o in n)if(n.hasOwnProperty(o)){var a=[];for(var u in r)r.hasOwnProperty(u)&&(s.is(r,"object")?a.push(void 0!==n[o][u]&&n[o][u]===r[u]):a.push(n[o]===r));a.length&&-1===a.indexOf(!1)&&(i=!0,n[o]=t)}i&&this.set(e,n)}},{key:"bulkSet",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!s.is(e,"array"))throw new Error("records must be an array of object, e.g. {key: foo, value: bar}");if(t||!1!==this._emitter.fireTheFirst("beforeBulkSet",e)){for(var r=0;r<e.length;r++){if(s.is(e[r].key,"undefined")||s.is(e[r].value,"undefined"))throw new Error("key and value properties are required");this.set(e[r].key,e[r].value,{silent:!0,fromBulk:!0})}t||this._emitter.fire("bulkSet",e)}}},{key:"bulkRemove",value:function(e,t){if(!s.is(e,"array"))throw new Error("keys must be an array of keys");if(t||!1!==this._emitter.fireTheFirst("beforeBulkRemove",e)){for(var r=0;r<e.length;r++)this.remove(e[r],!0);t||this._emitter.fire("bulkRemove",e)}}},{key:"clean",value:function(e){if(!s.is(e,"string"))throw new Error("key must be a string");for(var t in this._storage)this._storage.hasOwnProperty(t)&&-1!==t.indexOf(e)&&delete this._storage[t]}},{key:"all",value:function(){var e=[];for(var t in this._storage)this._storage.hasOwnProperty(t)&&(!this._opts.autoRemovePeriod&&this.expired(t)?this.remove(t,!0):e.push({key:t,value:this._storage[t].value}));return e}},{key:"expired",value:function(e){if(this._storage[e]&&this._storage[e].expiresOn){return new Date>new Date(this._storage[e].expiresOn)}return!1}},{key:"clear",value:function(){this._storage=this._memory.data={}}},{key:"has",value:function(e){return this._storage.hasOwnProperty(e)}},{key:"destroy",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];this.remove.apply(this,t)}},{key:"on",value:function(e,t){this._emitter.on.call(this._emitter,e,t)}},{key:"onRemoved",value:function(e){this._onRemoved=e}},{key:"onCreated",value:function(e){this._onCreated=e}},{key:"onUpdated",value:function(e){this._onUpdated=e}}]),e}();e.exports=l}).call(t,r(0),r(3))},function(e,t,r){"use strict";var n,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":i(window))&&(n=window)}e.exports=n},function(e,t,r){"use strict";(function(t){var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n={};n.is=function(e,t){return Object.prototype.toString.call(e).toLowerCase()==="[object "+t+"]".toLowerCase()},n.defaults=function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e.hasOwnProperty(i)?"object"===r(e[i])&&n.defaults(e[i],t[i]):e[i]=t[i]);return e},n.addSecondsToNow=function(e){var t=new Date;return new Date(t.setSeconds(t.getSeconds()+e))},n.addMSToNow=function(e){var t=new Date;return new Date(t.setMilliseconds(t.getMilliseconds()+e))},n.isServer=function(){return"object"===(void 0===t?"undefined":r(t))&&void 0!==t.pid},n.deprecated=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"warn";return void 0!==e&&(console[r](t||e),!0)},e.exports=n}).call(t,r(0))},function(e,t,r){"use strict";e.exports=r(6)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=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}}(),o=r(7),s=r(8),a=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n(this,e),this.defaultClassOpts={maxListeners:10,asyncDelay:10},this.defaultListenerOpts={maxCalls:0,prepend:!1},this.opts=o.defaults(t,this.defaultClassOpts),this.events={}}return i(e,[{key:"_createEvent",value:function(e,t,r){if(this.events[e]||(this.events[e]=[]),this.opts.maxListeners){var n=this.opts.maxListeners;if(this.events[e].length>=n)throw new Error(s[3]+n)}t.opts=o.defaults(r,this.defaultListenerOpts),t.info={calls:0},r.prepend?this.events[e].unshift(t):this.events[e].push(t),this._created.call(this,e,t,r)}},{key:"_callEvent",value:function(e,t,r){return t.opts.maxCalls&&t.info.calls++>=t.opts.maxCalls?void this.off(e,t):(this._catchAll.call(this,r),t.apply(this,r))}},{key:"_created",value:function(){}},{key:"_removed",value:function(){}},{key:"_catchAll",value:function(){}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!o.is(e,"string"))throw new Error(s[0]);if(e=e.trim(),!e.length)throw new Error(s[4]);if(o.is(t,"array")){for(var n in t)if(t.hasOwnProperty(n)){if(!o.is(t[n],"function"))throw new Error(s[1]);this._createEvent(e,t[n],r)}}else{if(!o.is(t,"function"))throw new Error(s[1]);this._createEvent(e,t,r)}return this}},{key:"once",value:function(e,t){return this.on(e,t,{maxCalls:1})}},{key:"fire",value:function(e){if(this.exists(e)){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];for(var i=0;i<this.events[e].length;i++)this._callEvent(e,this.events[e][i],r)}return this}},{key:"fireTheFirst",value:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];if(this.exists(e))return this._callEvent(e,this.events[e][0],r)}},{key:"fireAsync",value:function(e){for(var t=this,r=arguments.length,n=Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];n.unshift(e),setTimeout(function(){t.fire.apply(t,n)},this.opts.asyncDelay)}},{key:"off",value:function(e,t){if(!o.is(e,"string"))throw new Error(s[0]);if(this.events[e])if("function"==typeof t)for(var r=0;r<this.events[e].length;r++)this.events[e][r]===t&&(this.events[e].splice(r,1),this._removed.call(this,e,t));else delete this.events[e],this._removed.call(this,e);return this}},{key:"prependListener",value:function(e,t){return this.on(e,t,{prepend:!0})}},{key:"prependOnceListener",value:function(e,t){return this.on(e,t,{maxCalls:1,prepend:!0})}},{key:"clear",value:function(){return this.events=[],this}},{key:"getListenersCount",value:function(e){return this.getListeners(e).length}},{key:"getListeners",value:function(e){if(!o.is(e,"string"))throw new Error(s[0]);if(!this.exists(e))throw new Error(s[5]);return this.events[e]}},{key:"getEvents",value:function(){return this.events}},{key:"exists",value:function(e){if(!o.is(e,"string"))throw new Error(s[0]);return!o.is(this.events[e],"undefined")}},{key:"getMaxListeners",value:function(){return this.opts.maxListeners}},{key:"setMaxListeners",value:function(e){if(!o.is(e,"number"))throw new Error(s[2]);return this.opts.maxListeners=e,this}},{key:"onCatchAll",value:function(e){return this._catchAll=e,this}},{key:"onCreated",value:function(e){return this._created=e,this}},{key:"onRemoved",value:function(e){return this._removed=e,this}}]),e}();e.exports=a,e.exports._error=s},function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i={};i.is=function(e,t){return Object.prototype.toString.call(e).toLowerCase()==="[object "+t+"]".toLowerCase()},i.defaults=function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e.hasOwnProperty(r)?"object"===n(e[r])&&i.defaults(e[r],t[r]):e[r]=t[r]);return e},e.exports=i},function(e,t,r){"use strict";e.exports=["event name is required and must be a string","listener is required and must be a function or an array of function","value must be a number","increase maxListeners per event: ","event name not valid","event not found"]},function(e,t,r){"use strict"}]);
// [AIV] InCache Build version: 5.1.0
var incache=function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";function n(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function o(e){if(h===setTimeout)return setTimeout(e,0);if((h===n||!h)&&setTimeout)return h=setTimeout,setTimeout(e,0);try{return h(e,0)}catch(t){try{return h.call(null,e,0)}catch(t){return h.call(this,e,0)}}}function s(e){if(c===clearTimeout)return clearTimeout(e);if((c===i||!c)&&clearTimeout)return c=clearTimeout,clearTimeout(e);try{return c(e)}catch(t){try{return c.call(null,e)}catch(t){return c.call(this,e)}}}function a(){p&&d&&(p=!1,d.length?y=d.concat(y):m=-1,y.length&&u())}function u(){if(!p){var e=o(a);p=!0;for(var t=y.length;t;){for(d=y,y=[];++m<t;)d&&d[m].run();m=-1,t=y.length}d=null,p=!1,s(e)}}function l(e,t){this.fun=e,this.array=t}function f(){}var h,c,v=e.exports={};!function(){try{h="function"==typeof setTimeout?setTimeout:n}catch(e){h=n}try{c="function"==typeof clearTimeout?clearTimeout:i}catch(e){c=i}}();var d,y=[],p=!1,m=-1;v.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];y.push(new l(e,t)),1!==y.length||p||o(u)},l.prototype.run=function(){this.fun.apply(null,this.array)},v.title="browser",v.browser=!0,v.env={},v.argv=[],v.version="",v.versions={},v.on=f,v.addListener=f,v.once=f,v.off=f,v.removeListener=f,v.removeAllListeners=f,v.emit=f,v.prependListener=f,v.prependOnceListener=f,v.listeners=function(e){return[]},v.binding=function(e){throw new Error("process.binding is not supported")},v.cwd=function(){return"/"},v.chdir=function(e){throw new Error("process.chdir is not supported")},v.umask=function(){return 0}},function(e,t,r){"use strict";e.exports=r(2)},function(e,t,r){"use strict";(function(t,n){function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=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}}(),s=r(4),a=r(5),u=r(9),l=function(){function e(){var r=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,e),this._emitter=new a,this._timerExpiryCheck=null,this.GLOBAL_KEY="___InCache___storage___global___key___",this.DEFAULT_CONFIG={storeName:"",save:!0,filePath:".incache",maxAge:0,expires:null,silent:!1,share:!0,autoRemovePeriod:0,nullIfNotFound:!1,global:{silent:!1,life:0}},this._onRemoved=function(){},this._onCreated=function(){},this._onUpdated=function(){},s.isServer()&&(t.stdin.resume(),t.on("exit",function(){r._write()}),t.on("SIGINT",function(){r._write()})),this.setConfig(n)}return o(e,[{key:"_write",value:function(){var e=this._memory,t=e.config,r=e.data;if(t.save){var n=JSON.stringify(r);u.writeFileSync(t.filePath,n)}}},{key:"_read",value:function(){var e=this._memory.config;if(e.save&&u.existsSync(e.filePath)){var t=u.readFileSync(e.filePath);try{this._storage=this._memory.data=JSON.parse(t)}catch(e){this._storage=this._memory.data={}}}}},{key:"setConfig",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.global&&(s.deprecated(t.global.life,"global.life is deprecated use maxAge instead"),s.deprecated(t.global.silent,"global.silent is deprecated use silent instead")),s.defaults(t,this.DEFAULT_CONFIG),this._opts=t,this._root=t.share?s.isServer()?n:window:{},t.storeName&&(this.GLOBAL_KEY+=t.storeName),this._root[this.GLOBAL_KEY]||(this._root[this.GLOBAL_KEY]={metadata:{lastSave:null},data:{},config:this.DEFAULT_CONFIG}),this._root[this.GLOBAL_KEY].config=t,this._memory=this._root[this.GLOBAL_KEY],this._storage=this._memory.data,s.isServer()&&this._read(),this._timerExpiryCheck&&(clearInterval(this._timerExpiryCheck),this._timerExpiryCheck=null),t.autoRemovePeriod&&(this._timerExpiryCheck=setInterval(function(){var t=e.removeExpired();t.length&&e._emitter.fire("expired",t)},1e3*t.autoRemovePeriod))}},{key:"getConfig",value:function(){return this._memory.config}},{key:"set",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(r.silent||!1!==this._emitter.fireTheFirst("beforeSet",e,t)){var n={isNew:!0,createdOn:null,updatedOn:null,expiresOn:null,value:t};return r=s.defaults(r,this.DEFAULT_CONFIG),r.expires&&(s.is(r.expires,"date")||s.is(r.expires,"string"))?n.expiresOn=new Date(r.expires):r.maxAge&&s.is(r.maxAge,"number")?n.expiresOn=s.addMSToNow(r.maxAge):r.life&&s.is(r.life,"number")&&(s.deprecated(r.life,"life is deprecated use maxAge instead"),n.expiresOn=s.addSecondsToNow(r.life)),this.has(e)?(n.isNew=!1,n.createdOn=this._storage[e].createdOn,n.updatedOn=new Date,r.silent||(this._onUpdated.call(this,e,n),this._emitter.fire("update",e,n))):(n.createdOn=new Date,r.silent||(this._onCreated.call(this,e,n),this._emitter.fire("create",e,n))),this._storage[e]=n,r.silent||this._emitter.fire("set",e,n),n}}},{key:"get",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.has(e)?!this._opts.autoRemovePeriod&&this.expired(e)?(this.remove(e,!0),this._opts.nullIfNotFound?null:void 0):t?this._storage[e].value:this._storage[e]:this._opts.nullIfNotFound?null:void 0}},{key:"remove",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];(t||!1!==this._emitter.fireTheFirst("beforeRemove",e))&&(delete this._storage[e],t||(this._onRemoved.call(this,e),this._emitter.fire("remove",e)))}},{key:"removeFrom",value:function(e,t){if(!this.has(e))return null;if(s.is(t,"undefined"))throw new Error("where cannot be undefined");var r=this.get(e);if(!s.is(r,"array"))throw new Error("value must be an array");var n=r.length;for(var i in r)if(r.hasOwnProperty(i)){var o=[];for(var a in t)t.hasOwnProperty(a)&&(s.is(t,"object")?o.push(void 0!==r[i][a]&&r[i][a]===t[a]):o.push(r[i]===t));o.length&&-1===o.indexOf(!1)&&r.splice(i,1)}n!==r.length&&this.set(e,r)}},{key:"removeExpired",value:function(){var e=[];for(var t in this._storage)this._storage.hasOwnProperty(t)&&this.expired(t)&&(this.remove(t,!0),e.push(t));return e}},{key:"addTo",value:function(e,t){if(!this.has(e))return null;var r=this.get(e);if(!s.is(r,"array"))throw new Error("object must be an array");return r.push(t),this.set(e,r)}},{key:"prependTo",value:function(e,t){if(!this.has(e))return null;var r=this.get(e);if(!s.is(r,"array"))throw new Error("object must be an array");return r.unshift(t),this.set(e,r)}},{key:"updateIn",value:function(e,t,r){if(!this.has(e))return null;if(s.is(t,"undefined"))throw new Error("value cannot be undefined");if(s.is(r,"undefined"))throw new Error("where cannot be undefined");var n=this.get(e);if(!s.is(n,"array"))throw new Error("value must be an array");var i=!1;for(var o in n)if(n.hasOwnProperty(o)){var a=[];for(var u in r)r.hasOwnProperty(u)&&(s.is(r,"object")?a.push(void 0!==n[o][u]&&n[o][u]===r[u]):a.push(n[o]===r));a.length&&-1===a.indexOf(!1)&&(i=!0,n[o]=t)}i&&this.set(e,n)}},{key:"bulkSet",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!s.is(e,"array"))throw new Error("records must be an array of object, e.g. {key: foo, value: bar}");if(t||!1!==this._emitter.fireTheFirst("beforeBulkSet",e)){for(var r=0;r<e.length;r++){if(s.is(e[r].key,"undefined")||s.is(e[r].value,"undefined"))throw new Error("key and value properties are required");this.set(e[r].key,e[r].value,{silent:!0,fromBulk:!0})}t||this._emitter.fire("bulkSet",e)}}},{key:"bulkRemove",value:function(e,t){if(!s.is(e,"array"))throw new Error("keys must be an array of keys");if(t||!1!==this._emitter.fireTheFirst("beforeBulkRemove",e)){for(var r=0;r<e.length;r++)this.remove(e[r],!0);t||this._emitter.fire("bulkRemove",e)}}},{key:"clean",value:function(e){if(!s.is(e,"string"))throw new Error("key must be a string");for(var t in this._storage)this._storage.hasOwnProperty(t)&&-1!==t.indexOf(e)&&delete this._storage[t]}},{key:"all",value:function(){var e=[];for(var t in this._storage)this._storage.hasOwnProperty(t)&&(!this._opts.autoRemovePeriod&&this.expired(t)?this.remove(t,!0):e.push({key:t,value:this._storage[t].value}));return e}},{key:"expired",value:function(e){if(this._storage[e]&&this._storage[e].expiresOn){return new Date>new Date(this._storage[e].expiresOn)}return!1}},{key:"clear",value:function(){this._storage=this._memory.data={}}},{key:"has",value:function(e){return this._storage.hasOwnProperty(e)}},{key:"destroy",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];this.remove.apply(this,t)}},{key:"on",value:function(e,t){this._emitter.on.call(this._emitter,e,t)}},{key:"onRemoved",value:function(e){this._onRemoved=e}},{key:"onCreated",value:function(e){this._onCreated=e}},{key:"onUpdated",value:function(e){this._onUpdated=e}}]),e}();e.exports=l}).call(t,r(0),r(3))},function(e,t,r){"use strict";var n,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":i(window))&&(n=window)}e.exports=n},function(e,t,r){"use strict";(function(t){var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n={};n.is=function(e,t){return Object.prototype.toString.call(e).toLowerCase()==="[object "+t+"]".toLowerCase()},n.defaults=function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e.hasOwnProperty(i)?"object"===r(e[i])&&n.defaults(e[i],t[i]):e[i]=t[i]);return e},n.addSecondsToNow=function(e){var t=new Date;return new Date(t.setSeconds(t.getSeconds()+e))},n.addMSToNow=function(e){var t=new Date;return new Date(t.setMilliseconds(t.getMilliseconds()+e))},n.isServer=function(){return"object"===(void 0===t?"undefined":r(t))&&void 0!==t.pid},n.deprecated=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"warn";return void 0!==e&&(console[r](t||e),!0)},e.exports=n}).call(t,r(0))},function(e,t,r){"use strict";e.exports=r(6)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=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}}(),o=r(7),s=r(8),a=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n(this,e),this.defaultClassOpts={maxListeners:10,asyncDelay:10},this.defaultListenerOpts={maxCalls:0,prepend:!1},this.opts=o.defaults(t,this.defaultClassOpts),this.events={}}return i(e,[{key:"_createEvent",value:function(e,t,r){if(this.events[e]||(this.events[e]=[]),this.opts.maxListeners){var n=this.opts.maxListeners;if(this.events[e].length>=n)throw new Error(s[3]+n)}t.opts=o.defaults(r,this.defaultListenerOpts),t.info={calls:0},r.prepend?this.events[e].unshift(t):this.events[e].push(t),this._created.call(this,e,t,r)}},{key:"_callEvent",value:function(e,t,r){return t.opts.maxCalls&&t.info.calls++>=t.opts.maxCalls?void this.off(e,t):(this._catchAll.call(this,r),t.apply(this,r))}},{key:"_created",value:function(){}},{key:"_removed",value:function(){}},{key:"_catchAll",value:function(){}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!o.is(e,"string"))throw new Error(s[0]);if(e=e.trim(),!e.length)throw new Error(s[4]);if(o.is(t,"array")){for(var n in t)if(t.hasOwnProperty(n)){if(!o.is(t[n],"function"))throw new Error(s[1]);this._createEvent(e,t[n],r)}}else{if(!o.is(t,"function"))throw new Error(s[1]);this._createEvent(e,t,r)}return this}},{key:"once",value:function(e,t){return this.on(e,t,{maxCalls:1})}},{key:"fire",value:function(e){if(this.exists(e)){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];for(var i=0;i<this.events[e].length;i++)this._callEvent(e,this.events[e][i],r)}return this}},{key:"fireTheFirst",value:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];if(this.exists(e))return this._callEvent(e,this.events[e][0],r)}},{key:"fireAsync",value:function(e){for(var t=this,r=arguments.length,n=Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];n.unshift(e),setTimeout(function(){t.fire.apply(t,n)},this.opts.asyncDelay)}},{key:"off",value:function(e,t){if(!o.is(e,"string"))throw new Error(s[0]);if(this.events[e])if("function"==typeof t)for(var r=0;r<this.events[e].length;r++)this.events[e][r]===t&&(this.events[e].splice(r,1),this._removed.call(this,e,t));else delete this.events[e],this._removed.call(this,e);return this}},{key:"prependListener",value:function(e,t){return this.on(e,t,{prepend:!0})}},{key:"prependOnceListener",value:function(e,t){return this.on(e,t,{maxCalls:1,prepend:!0})}},{key:"clear",value:function(){return this.events=[],this}},{key:"getListenersCount",value:function(e){return this.getListeners(e).length}},{key:"getListeners",value:function(e){if(!o.is(e,"string"))throw new Error(s[0]);if(!this.exists(e))throw new Error(s[5]);return this.events[e]}},{key:"getEvents",value:function(){return this.events}},{key:"exists",value:function(e){if(!o.is(e,"string"))throw new Error(s[0]);return!o.is(this.events[e],"undefined")}},{key:"getMaxListeners",value:function(){return this.opts.maxListeners}},{key:"setMaxListeners",value:function(e){if(!o.is(e,"number"))throw new Error(s[2]);return this.opts.maxListeners=e,this}},{key:"onCatchAll",value:function(e){return this._catchAll=e,this}},{key:"onCreated",value:function(e){return this._created=e,this}},{key:"onRemoved",value:function(e){return this._removed=e,this}}]),e}();e.exports=a,e.exports._error=s},function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i={};i.is=function(e,t){return Object.prototype.toString.call(e).toLowerCase()==="[object "+t+"]".toLowerCase()},i.defaults=function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e.hasOwnProperty(r)?"object"===n(e[r])&&i.defaults(e[r],t[r]):e[r]=t[r]);return e},e.exports=i},function(e,t,r){"use strict";e.exports=["event name is required and must be a string","listener is required and must be a function or an array of function","value must be a number","increase maxListeners per event: ","event name not valid","event not found"]},function(e,t,r){"use strict"}]);
{
"name": "incache",
"version": "5.0.0",
"version": "5.1.0",
"description": "Simple key/value in-memory storage or on disk to persist some data",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -52,3 +52,3 @@ const helper = require('./helper');

autoRemovePeriod: 0,
nullIfNotFound: true,
nullIfNotFound: false,
global: {

@@ -105,2 +105,3 @@ silent: false,

* @see {@link constructor} for further information
* @since 3.0.0
*/

@@ -299,2 +300,3 @@ setConfig(opts = {}) {

* inCache.removeFrom('myArray', 'hello'); //-> ['world'];
* @since 3.0.0
*/

@@ -337,2 +339,3 @@ removeFrom(key, where) {

* @returns {Array} expired keys
* @since 4.1.0
* @example

@@ -366,2 +369,3 @@ * inCache.set('my key 1', 'my value');

* inCache.addTo('myArray', 'ciao'); //-> ['hello', 'world', 'ciao'];
* @since 3.0.0
*/

@@ -388,2 +392,3 @@ addTo(key, value) {

* inCache.prependTo('myArray', 'ciao'); //-> ['ciao', 'hello', 'world'];
* @since 3.0.0
*/

@@ -414,2 +419,3 @@ prependTo(key, value) {

* inCache.updateIn('myArray', {z: 0, x: 0}, {b: 2, c: 3}); //-> [{z: 0, x: 0}, {z: 0, x: 0}, {b: 4, e: 5}];
* @since 3.0.0
*/

@@ -595,2 +601,3 @@ updateIn(key, value, where) {

* @param args
* @since 4.1.1
*/

@@ -694,3 +701,3 @@ destroy(...args) {

/**
* Triggered when a record has been deleted. **Deprecated:** use `on('remove', callback)` instead
* Triggered when a record has been deleted. **Deprecated since 5.0.0:** use `on('remove', callback)` instead.
* @param callback {InCache~removedCallback} callback function

@@ -715,3 +722,3 @@ * @deprecated

/**
* Triggered when a record has been created. **Deprecated:** use `on('create', callback)` instead
* Triggered when a record has been created. **Deprecated since 5.0.0:** use `on('create', callback)` instead
* @param callback {InCache~createdCallback} callback function

@@ -737,3 +744,3 @@ * @deprecated

/**
* Triggered when a record has been updated. **Deprecated:** use `on('update', callback)` instead
* Triggered when a record has been updated. **Deprecated since 5.0.0:** use `on('update', callback)` instead
* @param callback {InCache~updatedCallback} callback function

@@ -740,0 +747,0 @@ * @deprecated

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