UNPKG

list-map

Version:

A list-map collection in the form of key, value, that ensures the index.

11 lines (10 loc) 2.02 kB
/* Copyright (c) 2019 Daybrush name: list-map license: MIT author: Daybrush repository: git+https://github.com/daybrush/list-map.git version: 0.1.1 */ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).ListMap=n()}(this,function(){"use strict";function r(t,n,e){void 0===e&&(e=-1);for(var i=t.length,r=0;r<i;++r)if(n(t[r],r,t))return r;return e}return function(){function t(){this.obj={},this.objKeys=[]}var n=t.prototype;return n.has=function(t){return t in this.obj},n.get=function(t){return this.obj[t]},n.set=function(t,n){return this.has(t)||this.objKeys.push(t),this.setItem(t,n),this},n.size=function(){return this.objKeys.length},n.keys=function(){return this.objKeys.slice()},n.values=function(){var n=this.obj;return this.objKeys.map(function(t){return n[t]})},n.getIndex=function(t){return this.objKeys.indexOf(t)},n.findIndex=function(e){var i=this.obj;return r(this.objKeys,function(t,n){return e(i[t],t,n,i)})},n.find=function(e){var i=this.obj,t=function(t,n,e){var i=r(t,n);return-1<i?t[i]:e}(this.objKeys,function(t,n){return e(i[t],t,n,i)});return i[t]},n.remove=function(t){if(this.has(t)){var n=this.getIndex(t);this.removeItem(t),this.spliceKeys(n,1)}return this},n.splice=function(t,n){for(var r=this,e=[],i=2;i<arguments.length;i++)e[i-2]=arguments[i];var o=e.filter(function(t){var n=t[0],e=t[1],i=r.has(n);return r.setItem(n,e),!i}),s=this.spliceKeys.apply(this,[t,n].concat(o.map(function(t){return t[0]})));s.forEach(function(t){r.removeItem(t)});var u=this.objKeys;return s.map(function(t){return[t,u[t]]})},n.forEach=function(e){var i=this.obj;return this.objKeys.forEach(function(t,n){return e(i[t],t,n,i)}),this},n.setItem=function(t,n){this.obj[t]=n},n.removeItem=function(t){delete this.obj[t]},n.spliceKeys=function(t,n){for(var e,i=[],r=2;r<arguments.length;r++)i[r-2]=arguments[r];return(e=this.objKeys).splice.apply(e,[t,n].concat(i))},t}()}); //# sourceMappingURL=list-map.pkgd.min.js.map