mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
![]() |
import{c as at,a9 as lt}from"./chunk-449c23a2.js";function I(e){return Array.isArray?Array.isArray(e):et(e)==="[object Array]"}const ut=1/0;function ft(e){if(typeof e=="string")return e;let t=e+"";return t=="0"&&1/e==-ut?"-0":t}function dt(e){return e==null?"":ft(e)}function y(e){return typeof e=="string"}function q(e){return typeof e=="number"}function gt(e){return e===!0||e===!1||pt(e)&&et(e)=="[object Boolean]"}function tt(e){return typeof e=="object"}function pt(e){return tt(e)&&e!==null}function M(e){return e!=null}function j(e){return!e.trim().length}function et(e){return e==null?e===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const Mt="Incorrect 'index' type",mt=e=>`Invalid value for key ${e}`,xt=e=>`Pattern length exceeds max of ${e}.`,Et=e=>`Missing ${e} property in key`,yt=e=>`Property 'weight' in key '${e}' must be a positive integer`,U=Object.prototype.hasOwnProperty;class _t{constructor(t){this._keys=[],this._keyMap={};let s=0;t.forEach(n=>{let r=st(n);s+=r.weight,this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function st(e){let t=null,s=null,n=null,r=1,i=null;if(y(e)||I(e))n=e,t=Q(e),s=K(e);else{if(!U.call(e,"name"))throw new Error(Et("name"));const c=e.name;if(n=c,U.call(e,"weight")&&(r=e.weight,r<=0))throw new Error(yt(c));t=Q(c),s=K(c),i=e.getFn}return{path:t,id:s,weight:r,src:n,getFn:i}}function Q(e){return I(e)?e:e.split(".")}function K(e){return I(e)?e.join("."):e}function It(e,t){let s=[],n=!1;const r=(i,c,o)=>{if(M(i))if(!c[o])s.push(i);else{let h=c[o];const a=i[h];if(!M(a))return;if(o===c.length-1&&(y(a)||q(a)||gt(a)))s.push(dt(a));else if(I(a)){n=!0;for(let l=0,f=a.length;l<f;l+=1)r(a[l],c,o+1)}else c.length&&r(a,c,o+1)}};return r(e,y(t)?t.split("."):t,0),n?s:s[0]}const St={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},At={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},wt={location:0,threshold:.6,distance:100},Lt={useExtendedSearch:!1,getFn:It,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var u={...At,...St,...wt,...Lt};const Rt=/[^ ]+/g;function bt(e=1,t=3){const s=new Map,n=Math.pow(10,t);return{get(r){const i=r.match(Rt).length;if(s.has(i))return s.get(i);const c=1/Math.pow(i,.5*e),o=parseFloat(Math.round(c*n)/n);return s.set(i,o),o},clear(){s.clear()}}}class V{constructor({getFn:t=u.getFn,fieldNormWeight:s=u.fieldNormWeight}={}){this.norm=bt(s,3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,y(this.docs[0])?this.docs.forEach((t,s)=>{this._addString(t,s)}):this.docs.forEach((t,s)=>{this._addObject(t,s)}),this.norm.clear())}add(t){const s=this.size();y(t)?this._addString(t,s):this._addObject(t,s)}removeAt(t){this.records.splice(t,1);for(let s=t,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(t,s){return t[this._keysMap[s]]}size(){return this.records.length}_addString(t,s){if(!M(t)||j(t))return;let n={v:t,i:s,n:this.norm.get(t)};this.records.push(n)}_addObject(t,s){let n={i:s,$:{}};this.keys.forEach((r,i)=>{let c=r.getFn?r.getFn(t):this.getFn(t,r.path);if(M(c)){if(I(c)){let o=[];const h=[{nestedArrIndex:-1,value:c}];for(;h.length;){const{nestedArrIndex:a,value:l}=h.pop();if(M(l))if(y(l)&&!j(l)){let f={v:l,i:a,n:this.norm.get(l)};o.push(f)}else I(l)&&l.forEach((f,d)=>{h.push({nestedArrIndex:d,value:f})})}n.$[i]=o}else if(y(c)&&!j(c)){let o={v:c,n:this.norm.get(c)};n.$[i]=o}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function nt(e,t,{getFn:s=u.getFn,fieldNormWeight:n=u.fieldNormWeight}={}){const r=new V({getFn:s,fieldNormWeight:n});return r.setKeys(e.map(st)),r.setSources(t),r.create(),r}function Nt(e,{getFn:t=u.getFn,fieldNormWeight:s=u.fieldNormWeigh
|