-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer-index-of-items.min.js
2 lines (2 loc) · 1.94 KB
/
buffer-index-of-items.min.js
1
2
'use strict';var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&'function'==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj},assert=console.assert.bind(console),_cache=new WeakMap,VALUE=Symbol('value-key'),LOOKUP=Symbol('lookup-key'),MINLENGTH=Symbol('min-length-key'),MAXLENGTH=Symbol('max-length-key');module.exports=indexOf,indexOf.create=indexOfCreate,indexOf.VALUE=VALUE,indexOf.LOOKUP=LOOKUP,indexOf.MINLENGTH=MINLENGTH,indexOf.MAXLENGTH=MAXLENGTH;function indexOf(a,b,d,e,f){var g;return(g=_cache.get(a))||_cache.set(a,g=lookupCreate(a)),g.lastIndex=g.offset=0,void 0===g(b,d,e,f)?-1:g.index}function indexOfCreate(a){var _f,b={},d=Number.MAX_SAFE_INTEGER,e=0;return assert(a instanceof Object,'invalid map (first argument), Object or Map expected'),(a instanceof Map?a.keys():Object.keys(a)).forEach(function(g){var h=b;if('string'==typeof g)g.split('').forEach(function(j){return h=h[j=j.charCodeAt()]||(h[j]={})});else if(g instanceof Buffer||g instanceof Array)g.forEach(function(j){return h=h[j]||(h[j]={})});else throw new Error('unsupported key type '+('undefined'==typeof g?'undefined':_typeof(g)));h[VALUE]=a instanceof Map?a.get(g):a[g],d>g.length&&(d=g.length),e<g.length&&(e=g.length)}),_f=function f(g,h,j,l){var o,p,q,m,n;if(isNaN(h)&&(h=_f.lastIndex||0),isNaN(j)&&(j=g.length),isNaN(l)&&(l=_f.offset||0),assert(g instanceof Buffer,'invalid buffer (first argument), Buffer expected'),assert(0|h===h,'invalid [index] (second argument), integer expected'),assert(0|j===j,'invalid [length] (third argument), integer expected'),assert(0|l===l,'invalid [offset] (fourth argument), integer expected'),0<(j-=l))for(0>(h-=l)&&(h=0);h<j-d;){// console.log( buffer[i] + ' at ' + i );
for(p=h,q=b;p<j&&(o=g[p++])in q;)q=q[o],VALUE in q&&(m=q[VALUE],n=p);if(void 0!==m)return _f.index=h+l,_f.lastIndex=n+l,m;h++}},_f[LOOKUP]=b,_f[MINLENGTH]=d,_f[MAXLENGTH]=e,_f}