typescript-map
Version:
ES6 Map Implemented in TypeScript
1 lines • 3.34 kB
JavaScript
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(function(){return(()=>{"use strict";var t={270:function(t,e){var r=this&&this.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),s=0;for(e=0;e<r;e++)for(var i=arguments[e],o=0,u=i.length;o<u;o++,s++)n[s]=i[o];return n};Object.defineProperty(e,"__esModule",{value:!0}),e.TSMap=void 0;var n=function(){function t(t){var e=this;e._keys=[],e._values=[],e.length=0,t&&t.forEach((function(t,r){e.set(t[0],t[1])}))}return t.prototype.fromJSON=function(e,r){var n=this,s=function(e){return null!==e&&"object"==typeof e&&r?(new t).fromJSON(e,!0):Array.isArray(e)&&r?e.map((function(t){return s(t)})):e};return Object.keys(e).forEach((function(t){e.hasOwnProperty(t)&&n.set(t,s(e[t]))})),n},t.prototype.toJSON=function(){var e={},r=this,n=function(e){return e instanceof t?e.toJSON():Array.isArray(e)?e.map((function(t){return n(t)})):e};return r.keys().forEach((function(t){e[String(t)]=n(r.get(t))})),e},t.prototype.entries=function(){var t=this;return[].slice.call(this.keys().map((function(e){return[e,t.get(e)]})))},t.prototype.keys=function(){return[].slice.call(this._keys)},t.prototype.values=function(){return[].slice.call(this._values)},t.prototype.has=function(t){return this._keys.indexOf(t)>-1},t.prototype.get=function(t){var e=this._keys.indexOf(t);return e>-1?this._values[e]:void 0},t.prototype.deepGet=function(e){if(!e||!e.length)return null;var r=function(e,n){return null==e?null:n.length?r(e instanceof t?e.get(n[0]):e[n[0]],n.slice(1)):e};return r(this.get(e[0]),e.slice(1))},t.prototype.set=function(t,e){var r=this,n=this._keys.indexOf(t);return n>-1?r._values[n]=e:(r._keys.push(t),r._values.push(e),r.length=r._values.length),this},t.prototype.sortedSet=function(t,e,r,n){var s=this,i=this._keys.length,o=r||0,u=void 0!==n?n:i-1;if(0==i)return s._keys.push(t),s._values.push(e),s;if(t==this._keys[o])return this._values[o]=e,this;if(t==this._keys[u])return this._values[u]=e,this;if(t>this._keys[u])return this._keys.splice(u+1,0,t),this._values.splice(u+1,0,e),this;if(t<this._keys[o])return this._values.splice(o,0,e),this._keys.splice(o,0,t),this;if(o>=u)return this;var f=o+Math.floor((u-o)/2);return t<this._keys[f]?this.sortedSet(t,e,o,f-1):t>this._keys[f]?this.sortedSet(t,e,f+1,u):this},t.prototype.size=function(){return this.length},t.prototype.clear=function(){var t=this;return t._keys.length=t.length=t._values.length=0,this},t.prototype.delete=function(t){var e=this,r=e._keys.indexOf(t);return r>-1&&(e._keys.splice(r,1),e._values.splice(r,1),e.length=e._keys.length,!0)},t.prototype.forEach=function(t){var e=this;this._keys.forEach((function(r,n){t(e.get(r),r,n)}))},t.prototype.map=function(t){var e=this;return this.keys().map((function(r,n){return t(e.get(r),r,n)}))},t.prototype.filter=function(t){var e=this;return r(e._keys).forEach((function(r,n){!1===t(e.get(r),r,n)&&e.delete(r)})),this},t.prototype.clone=function(){return new t(this.entries())},t}();e.TSMap=n}},e={};return function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(270)})()}));