@bicharts/shape-core 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
+ import{a as J,b as Z,c as v,d as P,e as L,p as B}from"./chunk-RPZZSD7D.mjs";var X=96,rn=new Set(["n a","none","null","nil","unknown","not applicable","not available","not specified","unspecified","missing","blank","empty","tbd","to be determined"]);function mn(n){return n?rn.has(n):!0}var j=80;var Q=[["AL","Alabama"],["AK","Alaska"],["AZ","Arizona"],["AR","Arkansas"],["CA","California"],["CO","Colorado"],["CT","Connecticut"],["DE","Delaware"],["FL","Florida"],["GA","Georgia"],["HI","Hawaii"],["ID","Idaho"],["IL","Illinois"],["IN","Indiana"],["IA","Iowa"],["KS","Kansas"],["KY","Kentucky"],["LA","Louisiana"],["ME","Maine"],["MD","Maryland"],["MA","Massachusetts"],["MI","Michigan"],["MN","Minnesota"],["MS","Mississippi"],["MO","Missouri"],["MT","Montana"],["NE","Nebraska"],["NV","Nevada"],["NH","New Hampshire"],["NJ","New Jersey"],["NM","New Mexico"],["NY","New York"],["NC","North Carolina"],["ND","North Dakota"],["OH","Ohio"],["OK","Oklahoma"],["OR","Oregon"],["PA","Pennsylvania"],["RI","Rhode Island"],["SC","South Carolina"],["SD","South Dakota"],["TN","Tennessee"],["TX","Texas"],["UT","Utah"],["VT","Vermont"],["VA","Virginia"],["WA","Washington"],["WV","West Virginia"],["WI","Wisconsin"],["WY","Wyoming"],["DC","District of Columbia"],["PR","Puerto Rico"],["GU","Guam"],["VI","U.S. Virgin Islands"],["AS","American Samoa"],["MP","Northern Mariana Islands"]],nn=new Set(Q.map(n=>n[0])),an={"Ala.":"AL","Alab.":"AL","Ariz.":"AZ","Ark.":"AR","Calif.":"CA","Cal.":"CA","Colo.":"CO","Col.":"CO","Conn.":"CT","Del.":"DE","Fla.":"FL","Flor.":"FL","Ga.":"GA","Ill.":"IL","Ind.":"IN","Kan.":"KS","Kans.":"KS","Ky.":"KY","La.":"LA","Md.":"MD","Mass.":"MA","Mich.":"MI","Minn.":"MN","Miss.":"MS","Mo.":"MO","Mont.":"MT","Neb.":"NE","Nebr.":"NE","Nev.":"NV","N.H.":"NH","N.J.":"NJ","N.M.":"NM","N.Mex.":"NM","N. Mex.":"NM","N.Y.":"NY","N.C.":"NC","N.D.":"ND","N.Dak.":"ND","N. Dak.":"ND","Okla.":"OK","Ore.":"OR","Oreg.":"OR","Pa.":"PA","Penn.":"PA","Penna.":"PA","R.I.":"RI","S.C.":"SC","S.D.":"SD","S.Dak.":"SD","S. Dak.":"SD","Tenn.":"TN","Tex.":"TX","Vt.":"VT","Va.":"VA","Wash.":"WA","W.Va.":"WV","W. Va.":"WV","Wis.":"WI","Wisc.":"WI","Wyo.":"WY","D.C.":"DC","Wash. D.C.":"DC","Wash., D.C.":"DC","P.R.":"PR","V.I.":"VI"},tn=(()=>{let n=new Map;for(let[i,s]of Q)n.set(p(s),i);n.set(p("Washington DC"),"DC"),n.set(p("Washington D.C."),"DC"),n.set(p("US Virgin Islands"),"VI");for(let[i,s]of Object.entries(an)){let o=p(i);o&&!n.has(o)&&n.set(o,s)}return n})(),en=new Set(["01","02","04","05","06","08","09","10","11","12","13","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","44","45","46","47","48","49","50","51","53","54","55","56","60","66","69","72","78"]);function E(n){return n.trim().toUpperCase()}function p(n){return J(n)}var G=new Set(["country","countries","nation","nationality","iso","geo"]),z=new Set(["state","province","st"]),q=new Set(["zip","zipcode","postal","postcode","plz"]),cn=new Set(["county","fips","borough","parish"]),un=new Set(["city","cities","town","municipality","metro","location","place"]);function ln(n){return n.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-./]+/g," ").toLowerCase().split(/\s+/).filter(i=>i.length>0)}function d(n,i){if(!n)return!1;for(let s of ln(n))if(i.has(s))return!0;return!1}var fn=96,dn=5,pn=6e4;function In(n,i,s){if(!n||n.length===0)return null;let o=[],A=new Set;for(let t of n){if(t==null)continue;let e=String(t).trim();if(e.length===0)continue;let r=e.toLowerCase();if(!A.has(r)&&(A.add(r),o.push(e),o.length>pn))return null}let S=o.length;if(S<2)return null;let g=o.map(E),I=o.map(p),h=L(),m=0,N=0,C=0,R=0,y=0,u=0,_=0,W=0,V=0,H=0,U=0,D=0,x=d(i,q);for(let t=0;t<S;++t){let e=g[t],r=I[t],c=o[t],T=v.has(e),O=nn.has(e);P.has(e)&&m++,T&&N++,O&&C++,T&&O&&H++;let k=h.has(r),w=tn.has(r);k&&R++,w&&y++,k&&w&&U++,O&&w&&D++,/^\d{5}(-\d{4})?$/.test(c)||x&&/^\d{3,4}$/.test(c)?u++:/^\d{4}$/.test(c)&&V++,/^\d{5}$/.test(c)&&en.has(c.slice(0,2))&&_++,B(r)&&W++}!x&&u>0&&(u+=V);let Y=t=>t/S*100,M=[],l=(t,e,r,c=!1)=>{let T=Y(e);T<(t==="city-name"?j:fn)||e<2||c&&e<dn&&!d(i,t==="country-name"?G:t==="city-name"?un:z)||M.push({kind:t,matched:e,spec:r,pct:T})};l("country-iso3",m,6),l("country-name",R,5,!0),l("us-state-name",y,5,!0),l("us-zip5",u,4),l("us-county-fips",_,4),l("country-iso2",N,3),l("us-state-code",C,3),l("city-name",W,2,!0);let sn=C-D,on=y-D;if(sn>0&&on>0&&l("us-state-name",C+y-D,5,!0),M.length===0)return null;M.sort((t,e)=>e.pct-t.pct||e.spec-t.spec);let a=M[0],b=!1,$={"country-iso2":"us-state-code","us-state-code":"country-iso2","us-zip5":"us-county-fips","us-county-fips":"us-zip5","country-name":"us-state-name","us-state-name":"country-name"}[a.kind],K=M[1],F=$&&K&&K.kind===$&&Math.abs(a.pct-K.pct)<=15;if(a.kind==="country-iso2"||a.kind==="us-state-code"){let t=a.matched>0?H/a.matched:0,e=d(i,G),r=d(i,z);if(F||t>=.5){if(e&&!r)return f("country-iso2",N,!1);if(r&&!e)return f("us-state-code",C,!1);b=!0}}else if(a.kind==="us-zip5"||a.kind==="us-county-fips"){let t=_===u&&u===S,e=d(i,q),r=d(i,cn);return r&&!e?f("us-county-fips",_,!1):e&&!r?f("us-zip5",u,!1):t?f("us-zip5",u,!0):f("us-zip5",u,!1)}else if(F&&(a.kind==="country-name"||a.kind==="us-state-name")){let t=a.matched>0?U/a.matched:0,e=d(i,G),r=d(i,z);if(e&&!r)return f("country-name",R,!1);if(r&&!e)return f("us-state-name",y,!1);t>=.5&&(b=!0)}return f(a.kind,a.matched,b);function f(t,e,r){let c={geoKind:t,geoMatchPct:Math.round(Y(e)*10)/10};return r&&(c.geoAmbiguous=!0),c}}function Sn(n,i){if(n==null)return null;let s=String(n).trim();if(s.length===0)return null;switch(i){case"country-iso3":{let o=E(s);return P.has(o)?o:null}case"country-iso2":return Z.get(E(s))??null;case"country-name":return L().get(p(s))??null;case"us-state-code":case"us-state-name":{let o=E(s);return nn.has(o)?o:tn.get(p(s))??null}case"us-zip5":{let o=/^(\d{5})(-\d{4})?$/.exec(s);return o?o[1]:/^\d{3,4}$/.test(s)?s.padStart(5,"0"):null}case"us-county-fips":return/^\d{5}$/.test(s)&&en.has(s.slice(0,2))?s:null;default:return null}}function _n(n){switch(n){case"country-iso3":case"country-iso2":case"country-name":case"us-state-code":case"us-state-name":case"us-zip5":case"us-county-fips":return!0;default:return!1}}function Dn(n,i){let s=new Array(n.length),o=new Set,A=[],S=0;for(let g=0;g<n.length;++g){let I=Sn(n[g],i);if(s[g]=I,I!==null)S++;else{let h=n[g];if(h!=null){let m=String(h).trim();if(m.length>0){let N=m.toLowerCase();o.has(N)||(o.add(N),A.push(m))}}}}return{iso:s,unmatched:A,matchedRows:S,totalRows:n.length}}export{X as a,mn as b,j as c,In as d,Sn as e,_n as f,Dn as g};
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a as w,f as b}from"./chunk-D2KN5NIR.mjs";import C from"papaparse";var D=500,S=/^[+-]?\d{1,15}$/,E=/^[+-]?(\d{1,3}(,\d{3})*|\d+)(\.\d+)?([eE][+-]?\d+)?$/,R=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/,L=/^\d{1,2}[\/\-.]\d{1,2}[\/\-.]\d{2,4}$/;function I(n){let i=0,e=0,r=0,o=0;for(let a of n){if(a==null)continue;if(typeof a=="number"){o++,e++,Number.isInteger(a)&&i++;continue}if(a instanceof Date){o++,r++;continue}if(typeof a=="boolean"){o++;continue}let c=String(a).trim();if(c!==""){if(o++,S.test(c)){i++,e++;continue}if(E.test(c)){e++;continue}if((R.test(c)||L.test(c))&&!isNaN(Date.parse(c))){r++;continue}}}return o===0?"String":r/o>.9?"DateTime":i===o?"Integer":e===o?"Decimal":"String"}function x(n,i){if(n==null)return null;if(typeof n=="number")return i==="String"?String(n):n;if(n instanceof Date)return i==="DateTime"?n:n.toISOString();if(typeof n=="boolean")return String(n);let e=String(n).trim();if(e==="")return null;switch(i){case"Integer":return S.test(e)?parseInt(e,10):null;case"Decimal":return E.test(e)?parseFloat(e.replace(/,/g,"")):null;case"DateTime":{let r=Date.parse(e);return isNaN(r)?null:new Date(r)}default:return e}}function M(n){let i=(n||"").toLowerCase().replace(/\(.*$/,"").trim();return/^(tinyint|smallint|int|integer|int2|int4|int8|bigint|serial|bigserial)$/.test(i)?"Integer":/^(decimal|numeric|money|smallmoney|float|real|double|double precision|number)$/.test(i)?"Decimal":/^(date|datetime|datetime2|smalldatetime|datetimeoffset|timestamp|timestamptz|time)$/.test(i)?"DateTime":(/^(bit|bool|boolean)$/.test(i),"String")}function g(n,i,e){if(n.length===0)throw new Error("ingest: no columns were resolved from the source. Supply column descriptors, or use a source shape that carries them (grid/table/objects/sql).");let r=n.length,o=n.map((t,s)=>t.dataType??I(i.slice(0,D).map(l=>l?.[s]))),a=new Set((e.measures??[]).map(t=>t.toLowerCase())),c=new Set((e.dimensions??[]).map(t=>t.toLowerCase())),d=new Set((e.nonAdditive??[]).map(t=>t.toLowerCase())),T=n.map((t,s)=>{let l=t.name.toLowerCase(),u=t.isMeasure??((o[s]==="Integer"||o[s]==="Decimal")&&!w(t.name));a.has(l)&&(u=!0),c.has(l)&&(u=!1);let h={name:t.name,dataType:o[s],isMeasure:u};return u&&d.has(l)&&(h.discourageAggregationAcrossGroups=!0),h}),m=new b;m.dedupRows=e.dedup!==!1,m.setColumns(T);for(let t=0;t<i.length;t++){let s=i[t];m.addRow(Array.from({length:r},(l,u)=>x(s?.[u],o[u])),t)}let y=m.getColumnsWithStats(e.privacyLevel??"20",e.locale??"en"),f=new Map(y.map(t=>[t.name,t]));n.forEach(t=>{let s=f.get(t.name);s&&(t.format&&(s.modelFormat=t.format),t.description&&(s.modelDesc=t.description))});for(let[t,s]of Object.entries(e.formats??{})){let l=f.get(t);l&&(l.modelFormat=s)}for(let[t,s]of Object.entries(e.descriptions??{})){let l=f.get(t);l&&(l.modelDesc=s)}for(let t of e.groupBy??[]){let s=f.get(t);s&&(s.isGrouping=!0)}return{columns:y,rows:m.toObjectArray(),totalRows:m.getRowCount(),index:m}}function p(n,i){return n.map(e=>Array.isArray(e)?e:i.map(r=>e[r]))}function A(n,i){let e=[],r=new Set,o=Math.min(n.length,Math.max(1,i));for(let a=0;a<o;a++){let c=n[a];if(!(!c||typeof c!="object"))for(let d of Object.keys(c))r.has(d)||(r.add(d),e.push(d))}return e}function $(n,i={}){switch(n.kind){case"csv":{let e=C.parse(n.text,{skipEmptyLines:!0});if(e.errors?.length&&e.data.length===0)throw new Error(`ingest: CSV parse failed - ${e.errors[0].message}`);let r=e.data;if(r.length<2)throw new Error("ingest: CSV needs a header line plus at least one data row.");let o=r[0].map(a=>(a??"").trim());return g(o.map(a=>({name:a})),r.slice(1),i)}case"grid":{if(!n.header?.length)throw new Error("ingest: 'grid' needs a non-empty header.");return g(n.header.map(e=>({name:(e??"").trim()})),n.rows??[],i)}case"table":{if(!n.columns?.length)throw new Error("ingest: 'table' needs at least one column descriptor.");let e=n.columns.map(r=>r.name);return g(n.columns,p(n.rows??[],e),i)}case"objects":{let e=n.rows??[],r=n.columns?.length?n.columns:A(e,i.columnScanLimit??D).map(o=>({name:o}));if(!r.length)throw new Error("ingest: 'objects' produced no columns - the rows array is empty or holds no object keys.");return g(r,p(e,r.map(o=>o.name)),i)}case"sql":{if(!n.schema?.length)throw new Error("ingest: 'sql' needs at least one schema column.");let e=n.schema.map(r=>{let o=M(r.dataType);return{name:r.name,dataType:o,isMeasure:r.isMeasure,format:r.format,description:r.description}});return g(e,p(n.rows??[],e.map(r=>r.name)),i)}default:{let e=n;throw new Error(`ingest: unknown source kind '${e?.kind}'. Expected one of: csv, grid, table, objects, sql.`)}}}export{M as a,$ as b};
2
+ import{a as w,f as b}from"./chunk-U6HNXHXJ.mjs";import C from"papaparse";var D=500,S=/^[+-]?\d{1,15}$/,E=/^[+-]?(\d{1,3}(,\d{3})*|\d+)(\.\d+)?([eE][+-]?\d+)?$/,R=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/,L=/^\d{1,2}[\/\-.]\d{1,2}[\/\-.]\d{2,4}$/;function I(n){let i=0,e=0,r=0,o=0;for(let a of n){if(a==null)continue;if(typeof a=="number"){o++,e++,Number.isInteger(a)&&i++;continue}if(a instanceof Date){o++,r++;continue}if(typeof a=="boolean"){o++;continue}let c=String(a).trim();if(c!==""){if(o++,S.test(c)){i++,e++;continue}if(E.test(c)){e++;continue}if((R.test(c)||L.test(c))&&!isNaN(Date.parse(c))){r++;continue}}}return o===0?"String":r/o>.9?"DateTime":i===o?"Integer":e===o?"Decimal":"String"}function x(n,i){if(n==null)return null;if(typeof n=="number")return i==="String"?String(n):n;if(n instanceof Date)return i==="DateTime"?n:n.toISOString();if(typeof n=="boolean")return String(n);let e=String(n).trim();if(e==="")return null;switch(i){case"Integer":return S.test(e)?parseInt(e,10):null;case"Decimal":return E.test(e)?parseFloat(e.replace(/,/g,"")):null;case"DateTime":{let r=Date.parse(e);return isNaN(r)?null:new Date(r)}default:return e}}function M(n){let i=(n||"").toLowerCase().replace(/\(.*$/,"").trim();return/^(tinyint|smallint|int|integer|int2|int4|int8|bigint|serial|bigserial)$/.test(i)?"Integer":/^(decimal|numeric|money|smallmoney|float|real|double|double precision|number)$/.test(i)?"Decimal":/^(date|datetime|datetime2|smalldatetime|datetimeoffset|timestamp|timestamptz|time)$/.test(i)?"DateTime":(/^(bit|bool|boolean)$/.test(i),"String")}function g(n,i,e){if(n.length===0)throw new Error("ingest: no columns were resolved from the source. Supply column descriptors, or use a source shape that carries them (grid/table/objects/sql).");let r=n.length,o=n.map((t,s)=>t.dataType??I(i.slice(0,D).map(l=>l?.[s]))),a=new Set((e.measures??[]).map(t=>t.toLowerCase())),c=new Set((e.dimensions??[]).map(t=>t.toLowerCase())),d=new Set((e.nonAdditive??[]).map(t=>t.toLowerCase())),T=n.map((t,s)=>{let l=t.name.toLowerCase(),u=t.isMeasure??((o[s]==="Integer"||o[s]==="Decimal")&&!w(t.name));a.has(l)&&(u=!0),c.has(l)&&(u=!1);let h={name:t.name,dataType:o[s],isMeasure:u};return u&&d.has(l)&&(h.discourageAggregationAcrossGroups=!0),h}),m=new b;m.dedupRows=e.dedup!==!1,m.setColumns(T);for(let t=0;t<i.length;t++){let s=i[t];m.addRow(Array.from({length:r},(l,u)=>x(s?.[u],o[u])),t)}let y=m.getColumnsWithStats(e.privacyLevel??"20",e.locale??"en"),f=new Map(y.map(t=>[t.name,t]));n.forEach(t=>{let s=f.get(t.name);s&&(t.format&&(s.modelFormat=t.format),t.description&&(s.modelDesc=t.description))});for(let[t,s]of Object.entries(e.formats??{})){let l=f.get(t);l&&(l.modelFormat=s)}for(let[t,s]of Object.entries(e.descriptions??{})){let l=f.get(t);l&&(l.modelDesc=s)}for(let t of e.groupBy??[]){let s=f.get(t);s&&(s.isGrouping=!0)}return{columns:y,rows:m.toObjectArray(),totalRows:m.getRowCount(),index:m}}function p(n,i){return n.map(e=>Array.isArray(e)?e:i.map(r=>e[r]))}function A(n,i){let e=[],r=new Set,o=Math.min(n.length,Math.max(1,i));for(let a=0;a<o;a++){let c=n[a];if(!(!c||typeof c!="object"))for(let d of Object.keys(c))r.has(d)||(r.add(d),e.push(d))}return e}function $(n,i={}){switch(n.kind){case"csv":{let e=C.parse(n.text,{skipEmptyLines:!0});if(e.errors?.length&&e.data.length===0)throw new Error(`ingest: CSV parse failed - ${e.errors[0].message}`);let r=e.data;if(r.length<2)throw new Error("ingest: CSV needs a header line plus at least one data row.");let o=r[0].map(a=>(a??"").trim());return g(o.map(a=>({name:a})),r.slice(1),i)}case"grid":{if(!n.header?.length)throw new Error("ingest: 'grid' needs a non-empty header.");return g(n.header.map(e=>({name:(e??"").trim()})),n.rows??[],i)}case"table":{if(!n.columns?.length)throw new Error("ingest: 'table' needs at least one column descriptor.");let e=n.columns.map(r=>r.name);return g(n.columns,p(n.rows??[],e),i)}case"objects":{let e=n.rows??[],r=n.columns?.length?n.columns:A(e,i.columnScanLimit??D).map(o=>({name:o}));if(!r.length)throw new Error("ingest: 'objects' produced no columns - the rows array is empty or holds no object keys.");return g(r,p(e,r.map(o=>o.name)),i)}case"sql":{if(!n.schema?.length)throw new Error("ingest: 'sql' needs at least one schema column.");let e=n.schema.map(r=>{let o=M(r.dataType);return{name:r.name,dataType:o,isMeasure:r.isMeasure,format:r.format,description:r.description}});return g(e,p(n.rows??[],e.map(r=>r.name)),i)}default:{let e=n;throw new Error(`ingest: unknown source kind '${e?.kind}'. Expected one of: csv, grid, table, objects, sql.`)}}}export{M as a,$ as b};
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a as H}from"./chunk-QEH7WTLB.mjs";import{a as j,b as q}from"./chunk-2LR73DNS.mjs";import{a as Y,b as G,c as x}from"./chunk-NWDPA7DG.mjs";import{c as U}from"./chunk-7GWUBKNE.mjs";import{a as z,b as F,c as k}from"./chunk-WBEROMBG.mjs";import X from"papaparse";var Z=12,$=100,J=.3,Q=.9,tt=120,et=1900,nt=2100,it=0,st=20,rt=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function at(p){if(!p)return!1;let e=p.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-./]+/g," ").toLowerCase().split(/\s+/).filter(o=>o.length>0);return e.length===0?!1:rt.has(e[e.length-1])}var ot=/\b(year|yr|fy|fiscal\s*year|calendar\s*year)\b/i,ut=/^(?:(?:19|20)\d{2}(?:[-/ ]?(?:q[1-4]|w(?:0?[1-9]|[1-4]\d|5[0-3])|(?:0?[1-9]|1[0-2])))?|q[1-4][-/ ](?:19|20)\d{2}|(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[-/ ]?(?:19|20)?\d{2})$/i;function W(p){if(!Number.isInteger(p)||p<190001||p>210012)return!1;let e=p%100;return e>=1&&e<=12}function P(p){if(!Number.isInteger(p)||p<19000101||p>21001231)return!1;let e=Math.floor(p/100)%100,o=p%100;return e>=1&&e<=12&&o>=1&&o<=31}function lt(p,e){if(!e||!/\b(?:19|20)\d{2}\b/.test(p))return!1;let o=p.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!o)return!1;let c=j(o);return c.length>0&&e[c]!==void 0}function ct(p){let{dataType:e,name:o,isMeasure:c,distinctCount:f}=p;if(e==="DateTime")return!0;if(c)return!1;if(e==="Integer"||e==="Decimal"){let n=p.minNum,b=p.maxNum;if(!(n!=null&&b!=null&&Number.isFinite(n)&&Number.isFinite(b)&&Number.isInteger(n)&&Number.isInteger(b)&&b>=n))return!1;let T=n>=1900&&b<=2100;if(T&&f>=2&&ot.test(o)||T&&f>=3&&f===b-n+1)return!0;let M=W(n)&&W(b),D=P(n)&&P(b);if(M||D){if(!p.sampleValues)return!0;let h=0,N=0;for(let l of p.sampleValues){if(l==null||l==="")continue;h++;let t=Number(String(l).trim());if(Number.isFinite(t)&&(M?W(t):P(t))&&N++,h>=60)break}if(h>=2&&N===h)return!0}return!1}if(p.sampleValues){let n=p.locale?q(p.locale):null,b=0,I=0;for(let T of p.sampleValues){if(T==null||T==="")continue;b++;let M=String(T).trim();if((ut.test(M)||lt(M,n))&&I++,b>=60)break}if(b>=2&&I/b>=.8)return!0}return!1}function mt(p){let e=(p||"").trim().toLowerCase();return e.startsWith("sum ")||e.startsWith("total ")?"sum":e.startsWith("average ")||e.startsWith("avg. ")?"avg":e.startsWith("count ")||e.startsWith("distinct count ")||e.startsWith("count (distinct) ")?"count":e.startsWith("min ")||e.startsWith("minimum ")?"min":e.startsWith("max ")||e.startsWith("maximum ")?"max":null}function ft(p){let{rows:e,measureColIdx:o,measureName:c,candidateDims:f,minNum:n,maxNum:b,discourageAgg:I}=p,T=100,M=.01,D="";for(let N of f){if(N.distinct<2||N.distinct>T)continue;let l=f.filter(i=>i.idx!==N.idx).map(i=>i.idx),t=new Map;for(let i of e){let u=i[o];if(typeof u!="number"||!Number.isFinite(u))continue;let d=l.length?l.map(y=>String(i[y])).join(D):"",g=t.get(d);g||(g={sum:0,cset:new Set},t.set(d,g)),g.sum+=u,g.cset.add(String(i[N.idx]))}let r=0,a=0,s=0;for(let i of t.values())i.cset.size<2||(s++,Math.abs(i.sum-100)<=100*M?r++:Math.abs(i.sum-1)<=1*M&&a++);if(s>=2&&(r/s>=.9||a/s>=.9))return{additivity:"part_of_whole",partOfWholeDim:N.name}}if(I)return{additivity:"intensive_rate"};let h=mt(c);return h==="avg"||h==="min"||h==="max"?{additivity:"intensive_rate"}:h==="sum"||h==="count"?{additivity:"additive"}:n!=null&&b!=null&&Number.isFinite(n)&&Number.isFinite(b)&&n>=0&&b<=1.0001&&b>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function B(p){let{dataType:e,isMeasure:o,name:c,distinct:f,nonblank:n,prec:b,maxval:I,minval:T}=p,M=I-T+1,D=M>0?f/M:1,h=n>0?f/n:0,N=e==="Decimal"||b>0;return at(c)?"Categorical":D>=Q&&(z(c)&&f<=tt||T>=et&&I<=nt||T>=it&&I<=st)?"Ordinal":o||f>Z&&(N||f>=$||h>=J)?"Continuous":"Categorical"}var K=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;STR(e){return e==null?"":e.toString()}getPrecision(e){if(!isFinite(e))return 0;let c=e.toString().split(".")[1];return c?c.length:0}getColumns(){return this._cols}hasTimeComponent(e){return!(e instanceof Date)||isNaN(e.getTime())?!1:e.getHours()!==0||e.getMinutes()!==0||e.getSeconds()!==0||e.getMilliseconds()!==0}getColumnsWithStats(e,o){if(this._computedStatsForLevel==e)return this._cols;let c=0,f=parseInt(e),n=[];for(let t of this._cols){let r=new Map,a=[],s=0,i=0,u=0,d=null,g=null,y=null,w=!1,R=!0,A=!0,v=null,S=!1;for(let C of this._rows){let m=C[c],_=this.STR(m);if(_!=""){if(s+=_.length,r.set(_,(r.get(_)||0)+1),i++,t.dataType=="Integer"||t.dataType=="Decimal"||t.dataType=="DateTime")if((d===null||m<d)&&(d=m),(g===null||m>g)&&(g=m),t.dataType=="Integer"||t.dataType=="Decimal"){if(y===null?y=m:y+=m,t.dataType=="Decimal"){let L=this.getPrecision(m);L>u&&(u=L)}a.push(m)}else w=w||this.hasTimeComponent(m);S&&(m<v?R=!1:m>v&&(A=!1)),v=m,S=!0}}if(i>=3&&(R&&!A?t.sortedDirection="asc":A&&!R?t.sortedDirection="desc":t.sortedDirection="none"),i>0&&r.size>0&&!t.isMeasure){let C=0,m=Number.MAX_SAFE_INTEGER;for(let _ of r.values())_>C&&(C=_),_<m&&(m=_);if(t.modalShare=C/i,t.minGroupCount=m===Number.MAX_SAFE_INTEGER?null:m,r.size===2){let _=[...r.keys()].map(V=>Y(V).trim().toLowerCase()).sort(),E=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(V=>_[0]===V[0]&&_[1]===V[1]),O=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(t.name);(E||O)&&(t.isBinaryFlag=!0)}}t.dataType=="DateTime"&&(t.dateWithTime=w),t.isTemporal=ct({dataType:t.dataType,name:t.name,isMeasure:t.isMeasure,distinctCount:r.size,minNum:typeof d=="number"?d:null,maxNum:typeof g=="number"?g:null,sampleValues:r.keys(),locale:o}),this.updateColumnStats10(f,t,i,r,u,g,d),this.updateColumnStats20(f,a,i,y,t,s,w,d,g,u,r,o),!t.isMeasure&&(t.dataType==="Integer"||t.dataType==="Decimal")&&B({dataType:t.dataType,isMeasure:!1,name:t.name,distinct:r.size,nonblank:i,prec:u,maxval:typeof g=="number"?g:0,minval:typeof d=="number"?d:0})==="Continuous"&&(t.isMeasure=!0),n[c]=t.isMeasure||r.size>2e3?null:new Set(r.keys()),c++}let b=[];this._cols.forEach((t,r)=>{t.isMeasure||b.push({idx:r,distinct:t.distinctCount??0,name:t.name})}),this._cols.forEach((t,r)=>{if(!t.isMeasure)return;let a=typeof t.lowValue=="number"?t.lowValue:null,s=typeof t.highValue=="number"?t.highValue:null,i=ft({rows:this._rows,measureColIdx:r,measureName:t.name,candidateDims:b,minNum:a,maxNum:s,discourageAgg:!!t.discourageAggregationAcrossGroups});t.additivity=i.additivity,i.partOfWholeDim&&(t.partOfWholeDim=i.partOfWholeDim)});let I=50,T=b.filter(t=>t.distinct>=2&&t.distinct<=I);this._cols.forEach((t,r)=>{if(!t.isMeasure)return;let a=[];for(let v of this._rows){let S=v[r];if(S==null||S==="")continue;let C=typeof S=="number"?S:parseFloat(S);isNaN(C)||a.push(C)}if(a.length===0)return;let s=[...a].sort((v,S)=>v-S),i=v=>s[Math.min(s.length-1,Math.max(0,Math.floor(v*(s.length-1))))],u=i(.5),d=i(.1),g=i(.9),y=Math.abs(u)>1e-9?Math.abs(u):Math.abs(s[s.length-1])>1e-9?Math.abs(s[s.length-1]):1;t.relativeDispersion=Math.round((g-d)/y*1e3)/1e3;let w=0;for(let v of a)w+=v;w/=a.length;let R=0;for(let v of a)R+=(v-w)*(v-w);if(R<=1e-12)return;let A=[];for(let v of T){let S=new Map;for(let m of this._rows){let _=m[r];if(_==null||_==="")continue;let L=typeof _=="number"?_:parseFloat(_);if(isNaN(L))continue;let E=this.STR(m[v.idx])+"",O=S.get(E);O?(O.s+=L,O.n++):S.set(E,{s:L,n:1})}let C=0;for(let m of S.values()){let _=m.s/m.n;C+=m.n*(_-w)*(_-w)}A.push({otherColumn:v.name,eta2:Math.round(C/R*1e4)/1e4})}A.length>0&&(t.groupDiscrimination=A)});let M=.97,D=5,h=this._cols.map((t,r)=>({c:t,i:r})).filter(t=>t.c.isMeasure);for(let t=0;t<h.length;t++)for(let r=t+1;r<h.length;r++){let a=h[t].i,s=h[r].i,i=0,u=0,d=0,g=0,y=0,w=0;for(let S of this._rows){let C=S[a],m=S[s];if(C==null||C===""||m===null||m===void 0||m==="")continue;let _=typeof C=="number"?C:parseFloat(C),L=typeof m=="number"?m:parseFloat(m);isNaN(_)||isNaN(L)||(i++,u+=_,d+=L,g+=_*_,y+=L*L,w+=_*L)}if(i<D)continue;let R=i*g-u*u,A=i*y-d*d;if(R<=1e-12||A<=1e-12)continue;let v=(i*w-u*d)/Math.sqrt(R*A);if(Math.abs(v)>=M){let S=h[t].c,C=h[r].c;S.collinearWithMeasures||(S.collinearWithMeasures=[]),C.collinearWithMeasures||(C.collinearWithMeasures=[]),S.collinearWithMeasures.push(C.name),C.collinearWithMeasures.push(S.name)}}for(let t=0;t<this._cols.length;t++){let r=n[t];if(!r||r.size===0)continue;let a=[];for(let s=0;s<this._cols.length;s++){if(s===t)continue;let i=n[s];if(!i||i.size===0)continue;let u=0;for(let g of r)i.has(g)&&u++;let d=Math.round(u/r.size*100);d>0&&a.push({otherColumn:this._cols[s].name,percentShared:d})}a.length>0&&(this._cols[t].sharedValueRatioWithOthers=a)}let N=50,l=[];for(let t=0;t<this._cols.length;t++){let r=n[t];r&&r.size>=2&&r.size<=N&&l.push(t)}if(l.length>=2){let t=new Map,r=(s,i)=>s+":"+i;for(let s=0;s<l.length;s++)for(let i=s+1;i<l.length;i++)t.set(r(l[s],l[i]),new Map);for(let s of this._rows)for(let i=0;i<l.length;i++){let u=this.STR(s[l[i]])+"";for(let d=i+1;d<l.length;d++){let g=""+this.STR(s[l[d]]),y=t.get(r(l[i],l[d])),w=u+""+g;y.set(w,(y.get(w)??0)+1)}}let a=new Map;for(let s=0;s<l.length;s++)for(let i=s+1;i<l.length;i++){let u=l[s],d=l[i],g=n[u].size,y=n[d].size,w=t.get(r(u,d)),R=w.size,A=0;for(let m of w.values())(A===0||m<A)&&(A=m);let v=Math.round(R/(g*y)*100),S=R===g,C=R===y;if((this._cols[u].categoricalPairStats||=[]).push({otherColumn:this._cols[d].name,fillPct:v,determinesOther:S,minCellCount:A,distinctCombinations:R}),(this._cols[d].categoricalPairStats||=[]).push({otherColumn:this._cols[u].name,fillPct:v,determinesOther:C,minCellCount:A,distinctCombinations:R}),S&&g>y){let m=a.get(u);(!m||y<m.card)&&a.set(u,{name:this._cols[d].name,card:y,ratio:y/g})}if(C&&y>g){let m=a.get(d);(!m||g<m.card)&&a.set(d,{name:this._cols[u].name,card:g,ratio:g/y})}}for(let[s,i]of a)this._cols[s].primaryParentColumn=i.name,this._cols[s].nestingRatio=Math.round(i.ratio*100)/100}return this._computedStatsForLevel=e,this._cols}updateColumnStats20(e,o,c,f,n,b,I,T,M,D,h,N){if(e>=20){let l=[...o].sort((a,s)=>a-s),t=Math.floor(l.length/2);if(c>0&&f!=null?n.avgValue=n.dataType=="Integer"?Math.round(f/c):f/c:n.avgValue=null,c>0&&(n.avgLength=b/c),this._rows.length>0&&(n.dataType!="DateTime"||I||!T?n.lowValue=T:n.lowValue=new Date(T).toISOString().slice(0,10)+"T00:00:00.000Z",n.dataType!="DateTime"||I||!M?n.highValue=M:n.highValue=new Date(M).toISOString().slice(0,10)+"T00:00:00.000Z",n.medianValue=l.length===0?null:l.length%2===0?n.dataType=="Integer"?Math.round((l[t-1]+l[t])/2):(l[t-1]+l[t])/2:l[t],n.numericPrecision=D),l.length>0){let a=n.avgValue??0,s=l.length,i=0,u=0;for(let g of l){let y=g-a;i+=y*y,u+=y*y*y}let d=i/s;n.skewness=d===0?0:u/s/Math.pow(Math.sqrt(d),3),n.stdDev=Math.sqrt(d)}f!==null&&(n.sum=f);let r=Array.from(h.entries()).sort((a,s)=>s[1]-a[1]);if(n.topCategories=r.slice(0,10).map(a=>a[1]),!n.isMeasure&&r.length>0){if(n.dataType==="String"){let s=r.map(u=>u[0]);n.formatSignature=H(s);let i=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;n.formatSignature&&!i.test(n.formatSignature)&&(n.avgLength===void 0||n.avgLength>=3)&&(n.isFreeText=!0)}else n.topCategoryValues=r.slice(0,5).map(s=>s[0]);if(e>=20){let s=r.map(u=>u[0]),i=k(s,N);if(i!==null)n.ordinalPattern=i.pattern,n.orderedDomain=i.orderedDomain;else if(n.dataType==="String"){let u=F(s);u!==null&&(n.safeDistinctValues=u)}}let a=U(r.map(s=>s[0]),n.name,N);a!==null&&(n.geoKind=a.geoKind,n.geoMatchPct=a.geoMatchPct,a.geoAmbiguous&&(n.geoAmbiguous=!0))}if(l.length>=8&&(n.dataType==="Integer"||n.dataType==="Decimal")){let a=s=>l[Math.floor((l.length-1)*s)];n.quantiles={p05:a(.05),p25:a(.25),p75:a(.75),p95:a(.95)}}}}updateColumnStats10(e,o,c,f,n,b,I){e>=10&&(o.blankCount=this._rows.length-c,o.distinctCount=f.size+(o.blankCount!=0?1:0),o.valueNature="Categorical",c>0&&(o.dataType==="Integer"||o.dataType==="Decimal"?o.valueNature=B({dataType:o.dataType,isMeasure:!!o.isMeasure,name:o.name,distinct:f.size,nonblank:c,prec:n,maxval:b,minval:I}):o.dataType==="DateTime"&&(o.valueNature=o.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let e=[];if(this._cols.forEach((c,f)=>{c.isMeasure||e.push(f)}),e.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let o=new Set;for(let c of this._rows)o.add(JSON.stringify(e.map(f=>c[f])));return this._leafCardinality=o.size,this._leafCardinality}_leafCardinality=null;obfuscateString(e){let o="abcdefghijklmnopqrstuvwxyz",c=()=>o[Math.floor(x()*o.length)],f=()=>c().toUpperCase(),n=()=>Math.floor(x()*10).toString(),b=t=>/[A-Z]/.test(t)?f():/[a-z]/.test(t)?c():/[0-9]/.test(t)?n():t,I=e.includes("@")&&e.includes("."),T=I?e.split("@"):[e],M=I?T[1]:"",D=M.endsWith(".com"),h=D?".com":"",N=D?M.slice(0,-4):M,l=t=>{let r="";for(let a of t)r+=b(a),/[a-zA-Z0-9]/.test(a)&&x()<.2&&(r+=b(a));if(r.length>6){let a=Math.floor(x()*Math.min(3,r.length-6));for(let s=0;s<a;s++){let i=0;for(;i<5;){let u=Math.floor(x()*r.length);if(/[a-zA-Z0-9]/.test(r[u])){r=r.slice(0,u)+r.slice(u+1);break}i++}}}return r};if(I){let t=l(T[0]),r=l(N);return`${t}@${r}${h}`}else return l(e)}toObjectArray(){return this._rows.map(e=>{let o={};return this._cols.forEach((c,f)=>{o[c.name]=e[f]}),o})}async getCSVAsync(e){let o=[],c=e?25:1e7,f=e?4e3:1e7,n=new Map;for(let I of this._rows){let T={};for(let M=0;M<this._cols.length;M++){let D=this._cols[M],h=I[M];if(this.STR(h)!=""){if(e&&D.dataType=="String")if(n.has(h))h=n.get(h);else{let N=this.obfuscateString(h);n.set(h,N),h=N}else D.dataType=="DateTime"&&!D.dateWithTime&&(h=new Date(h).toISOString().slice(0,10)+"T00:00:00.000Z");f-=this.STR(h).length}else h=null;T[M]=h,--f}if(o.push(T),--c,c<=0||f<=0)break}return await X.unparse(o,{header:!1})}getCSVHeaderLine(){return X.unparse([this._cols.map(e=>this.STR(e.name))])}addRow(e,o){if(this.dedupRows){let c="";for(let n of e)c+=this.STR(n)+"~";let f=G(c);if(this._rowHashes.has(f))return!1;this._rowHashes.add(f)}return this._rows.push(e),this._origIndices.push(o??-1),!0}getOriginalRowIndex(e){return e<0||e>=this._origIndices.length?-1:this._origIndices[e]}reset(){this._cols=[],this._rows=[],this._origIndices=[],this._rowHashes=new Set,this._leafCardinality=null}setColumns(e){this._cols=e}};export{at as a,ct as b,mt as c,ft as d,B as e,K as f};
2
+ import{a as H}from"./chunk-QEH7WTLB.mjs";import{a as j,b as q}from"./chunk-2LR73DNS.mjs";import{a as Y,b as G,c as x}from"./chunk-NWDPA7DG.mjs";import{d as U}from"./chunk-3VJWHB2I.mjs";import{a as z,b as F,c as k}from"./chunk-WBEROMBG.mjs";import X from"papaparse";var Z=12,$=100,J=.3,Q=.9,tt=120,et=1900,nt=2100,it=0,st=20,rt=new Set(["id","ids","uuid","guid","key","zip","zipcode","postal","postalcode","ssn","code","codes","sku","isbn","msisdn","imei"]);function at(p){if(!p)return!1;let e=p.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-./]+/g," ").toLowerCase().split(/\s+/).filter(o=>o.length>0);return e.length===0?!1:rt.has(e[e.length-1])}var ot=/\b(year|yr|fy|fiscal\s*year|calendar\s*year)\b/i,ut=/^(?:(?:19|20)\d{2}(?:[-/ ]?(?:q[1-4]|w(?:0?[1-9]|[1-4]\d|5[0-3])|(?:0?[1-9]|1[0-2])))?|q[1-4][-/ ](?:19|20)\d{2}|(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*[-/ ]?(?:19|20)?\d{2})$/i;function W(p){if(!Number.isInteger(p)||p<190001||p>210012)return!1;let e=p%100;return e>=1&&e<=12}function P(p){if(!Number.isInteger(p)||p<19000101||p>21001231)return!1;let e=Math.floor(p/100)%100,o=p%100;return e>=1&&e<=12&&o>=1&&o<=31}function lt(p,e){if(!e||!/\b(?:19|20)\d{2}\b/.test(p))return!1;let o=p.replace(/\b(?:19|20)\d{2}\b/g,"").replace(/[-/.,]/g," ").trim();if(!o)return!1;let c=j(o);return c.length>0&&e[c]!==void 0}function ct(p){let{dataType:e,name:o,isMeasure:c,distinctCount:f}=p;if(e==="DateTime")return!0;if(c)return!1;if(e==="Integer"||e==="Decimal"){let n=p.minNum,b=p.maxNum;if(!(n!=null&&b!=null&&Number.isFinite(n)&&Number.isFinite(b)&&Number.isInteger(n)&&Number.isInteger(b)&&b>=n))return!1;let T=n>=1900&&b<=2100;if(T&&f>=2&&ot.test(o)||T&&f>=3&&f===b-n+1)return!0;let M=W(n)&&W(b),D=P(n)&&P(b);if(M||D){if(!p.sampleValues)return!0;let h=0,N=0;for(let l of p.sampleValues){if(l==null||l==="")continue;h++;let t=Number(String(l).trim());if(Number.isFinite(t)&&(M?W(t):P(t))&&N++,h>=60)break}if(h>=2&&N===h)return!0}return!1}if(p.sampleValues){let n=p.locale?q(p.locale):null,b=0,I=0;for(let T of p.sampleValues){if(T==null||T==="")continue;b++;let M=String(T).trim();if((ut.test(M)||lt(M,n))&&I++,b>=60)break}if(b>=2&&I/b>=.8)return!0}return!1}function mt(p){let e=(p||"").trim().toLowerCase();return e.startsWith("sum ")||e.startsWith("total ")?"sum":e.startsWith("average ")||e.startsWith("avg. ")?"avg":e.startsWith("count ")||e.startsWith("distinct count ")||e.startsWith("count (distinct) ")?"count":e.startsWith("min ")||e.startsWith("minimum ")?"min":e.startsWith("max ")||e.startsWith("maximum ")?"max":null}function ft(p){let{rows:e,measureColIdx:o,measureName:c,candidateDims:f,minNum:n,maxNum:b,discourageAgg:I}=p,T=100,M=.01,D="";for(let N of f){if(N.distinct<2||N.distinct>T)continue;let l=f.filter(i=>i.idx!==N.idx).map(i=>i.idx),t=new Map;for(let i of e){let u=i[o];if(typeof u!="number"||!Number.isFinite(u))continue;let d=l.length?l.map(y=>String(i[y])).join(D):"",g=t.get(d);g||(g={sum:0,cset:new Set},t.set(d,g)),g.sum+=u,g.cset.add(String(i[N.idx]))}let r=0,a=0,s=0;for(let i of t.values())i.cset.size<2||(s++,Math.abs(i.sum-100)<=100*M?r++:Math.abs(i.sum-1)<=1*M&&a++);if(s>=2&&(r/s>=.9||a/s>=.9))return{additivity:"part_of_whole",partOfWholeDim:N.name}}if(I)return{additivity:"intensive_rate"};let h=mt(c);return h==="avg"||h==="min"||h==="max"?{additivity:"intensive_rate"}:h==="sum"||h==="count"?{additivity:"additive"}:n!=null&&b!=null&&Number.isFinite(n)&&Number.isFinite(b)&&n>=0&&b<=1.0001&&b>0?{additivity:"intensive_rate"}:{additivity:"unknown"}}function B(p){let{dataType:e,isMeasure:o,name:c,distinct:f,nonblank:n,prec:b,maxval:I,minval:T}=p,M=I-T+1,D=M>0?f/M:1,h=n>0?f/n:0,N=e==="Decimal"||b>0;return at(c)?"Categorical":D>=Q&&(z(c)&&f<=tt||T>=et&&I<=nt||T>=it&&I<=st)?"Ordinal":o||f>Z&&(N||f>=$||h>=J)?"Continuous":"Categorical"}var K=class{_computedStatsForLevel=null;_cols=[];_rows=[];_origIndices=[];_rowHashes=new Set;dedupRows=!0;STR(e){return e==null?"":e.toString()}getPrecision(e){if(!isFinite(e))return 0;let c=e.toString().split(".")[1];return c?c.length:0}getColumns(){return this._cols}hasTimeComponent(e){return!(e instanceof Date)||isNaN(e.getTime())?!1:e.getHours()!==0||e.getMinutes()!==0||e.getSeconds()!==0||e.getMilliseconds()!==0}getColumnsWithStats(e,o){if(this._computedStatsForLevel==e)return this._cols;let c=0,f=parseInt(e),n=[];for(let t of this._cols){let r=new Map,a=[],s=0,i=0,u=0,d=null,g=null,y=null,w=!1,R=!0,A=!0,v=null,S=!1;for(let C of this._rows){let m=C[c],_=this.STR(m);if(_!=""){if(s+=_.length,r.set(_,(r.get(_)||0)+1),i++,t.dataType=="Integer"||t.dataType=="Decimal"||t.dataType=="DateTime")if((d===null||m<d)&&(d=m),(g===null||m>g)&&(g=m),t.dataType=="Integer"||t.dataType=="Decimal"){if(y===null?y=m:y+=m,t.dataType=="Decimal"){let L=this.getPrecision(m);L>u&&(u=L)}a.push(m)}else w=w||this.hasTimeComponent(m);S&&(m<v?R=!1:m>v&&(A=!1)),v=m,S=!0}}if(i>=3&&(R&&!A?t.sortedDirection="asc":A&&!R?t.sortedDirection="desc":t.sortedDirection="none"),i>0&&r.size>0&&!t.isMeasure){let C=0,m=Number.MAX_SAFE_INTEGER;for(let _ of r.values())_>C&&(C=_),_<m&&(m=_);if(t.modalShare=C/i,t.minGroupCount=m===Number.MAX_SAFE_INTEGER?null:m,r.size===2){let _=[...r.keys()].map(V=>Y(V).trim().toLowerCase()).sort(),E=[["false","true"],["no","yes"],["n","y"],["0","1"],["f","t"]].some(V=>_[0]===V[0]&&_[1]===V[1]),O=/^(is|has)[_a-z0-9]|(?:default|churn|fraud|approv|convert|active|cancel|delinquen|flag|paid|win|pass|fail)/i.test(t.name);(E||O)&&(t.isBinaryFlag=!0)}}t.dataType=="DateTime"&&(t.dateWithTime=w),t.isTemporal=ct({dataType:t.dataType,name:t.name,isMeasure:t.isMeasure,distinctCount:r.size,minNum:typeof d=="number"?d:null,maxNum:typeof g=="number"?g:null,sampleValues:r.keys(),locale:o}),this.updateColumnStats10(f,t,i,r,u,g,d),this.updateColumnStats20(f,a,i,y,t,s,w,d,g,u,r,o),!t.isMeasure&&(t.dataType==="Integer"||t.dataType==="Decimal")&&B({dataType:t.dataType,isMeasure:!1,name:t.name,distinct:r.size,nonblank:i,prec:u,maxval:typeof g=="number"?g:0,minval:typeof d=="number"?d:0})==="Continuous"&&(t.isMeasure=!0),n[c]=t.isMeasure||r.size>2e3?null:new Set(r.keys()),c++}let b=[];this._cols.forEach((t,r)=>{t.isMeasure||b.push({idx:r,distinct:t.distinctCount??0,name:t.name})}),this._cols.forEach((t,r)=>{if(!t.isMeasure)return;let a=typeof t.lowValue=="number"?t.lowValue:null,s=typeof t.highValue=="number"?t.highValue:null,i=ft({rows:this._rows,measureColIdx:r,measureName:t.name,candidateDims:b,minNum:a,maxNum:s,discourageAgg:!!t.discourageAggregationAcrossGroups});t.additivity=i.additivity,i.partOfWholeDim&&(t.partOfWholeDim=i.partOfWholeDim)});let I=50,T=b.filter(t=>t.distinct>=2&&t.distinct<=I);this._cols.forEach((t,r)=>{if(!t.isMeasure)return;let a=[];for(let v of this._rows){let S=v[r];if(S==null||S==="")continue;let C=typeof S=="number"?S:parseFloat(S);isNaN(C)||a.push(C)}if(a.length===0)return;let s=[...a].sort((v,S)=>v-S),i=v=>s[Math.min(s.length-1,Math.max(0,Math.floor(v*(s.length-1))))],u=i(.5),d=i(.1),g=i(.9),y=Math.abs(u)>1e-9?Math.abs(u):Math.abs(s[s.length-1])>1e-9?Math.abs(s[s.length-1]):1;t.relativeDispersion=Math.round((g-d)/y*1e3)/1e3;let w=0;for(let v of a)w+=v;w/=a.length;let R=0;for(let v of a)R+=(v-w)*(v-w);if(R<=1e-12)return;let A=[];for(let v of T){let S=new Map;for(let m of this._rows){let _=m[r];if(_==null||_==="")continue;let L=typeof _=="number"?_:parseFloat(_);if(isNaN(L))continue;let E=this.STR(m[v.idx])+"",O=S.get(E);O?(O.s+=L,O.n++):S.set(E,{s:L,n:1})}let C=0;for(let m of S.values()){let _=m.s/m.n;C+=m.n*(_-w)*(_-w)}A.push({otherColumn:v.name,eta2:Math.round(C/R*1e4)/1e4})}A.length>0&&(t.groupDiscrimination=A)});let M=.97,D=5,h=this._cols.map((t,r)=>({c:t,i:r})).filter(t=>t.c.isMeasure);for(let t=0;t<h.length;t++)for(let r=t+1;r<h.length;r++){let a=h[t].i,s=h[r].i,i=0,u=0,d=0,g=0,y=0,w=0;for(let S of this._rows){let C=S[a],m=S[s];if(C==null||C===""||m===null||m===void 0||m==="")continue;let _=typeof C=="number"?C:parseFloat(C),L=typeof m=="number"?m:parseFloat(m);isNaN(_)||isNaN(L)||(i++,u+=_,d+=L,g+=_*_,y+=L*L,w+=_*L)}if(i<D)continue;let R=i*g-u*u,A=i*y-d*d;if(R<=1e-12||A<=1e-12)continue;let v=(i*w-u*d)/Math.sqrt(R*A);if(Math.abs(v)>=M){let S=h[t].c,C=h[r].c;S.collinearWithMeasures||(S.collinearWithMeasures=[]),C.collinearWithMeasures||(C.collinearWithMeasures=[]),S.collinearWithMeasures.push(C.name),C.collinearWithMeasures.push(S.name)}}for(let t=0;t<this._cols.length;t++){let r=n[t];if(!r||r.size===0)continue;let a=[];for(let s=0;s<this._cols.length;s++){if(s===t)continue;let i=n[s];if(!i||i.size===0)continue;let u=0;for(let g of r)i.has(g)&&u++;let d=Math.round(u/r.size*100);d>0&&a.push({otherColumn:this._cols[s].name,percentShared:d})}a.length>0&&(this._cols[t].sharedValueRatioWithOthers=a)}let N=50,l=[];for(let t=0;t<this._cols.length;t++){let r=n[t];r&&r.size>=2&&r.size<=N&&l.push(t)}if(l.length>=2){let t=new Map,r=(s,i)=>s+":"+i;for(let s=0;s<l.length;s++)for(let i=s+1;i<l.length;i++)t.set(r(l[s],l[i]),new Map);for(let s of this._rows)for(let i=0;i<l.length;i++){let u=this.STR(s[l[i]])+"";for(let d=i+1;d<l.length;d++){let g=""+this.STR(s[l[d]]),y=t.get(r(l[i],l[d])),w=u+""+g;y.set(w,(y.get(w)??0)+1)}}let a=new Map;for(let s=0;s<l.length;s++)for(let i=s+1;i<l.length;i++){let u=l[s],d=l[i],g=n[u].size,y=n[d].size,w=t.get(r(u,d)),R=w.size,A=0;for(let m of w.values())(A===0||m<A)&&(A=m);let v=Math.round(R/(g*y)*100),S=R===g,C=R===y;if((this._cols[u].categoricalPairStats||=[]).push({otherColumn:this._cols[d].name,fillPct:v,determinesOther:S,minCellCount:A,distinctCombinations:R}),(this._cols[d].categoricalPairStats||=[]).push({otherColumn:this._cols[u].name,fillPct:v,determinesOther:C,minCellCount:A,distinctCombinations:R}),S&&g>y){let m=a.get(u);(!m||y<m.card)&&a.set(u,{name:this._cols[d].name,card:y,ratio:y/g})}if(C&&y>g){let m=a.get(d);(!m||g<m.card)&&a.set(d,{name:this._cols[u].name,card:g,ratio:g/y})}}for(let[s,i]of a)this._cols[s].primaryParentColumn=i.name,this._cols[s].nestingRatio=Math.round(i.ratio*100)/100}return this._computedStatsForLevel=e,this._cols}updateColumnStats20(e,o,c,f,n,b,I,T,M,D,h,N){if(e>=20){let l=[...o].sort((a,s)=>a-s),t=Math.floor(l.length/2);if(c>0&&f!=null?n.avgValue=n.dataType=="Integer"?Math.round(f/c):f/c:n.avgValue=null,c>0&&(n.avgLength=b/c),this._rows.length>0&&(n.dataType!="DateTime"||I||!T?n.lowValue=T:n.lowValue=new Date(T).toISOString().slice(0,10)+"T00:00:00.000Z",n.dataType!="DateTime"||I||!M?n.highValue=M:n.highValue=new Date(M).toISOString().slice(0,10)+"T00:00:00.000Z",n.medianValue=l.length===0?null:l.length%2===0?n.dataType=="Integer"?Math.round((l[t-1]+l[t])/2):(l[t-1]+l[t])/2:l[t],n.numericPrecision=D),l.length>0){let a=n.avgValue??0,s=l.length,i=0,u=0;for(let g of l){let y=g-a;i+=y*y,u+=y*y*y}let d=i/s;n.skewness=d===0?0:u/s/Math.pow(Math.sqrt(d),3),n.stdDev=Math.sqrt(d)}f!==null&&(n.sum=f);let r=Array.from(h.entries()).sort((a,s)=>s[1]-a[1]);if(n.topCategories=r.slice(0,10).map(a=>a[1]),!n.isMeasure&&r.length>0){if(n.dataType==="String"){let s=r.map(u=>u[0]);n.formatSignature=H(s);let i=/^(UUID|EMAIL_LIKE|URL_LIKE|PHONE_LIKE|NUMERIC_ID|HEX_ID|OPAQUE_ID_ALPHANUMERIC|DATE_STR|BOOLEAN)$/;n.formatSignature&&!i.test(n.formatSignature)&&(n.avgLength===void 0||n.avgLength>=3)&&(n.isFreeText=!0)}else n.topCategoryValues=r.slice(0,5).map(s=>s[0]);if(e>=20){let s=r.map(u=>u[0]),i=k(s,N);if(i!==null)n.ordinalPattern=i.pattern,n.orderedDomain=i.orderedDomain;else if(n.dataType==="String"){let u=F(s);u!==null&&(n.safeDistinctValues=u)}}let a=U(r.map(s=>s[0]),n.name,N);a!==null&&(n.geoKind=a.geoKind,n.geoMatchPct=a.geoMatchPct,a.geoAmbiguous&&(n.geoAmbiguous=!0))}if(l.length>=8&&(n.dataType==="Integer"||n.dataType==="Decimal")){let a=s=>l[Math.floor((l.length-1)*s)];n.quantiles={p05:a(.05),p25:a(.25),p75:a(.75),p95:a(.95)}}}}updateColumnStats10(e,o,c,f,n,b,I){e>=10&&(o.blankCount=this._rows.length-c,o.distinctCount=f.size+(o.blankCount!=0?1:0),o.valueNature="Categorical",c>0&&(o.dataType==="Integer"||o.dataType==="Decimal"?o.valueNature=B({dataType:o.dataType,isMeasure:!!o.isMeasure,name:o.name,distinct:f.size,nonblank:c,prec:n,maxval:b,minval:I}):o.dataType==="DateTime"&&(o.valueNature=o.dateWithTime?"Continuous":"Ordinal")))}getRowCount(){return this._rows.length}getLeafCardinality(){if(this._leafCardinality!==null)return this._leafCardinality;let e=[];if(this._cols.forEach((c,f)=>{c.isMeasure||e.push(f)}),e.length===0)return this._leafCardinality=this._rows.length,this._leafCardinality;let o=new Set;for(let c of this._rows)o.add(JSON.stringify(e.map(f=>c[f])));return this._leafCardinality=o.size,this._leafCardinality}_leafCardinality=null;obfuscateString(e){let o="abcdefghijklmnopqrstuvwxyz",c=()=>o[Math.floor(x()*o.length)],f=()=>c().toUpperCase(),n=()=>Math.floor(x()*10).toString(),b=t=>/[A-Z]/.test(t)?f():/[a-z]/.test(t)?c():/[0-9]/.test(t)?n():t,I=e.includes("@")&&e.includes("."),T=I?e.split("@"):[e],M=I?T[1]:"",D=M.endsWith(".com"),h=D?".com":"",N=D?M.slice(0,-4):M,l=t=>{let r="";for(let a of t)r+=b(a),/[a-zA-Z0-9]/.test(a)&&x()<.2&&(r+=b(a));if(r.length>6){let a=Math.floor(x()*Math.min(3,r.length-6));for(let s=0;s<a;s++){let i=0;for(;i<5;){let u=Math.floor(x()*r.length);if(/[a-zA-Z0-9]/.test(r[u])){r=r.slice(0,u)+r.slice(u+1);break}i++}}}return r};if(I){let t=l(T[0]),r=l(N);return`${t}@${r}${h}`}else return l(e)}toObjectArray(){return this._rows.map(e=>{let o={};return this._cols.forEach((c,f)=>{o[c.name]=e[f]}),o})}async getCSVAsync(e){let o=[],c=e?25:1e7,f=e?4e3:1e7,n=new Map;for(let I of this._rows){let T={};for(let M=0;M<this._cols.length;M++){let D=this._cols[M],h=I[M];if(this.STR(h)!=""){if(e&&D.dataType=="String")if(n.has(h))h=n.get(h);else{let N=this.obfuscateString(h);n.set(h,N),h=N}else D.dataType=="DateTime"&&!D.dateWithTime&&(h=new Date(h).toISOString().slice(0,10)+"T00:00:00.000Z");f-=this.STR(h).length}else h=null;T[M]=h,--f}if(o.push(T),--c,c<=0||f<=0)break}return await X.unparse(o,{header:!1})}getCSVHeaderLine(){return X.unparse([this._cols.map(e=>this.STR(e.name))])}addRow(e,o){if(this.dedupRows){let c="";for(let n of e)c+=this.STR(n)+"~";let f=G(c);if(this._rowHashes.has(f))return!1;this._rowHashes.add(f)}return this._rows.push(e),this._origIndices.push(o??-1),!0}getOriginalRowIndex(e){return e<0||e>=this._origIndices.length?-1:this._origIndices[e]}reset(){this._cols=[],this._rows=[],this._origIndices=[],this._rowHashes=new Set,this._leafCardinality=null}setColumns(e){this._cols=e}};export{at as a,ct as b,mt as c,ft as d,B as e,K as f};
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{c as a,d as b,e as c,f as d}from"./chunk-7GWUBKNE.mjs";import"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";export{d as buildGeoIsoColumn,a as detectGeo,c as isJoinGeoKind,b as toGeoIso};
2
+ import{d as a,e as b,f as c,g as d}from"./chunk-3VJWHB2I.mjs";import"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";export{d as buildGeoIsoColumn,a as detectGeo,c as isJoinGeoKind,b as toGeoIso};
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a as pt,b as yt}from"./chunk-3GD3OCV5.mjs";import{a as at,b as ct,c as ut,d as lt,e as ft,f as dt}from"./chunk-D2KN5NIR.mjs";import{a as nt}from"./chunk-QEH7WTLB.mjs";import{a as et,b as ot}from"./chunk-2LR73DNS.mjs";import{a as it,b as rt,c as st}from"./chunk-NWDPA7DG.mjs";import{a as p,b as A,c as Q,d as Z,e as Y,f as tt}from"./chunk-7GWUBKNE.mjs";import{a as M,f as b,g as V,h as q,i as f,j as F,k as U,l as x,m as W,n as X,o as j,p as k,q as J}from"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";import{a as E,b as H,c as K}from"./chunk-WBEROMBG.mjs";var L=2,_=400;function w(r){return!!b(r)}function m(r){let n=new Set;for(let e of r){if(e==null)continue;let i=M(String(e));if(!A(i)&&!n.has(i)&&(n.add(i),n.size>=_))break}return Array.from(n)}function h(r){let n=m(r);if(n.length===0||gt(r)<95)return!1;let e=n.filter(a=>w(a)&&!f(a)).length,i=n.filter(a=>!w(a)&&!!f(a)).length;return e>=1&&e>=i}var mt=new Set(["USA","CAN","MEX"]);function N(r,n){if(!f(r))return!1;let e=b(r);return e?n==="world"?!0:mt.has(e):!1}function gt(r){let n=m(r);if(n.length===0)return 0;let e=0;for(let i of n)w(i)&&e++;return Math.round(e/n.length*1e3)/10}function v(r){let n=m(r);if(n.length===0)return 0;let e=0;for(let i of n)f(i)&&e++;return Math.round(e/n.length*1e3)/10}function $(r){let n=new Set;for(let e of r){if(e==null)continue;let i=String(e).trim();if(!A(M(i))&&!n.has(i)&&(n.add(i),n.size>=_))break}return Array.from(n)}function B(r){let n=$(r);if(n.length===0)return 0;let e=0;for(let i of n)x(i).length>0&&e++;return Math.round(e/n.length*1e3)/10}function ht(r,n){let e=m(r);if(e.length===0)return 0;let i=0;for(let a of e)k(a,n)&&i++;return Math.round(i/e.length*1e3)/10}function T(r,n){let e=0;for(let i of m(r))n(i)&&e++;return e}function Ct(r,n){let e=0;for(let i of $(r))n(i)&&e++;return e}function Pt(r,n,e,i){let a=[],g=[],o={},G=new Set(r),y=t=>n.map(s=>s[t]);for(let t of["city","zip","lat","lon","country"]){let s=e?.[t];s&&G.has(s)&&(o[t]=s)}let l=e?.state;if(l&&G.has(l)){let t=y(l),s=m(t);s.length>0&&s.every(c=>N(c,i))?g.push(`state=${l} (every value is "CA", which is both Canada and California)`):h(t)?(g.push(`state=${l} (every value is a country, not a state)`),o.country||(o.country=l)):v(t)<95?g.push(`state=${l} (only ${v(t)}% of values are states/provinces)`):o.state=l}let d=new Set(Object.values(o).filter(Boolean)),C=r.filter(t=>!d.has(t)&&!t.startsWith("__"));if(!o.state){let t=null;for(let s of C){let c=y(s);if(h(c))continue;let u=v(c);if(u<95)continue;let S=T(c,P=>!!f(P)),O=T(c,P=>!!f(P)&&!N(P,i));S<L&&O<1||(!t||u>t.pct)&&(t={name:s,pct:u})}t&&(o.state=t.name,d.add(t.name),a.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of C){if(d.has(t))continue;let s=y(t),c=B(s);if(!(c<95)&&!(Ct(s,u=>x(u).length>0)<L)){o.zip=t,d.add(t),a.push(`zip=${t} (${c}% ZIP codes)`);break}}if(!o.country){for(let t of C)if(!d.has(t)&&h(y(t))){o.country=t,d.add(t),a.push(`country=${t}`);break}}if(!o.city){let t=null;for(let s of C){if(d.has(s))continue;let c=y(s),u=ht(c,i);u<95||T(c,S=>k(S,i))<L||(!t||u>t.pct)&&(t={name:s,pct:u})}t&&(o.city=t.name,a.push(`city=${t.name} (${t.pct}% known cities)`))}let I=o.country?y(o.country):[],R=!!o.country&&h(I),D=R?new Set(I.map(t=>b(t==null?null:String(t))).filter(Boolean)).size:0,z=R&&D>=2;return o.country&&!z&&!(o.city||o.state||o.zip||o.lat&&o.lon)&&g.push(R?`country=${o.country} (every row resolves to the same country - nothing to place apart)`:`country=${o.country} (values are not country identifiers)`),{bind:!!(o.city||o.state||o.zip||z||o.lat&&o.lon)?o:null,backfilled:a,refused:g}}export{st as GET_RANDOM,dt as IndexedText,p as ROLE_MATCH_PCT,rt as SIMPLE_STRING_HASH,it as STR,v as admin1MatchPct,tt as buildGeoIsoColumn,j as buildGeoPointColumns,J as cityMatchPct,lt as classifyAdditivity,ft as classifyNumericValueNature,ct as classifyTemporal,nt as detectFormatSignature,Q as detectGeo,K as detectOrdinalDomain,pt as engineTypeForSqlType,ut as hostAggHint,yt as ingest,A as isBlankLike,q as isCityTableLoaded,W as isGeoPointAmbiguity,at as isIdentifierName,Y as isJoinGeoKind,E as isOrdinalFriendlyName,h as looksLikeCountryColumn,ot as monthLookupFor,F as normalizeCountry,et as normalizeMonthKey,M as normalizePlaceName,V as registerCityTable,f as resolveAdmin1,X as resolveGeoPoint,Pt as resolvePointRoles,H as safeDistinctValuesToShip,Z as toGeoIso,B as zipMatchPct,x as zipPrefixCandidates,U as zipToPrefix3};
2
+ import{a as yt,b as mt}from"./chunk-TNJKZKAG.mjs";import{a as ct,b as ut,c as lt,d as ft,e as dt,f as pt}from"./chunk-U6HNXHXJ.mjs";import{a as et}from"./chunk-QEH7WTLB.mjs";import{a as ot,b as it}from"./chunk-2LR73DNS.mjs";import{a as rt,b as st,c as at}from"./chunk-NWDPA7DG.mjs";import{a as y,b as x,c as k,d as Q,e as Z,f as tt,g as nt}from"./chunk-3VJWHB2I.mjs";import{a as M,f as b,g as q,h as F,i as f,j as U,k as W,l as A,m as X,n as Y,o as j,p as T,q as J}from"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";import{a as H,b as K,c as V}from"./chunk-WBEROMBG.mjs";var L=2,$=400;function w(r){return!!b(r)}function m(r){let n=new Set;for(let e of r){if(e==null)continue;let i=M(String(e));if(!x(i)&&!n.has(i)&&(n.add(i),n.size>=$))break}return Array.from(n)}function h(r){let n=m(r);if(n.length===0||ht(r)<96)return!1;let e=n.filter(a=>w(a)&&!f(a)).length,i=n.filter(a=>!w(a)&&!!f(a)).length;return e>=1&&e>=i}var gt=new Set(["USA","CAN","MEX"]);function N(r,n){if(!f(r))return!1;let e=b(r);return e?n==="world"?!0:gt.has(e):!1}function ht(r){let n=m(r);if(n.length===0)return 0;let e=0;for(let i of n)w(i)&&e++;return Math.round(e/n.length*1e3)/10}function R(r){let n=m(r);if(n.length===0)return 0;let e=0;for(let i of n)f(i)&&e++;return Math.round(e/n.length*1e3)/10}function O(r){let n=new Set;for(let e of r){if(e==null)continue;let i=String(e).trim();if(!x(M(i))&&!n.has(i)&&(n.add(i),n.size>=$))break}return Array.from(n)}function B(r){let n=O(r);if(n.length===0)return 0;let e=0;for(let i of n)A(i).length>0&&e++;return Math.round(e/n.length*1e3)/10}function Ct(r,n){let e=m(r);if(e.length===0)return 0;let i=0;for(let a of e)T(a,n)&&i++;return Math.round(i/e.length*1e3)/10}function I(r,n){let e=0;for(let i of m(r))n(i)&&e++;return e}function Pt(r,n){let e=0;for(let i of O(r))n(i)&&e++;return e}function Mt(r,n,e,i){let a=[],g=[],o={},G=new Set(r),p=t=>n.map(s=>s[t]);for(let t of["city","zip","lat","lon","country"]){let s=e?.[t];s&&G.has(s)&&(o[t]=s)}let l=e?.state;if(l&&G.has(l)){let t=p(l),s=m(t);s.length>0&&s.every(c=>N(c,i))?g.push(`state=${l} (every value is "CA", which is both Canada and California)`):h(t)?(g.push(`state=${l} (every value is a country, not a state)`),o.country||(o.country=l)):R(t)<96?g.push(`state=${l} (only ${R(t)}% of values are states/provinces)`):o.state=l}let d=new Set(Object.values(o).filter(Boolean)),C=r.filter(t=>!d.has(t)&&!t.startsWith("__"));if(!o.state){let t=null;for(let s of C){let c=p(s);if(h(c))continue;let u=R(c);if(u<96)continue;let S=I(c,P=>!!f(P)),E=I(c,P=>!!f(P)&&!N(P,i));S<L&&E<1||(!t||u>t.pct)&&(t={name:s,pct:u})}t&&(o.state=t.name,d.add(t.name),a.push(`state=${t.name} (${t.pct}% states/provinces)`))}if(!o.zip)for(let t of C){if(d.has(t))continue;let s=p(t),c=B(s);if(!(c<96)&&!(Pt(s,u=>A(u).length>0)<L)){o.zip=t,d.add(t),a.push(`zip=${t} (${c}% ZIP codes)`);break}}if(!o.country){for(let t of C)if(!d.has(t)&&h(p(t))){o.country=t,d.add(t),a.push(`country=${t}`);break}}if(!o.city){let t=null;for(let s of C){if(d.has(s))continue;let c=p(s),u=Ct(c,i);u<k||I(c,S=>T(S,i))<L||(!t||u>t.pct)&&(t={name:s,pct:u})}t&&(o.city=t.name,a.push(`city=${t.name} (${t.pct}% known cities)`))}let _=o.country?p(o.country):[],v=!!o.country&&h(_),D=v?new Set(_.map(t=>b(t==null?null:String(t))).filter(Boolean)).size:0,z=v&&D>=2;return o.country&&!z&&!(o.city||o.state||o.zip||o.lat&&o.lon)&&g.push(v?`country=${o.country} (every row resolves to the same country - nothing to place apart)`:`country=${o.country} (values are not country identifiers)`),{bind:!!(o.city||o.state||o.zip||z||o.lat&&o.lon)?o:null,backfilled:a,refused:g}}export{k as CITY_ROLE_MATCH_PCT,at as GET_RANDOM,pt as IndexedText,y as ROLE_MATCH_PCT,st as SIMPLE_STRING_HASH,rt as STR,R as admin1MatchPct,nt as buildGeoIsoColumn,j as buildGeoPointColumns,J as cityMatchPct,ft as classifyAdditivity,dt as classifyNumericValueNature,ut as classifyTemporal,et as detectFormatSignature,Q as detectGeo,V as detectOrdinalDomain,yt as engineTypeForSqlType,lt as hostAggHint,mt as ingest,x as isBlankLike,F as isCityTableLoaded,X as isGeoPointAmbiguity,ct as isIdentifierName,tt as isJoinGeoKind,H as isOrdinalFriendlyName,h as looksLikeCountryColumn,it as monthLookupFor,U as normalizeCountry,ot as normalizeMonthKey,M as normalizePlaceName,q as registerCityTable,f as resolveAdmin1,Y as resolveGeoPoint,Mt as resolvePointRoles,K as safeDistinctValuesToShip,Z as toGeoIso,B as zipMatchPct,A as zipPrefixCandidates,W as zipToPrefix3};
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a,b,c,d,e,f}from"./chunk-D2KN5NIR.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-NWDPA7DG.mjs";import"./chunk-7GWUBKNE.mjs";import"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";import"./chunk-WBEROMBG.mjs";export{f as IndexedText,d as classifyAdditivity,e as classifyNumericValueNature,b as classifyTemporal,c as hostAggHint,a as isIdentifierName};
2
+ import{a,b,c,d,e,f}from"./chunk-U6HNXHXJ.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-NWDPA7DG.mjs";import"./chunk-3VJWHB2I.mjs";import"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";import"./chunk-WBEROMBG.mjs";export{f as IndexedText,d as classifyAdditivity,e as classifyNumericValueNature,b as classifyTemporal,c as hostAggHint,a as isIdentifierName};
package/dist/ingest.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a,b}from"./chunk-3GD3OCV5.mjs";import"./chunk-D2KN5NIR.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-NWDPA7DG.mjs";import"./chunk-7GWUBKNE.mjs";import"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";import"./chunk-WBEROMBG.mjs";export{a as engineTypeForSqlType,b as ingest};
2
+ import{a,b}from"./chunk-TNJKZKAG.mjs";import"./chunk-U6HNXHXJ.mjs";import"./chunk-QEH7WTLB.mjs";import"./chunk-2LR73DNS.mjs";import"./chunk-NWDPA7DG.mjs";import"./chunk-3VJWHB2I.mjs";import"./chunk-RPZZSD7D.mjs";import"./chunk-JH3W3DH7.mjs";import"./chunk-WBEROMBG.mjs";export{a as engineTypeForSqlType,b as ingest};
@@ -3,7 +3,7 @@ export type { IValueCollection } from "./indexedText";
3
3
  export { classifyTemporal, classifyAdditivity, classifyNumericValueNature, hostAggHint, isIdentifierName, } from "./indexedText";
4
4
  export type { LLMColumnWithValue } from "./models";
5
5
  export type { LLMRequestModifier, SimpleColumn, VegaRendererPayload, LLMClientHints, LLMRequestCode, LLMQualifyResult, LLMRequestCodeResult, GetLicenseStatusResult, } from "./models";
6
- export { ROLE_MATCH_PCT, isBlankLike } from "./matchQuality";
6
+ export { ROLE_MATCH_PCT, CITY_ROLE_MATCH_PCT, isBlankLike } from "./matchQuality";
7
7
  export { detectOrdinalDomain, safeDistinctValuesToShip, isOrdinalFriendlyName } from "./ordinalDetector";
8
8
  export { detectFormatSignature } from "./formatDetector";
9
9
  export { detectGeo, toGeoIso, buildGeoIsoColumn, isJoinGeoKind } from "./geoDetector";
@@ -4,9 +4,10 @@
4
4
  *
5
5
  * One number for every role — city, state, ZIP, country, and the choropleth region detector
6
6
  * (Joel 2026-08-02: "I would prefer one constant, so maybe we make that 95 and apply to
7
- * all"). Tune here and they all move together.
7
+ * all", revised to 96). Tune here and they all move together — except CITY, which has its own
8
+ * looser bar below for a reason worth reading.
8
9
  *
9
- * 95 is high enough that a column of something else cannot claim a role by accident, and
10
+ * 96 is high enough that a column of something else cannot claim a role by accident, and
10
11
  * loose enough to survive the odd bad row. Below it the data needs cleaning, which is the
11
12
  * user's call and not something to guess through.
12
13
  *
@@ -16,7 +17,7 @@
16
17
  * That protection was always really the MEASURE EXCLUSION (callers pass dimensions only);
17
18
  * 100 vs 95 never distinguished a revenue column from a ZIP column, since both score 100.
18
19
  */
19
- export declare const ROLE_MATCH_PCT = 95;
20
+ export declare const ROLE_MATCH_PCT = 96;
20
21
  /**
21
22
  * Is this ALREADY-NORMALIZED token a blank in disguise?
22
23
  *
@@ -24,3 +25,22 @@ export declare const ROLE_MATCH_PCT = 95;
24
25
  * catches the ones a person typed.
25
26
  */
26
27
  export declare function isBlankLike(normalized: string): boolean;
28
+ /**
29
+ * CITY is held LOWER, and deliberately so (Joel 2026-08-02: "maybe city is a good one to make
30
+ * lower - 80% even").
31
+ *
32
+ * The other roles are closed vocabularies. There are ~195 countries and ~90 admin1s in scope,
33
+ * every one with a short recorded set of spellings, so a real column of them scores at or
34
+ * near 100 and anything below is genuinely dirty data.
35
+ *
36
+ * City names are not that. They are open free text: "St. Louis" / "Saint Louis", "Ft. Worth",
37
+ * a neighbourhood standing in for its city, a suburb the gazetteer holds only under its metro
38
+ * name, a district office written as a place. A perfectly ordinary, perfectly usable city
39
+ * column routinely resolves 80-90% of its distinct values, and holding it to the closed-
40
+ * vocabulary bar would refuse the ROLE outright — which does not degrade the map, it removes
41
+ * it, because with no city role the City+State tier never engages at all.
42
+ *
43
+ * The rows that do not resolve are not silently placed: they come back unplaced and counted,
44
+ * which is the honest outcome and one the chart already reports.
45
+ */
46
+ export declare const CITY_ROLE_MATCH_PCT = 80;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bicharts/shape-core",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "Host-agnostic data-shape profiler: ingest a dataset's rows through IValueCollection.addRow and read back the measured shape as an LLMColumnWithValue[] payload \u2014 types, cardinality, temporal/ordinal detection, geographic region and point resolution, cross-column signals. MEASUREMENT only: the policy that decides what a measured shape means for chart selection lives server-side.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1,2 +0,0 @@
1
- /*! @bicharts/shape-core — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
- import{a as $,b as F,c as J,d as w,e as P,p as Z}from"./chunk-RPZZSD7D.mjs";var en=95,sn=new Set(["n a","none","null","nil","unknown","not applicable","not available","not specified","unspecified","missing","blank","empty","tbd","to be determined"]);function Sn(n){return n?sn.has(n):!0}var B=[["AL","Alabama"],["AK","Alaska"],["AZ","Arizona"],["AR","Arkansas"],["CA","California"],["CO","Colorado"],["CT","Connecticut"],["DE","Delaware"],["FL","Florida"],["GA","Georgia"],["HI","Hawaii"],["ID","Idaho"],["IL","Illinois"],["IN","Indiana"],["IA","Iowa"],["KS","Kansas"],["KY","Kentucky"],["LA","Louisiana"],["ME","Maine"],["MD","Maryland"],["MA","Massachusetts"],["MI","Michigan"],["MN","Minnesota"],["MS","Mississippi"],["MO","Missouri"],["MT","Montana"],["NE","Nebraska"],["NV","Nevada"],["NH","New Hampshire"],["NJ","New Jersey"],["NM","New Mexico"],["NY","New York"],["NC","North Carolina"],["ND","North Dakota"],["OH","Ohio"],["OK","Oklahoma"],["OR","Oregon"],["PA","Pennsylvania"],["RI","Rhode Island"],["SC","South Carolina"],["SD","South Dakota"],["TN","Tennessee"],["TX","Texas"],["UT","Utah"],["VT","Vermont"],["VA","Virginia"],["WA","Washington"],["WV","West Virginia"],["WI","Wisconsin"],["WY","Wyoming"],["DC","District of Columbia"],["PR","Puerto Rico"],["GU","Guam"],["VI","U.S. Virgin Islands"],["AS","American Samoa"],["MP","Northern Mariana Islands"]],X=new Set(B.map(n=>n[0])),on={"Ala.":"AL","Alab.":"AL","Ariz.":"AZ","Ark.":"AR","Calif.":"CA","Cal.":"CA","Colo.":"CO","Col.":"CO","Conn.":"CT","Del.":"DE","Fla.":"FL","Flor.":"FL","Ga.":"GA","Ill.":"IL","Ind.":"IN","Kan.":"KS","Kans.":"KS","Ky.":"KY","La.":"LA","Md.":"MD","Mass.":"MA","Mich.":"MI","Minn.":"MN","Miss.":"MS","Mo.":"MO","Mont.":"MT","Neb.":"NE","Nebr.":"NE","Nev.":"NV","N.H.":"NH","N.J.":"NJ","N.M.":"NM","N.Mex.":"NM","N. Mex.":"NM","N.Y.":"NY","N.C.":"NC","N.D.":"ND","N.Dak.":"ND","N. Dak.":"ND","Okla.":"OK","Ore.":"OR","Oreg.":"OR","Pa.":"PA","Penn.":"PA","Penna.":"PA","R.I.":"RI","S.C.":"SC","S.D.":"SD","S.Dak.":"SD","S. Dak.":"SD","Tenn.":"TN","Tex.":"TX","Vt.":"VT","Va.":"VA","Wash.":"WA","W.Va.":"WV","W. Va.":"WV","Wis.":"WI","Wisc.":"WI","Wyo.":"WY","D.C.":"DC","Wash. D.C.":"DC","Wash., D.C.":"DC","P.R.":"PR","V.I.":"VI"},j=(()=>{let n=new Map;for(let[i,s]of B)n.set(d(s),i);n.set(d("Washington DC"),"DC"),n.set(d("Washington D.C."),"DC"),n.set(d("US Virgin Islands"),"VI");for(let[i,s]of Object.entries(on)){let o=d(i);o&&!n.has(o)&&n.set(o,s)}return n})(),q=new Set(["01","02","04","05","06","08","09","10","11","12","13","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","44","45","46","47","48","49","50","51","53","54","55","56","60","66","69","72","78"]);function E(n){return n.trim().toUpperCase()}function d(n){return $(n)}var G=new Set(["country","countries","nation","nationality","iso","geo"]),L=new Set(["state","province","st"]),v=new Set(["zip","zipcode","postal","postcode","plz"]),rn=new Set(["county","fips","borough","parish"]),an=new Set(["city","cities","town","municipality","metro","location","place"]);function un(n){return n.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-./]+/g," ").toLowerCase().split(/\s+/).filter(i=>i.length>0)}function f(n,i){if(!n)return!1;for(let s of un(n))if(i.has(s))return!0;return!1}var cn=95,ln=5,fn=6e4;function Cn(n,i,s){if(!n||n.length===0)return null;let o=[],h=new Set;for(let t of n){if(t==null)continue;let e=String(t).trim();if(e.length===0)continue;let r=e.toLowerCase();if(!h.has(r)&&(h.add(r),o.push(e),o.length>fn))return null}let p=o.length;if(p<2)return null;let S=o.map(E),T=o.map(d),A=P(),m=0,N=0,y=0,K=0,C=0,g=0,D=0,W=0,z=0,V=0,O=0,Q=f(i,v);for(let t=0;t<p;++t){let e=S[t],r=T[t],l=o[t],I=J.has(e),_=X.has(e);w.has(e)&&m++,I&&N++,_&&y++,I&&_&&z++;let Y=A.has(r),k=j.has(r);Y&&K++,k&&C++,Y&&k&&V++,_&&k&&O++,(/^\d{5}(-\d{4})?$/.test(l)||Q&&/^\d{3,4}$/.test(l))&&g++,/^\d{5}$/.test(l)&&q.has(l.slice(0,2))&&D++,Z(r)&&W++}let H=t=>t/p*100,M=[],u=(t,e,r,l=!1)=>{let I=H(e);I<cn||e<2||l&&e<ln&&!f(i,t==="country-name"?G:t==="city-name"?an:L)||M.push({kind:t,matched:e,spec:r,pct:I})};u("country-iso3",m,6),u("country-name",K,5,!0),u("us-state-name",C,5,!0),u("us-zip5",g,4),u("us-county-fips",D,4),u("country-iso2",N,3),u("us-state-code",y,3),u("city-name",W,2,!0);let nn=y-O,tn=C-O;if(nn>0&&tn>0&&u("us-state-name",y+C-O,5,!0),M.length===0)return null;M.sort((t,e)=>e.pct-t.pct||e.spec-t.spec);let a=M[0],R=!1,U={"country-iso2":"us-state-code","us-state-code":"country-iso2","us-zip5":"us-county-fips","us-county-fips":"us-zip5","country-name":"us-state-name","us-state-name":"country-name"}[a.kind],b=M[1],x=U&&b&&b.kind===U&&Math.abs(a.pct-b.pct)<=15;if(a.kind==="country-iso2"||a.kind==="us-state-code"){let t=a.matched>0?z/a.matched:0,e=f(i,G),r=f(i,L);if(x||t>=.5){if(e&&!r)return c("country-iso2",N,!1);if(r&&!e)return c("us-state-code",y,!1);R=!0}}else if(a.kind==="us-zip5"||a.kind==="us-county-fips"){let t=D===g&&g===p,e=f(i,v),r=f(i,rn);return r&&!e?c("us-county-fips",D,!1):e&&!r?c("us-zip5",g,!1):t?c("us-zip5",g,!0):c("us-zip5",g,!1)}else if(x&&(a.kind==="country-name"||a.kind==="us-state-name")){let t=a.matched>0?V/a.matched:0,e=f(i,G),r=f(i,L);if(e&&!r)return c("country-name",K,!1);if(r&&!e)return c("us-state-name",C,!1);t>=.5&&(R=!0)}return c(a.kind,a.matched,R);function c(t,e,r){let l={geoKind:t,geoMatchPct:Math.round(H(e)*10)/10};return r&&(l.geoAmbiguous=!0),l}}function dn(n,i){if(n==null)return null;let s=String(n).trim();if(s.length===0)return null;switch(i){case"country-iso3":{let o=E(s);return w.has(o)?o:null}case"country-iso2":return F.get(E(s))??null;case"country-name":return P().get(d(s))??null;case"us-state-code":case"us-state-name":{let o=E(s);return X.has(o)?o:j.get(d(s))??null}case"us-zip5":{let o=/^(\d{5})(-\d{4})?$/.exec(s);return o?o[1]:/^\d{3,4}$/.test(s)?s.padStart(5,"0"):null}case"us-county-fips":return/^\d{5}$/.test(s)&&q.has(s.slice(0,2))?s:null;default:return null}}function Mn(n){switch(n){case"country-iso3":case"country-iso2":case"country-name":case"us-state-code":case"us-state-name":case"us-zip5":case"us-county-fips":return!0;default:return!1}}function In(n,i){let s=new Array(n.length),o=new Set,h=[],p=0;for(let S=0;S<n.length;++S){let T=dn(n[S],i);if(s[S]=T,T!==null)p++;else{let A=n[S];if(A!=null){let m=String(A).trim();if(m.length>0){let N=m.toLowerCase();o.has(N)||(o.add(N),h.push(m))}}}}return{iso:s,unmatched:h,matchedRows:p,totalRows:n.length}}export{en as a,Sn as b,Cn as c,dn as d,Mn as e,In as f};