@tidyjs/tidy
Advanced tools
Comparing version 2.0.4 to 2.0.5
function first(key) { | ||
const keyFn = typeof key === "function" ? key : (d) => d[key]; | ||
return (items) => keyFn(items[0]); | ||
return (items) => items.length ? keyFn(items[0]) : void 0; | ||
} | ||
@@ -5,0 +5,0 @@ |
function last(key) { | ||
const keyFn = typeof key === "function" ? key : (d) => d[key]; | ||
return (items) => keyFn(items[items.length - 1]); | ||
return (items) => items.length ? keyFn(items[items.length - 1]) : void 0; | ||
} | ||
@@ -5,0 +5,0 @@ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
const keyFn = typeof key === "function" ? key : (d) => d[key]; | ||
return (items) => keyFn(items[0]); | ||
return (items) => items.length ? keyFn(items[0]) : void 0; | ||
} | ||
@@ -10,0 +10,0 @@ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
const keyFn = typeof key === "function" ? key : (d) => d[key]; | ||
return (items) => keyFn(items[items.length - 1]); | ||
return (items) => items.length ? keyFn(items[items.length - 1]) : void 0; | ||
} | ||
@@ -10,0 +10,0 @@ |
@@ -1131,3 +1131,3 @@ (function (global, factory) { | ||
const keyFn = typeof key === "function" ? key : (d) => d[key]; | ||
return (items) => keyFn(items[0]); | ||
return (items) => items.length ? keyFn(items[0]) : void 0; | ||
} | ||
@@ -1137,3 +1137,3 @@ | ||
const keyFn = typeof key === "function" ? key : (d) => d[key]; | ||
return (items) => keyFn(items[items.length - 1]); | ||
return (items) => items.length ? keyFn(items[items.length - 1]) : void 0; | ||
} | ||
@@ -1140,0 +1140,0 @@ |
@@ -1,2 +0,2 @@ | ||
(function(l,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("d3-array")):typeof define=="function"&&define.amd?define(["exports","d3-array"],h):(l=typeof globalThis!="undefined"?globalThis:l||self,h(l.Tidy={},l.d3))})(this,function(l,h){"use strict";function z(n,...t){if(typeof n=="function")throw new Error("You must supply the data as the first argument to tidy()");let e=n;for(const r of t)e=r(e);return e}function on(n){return e=>e.filter(n)}function cn(n,t){return r=>{if(typeof n=="function"){if(!n(r))return r}else if(!n)return r;return z(r,...t)}}function sn(n){return e=>e.map(n)}function S(n){return n==null?[]:Array.isArray(n)?n:[n]}function ln(n){return e=>{if(n=S(n),!n.length){const u=new Set;for(const s of e)u.add(s);return Array.from(u)}const r=new Map,o=[],c=n[n.length-1];for(const u of e){let s=r,f=!1;for(const a of n){const d=typeof a=="function"?a(u):u[a];if(a===c){f=s.has(d),f||(o.push(u),s.set(d,!0));break}s.has(d)||s.set(d,new Map),s=s.get(d)}}return o}}function I(n){return e=>{const r=S(n).map(o=>typeof o=="function"?o:V(o));return e.slice().sort((o,c)=>{for(const u of r){const s=u(o,c);if(s!==0)return s}return 0})}}function V(n){return function(e,r){return h.ascending(e[n],r[n])}}function U(n){return function(e,r){return h.descending(e[n],r[n])}}function fn(n,t,e){let{position:r="start"}=e!=null?e:{};const o=r==="end"?-1:1,c=new Map;for(let s=0;s<t.length;++s)c.set(t[s],s);const u=typeof n=="function"?n:s=>s[n];return function(f,a){var d,i;const m=(d=c.get(u(f)))!=null?d:-1,y=(i=c.get(u(a)))!=null?i:-1;return m>=0&&y>=0?m-y:m>=0?o*-1:y>=0?o*1:0}}function D(n,t){return r=>{t=t!=null?t:{};const o={},c=Object.keys(n);for(const u of c)o[u]=n[u](r);if(t.rest&&r.length){const u=Object.keys(r[0]);for(const s of u)c.includes(s)||(o[s]=t.rest(s)(r))}return[o]}}function R(n,t,e,r){if(!n.length)return[];const o={};let c;if(r==null)c=Object.keys(n[0]);else{c=[];for(const u of S(r))typeof u=="function"?c.push(...u(n)):c.push(u)}for(const u of c){if(e){const s=n.map(f=>f[u]);if(!e(s))continue}o[u]=t(u)(n)}return[o]}function B(n){return e=>R(e,n)}function N(n,t){return r=>R(r,t,n)}function J(n,t){return r=>R(r,t,void 0,n)}function w(n){return e=>{const r=[];for(const o of e){const c={...o};for(const u in n){const s=n[u],f=typeof s=="function"?s(c):s;c[u]=f}r.push(c)}return r}}function an(n,t){return r=>{const o=D(n)(r),c=w(t)(o);return[...r,...c]}}function mn(n,t){return r=>{const o=B(n)(r),c=w(t)(o);return[...r,...c]}}function dn(n,t,e){return o=>{const c=N(n,t)(o),u=w(e)(c);return[...o,...u]}}function yn(n,t,e){return o=>{const c=J(n,t)(o),u=w(e)(c);return[...o,...u]}}function $(n,t){return{...n,...t.reduce((e,r)=>(e[r[0]]=r[1],e),{})}}function L(n,t,e,r,o,c=0){for(const[u,s]of n.entries()){const f=[...e,u];if(s instanceof Map){const a=r(t,f,c);L(s,a,f,r,o,c+1)}else o(t,f,s,c)}return t}function pn(n,t,e=r=>r[r.length-1]){function r(u,s){const f=new Map;return u.set(e(s),f),f}function o(u,s,f){u.set(e(s),t(f,s))}const c=new Map;return L(n,c,[],r,o),c}const O=n=>n;function _(n,t,e){return o=>{const c=gn(o,n),u=hn(c,t,e==null?void 0:e.addGroupKeys);if(e==null?void 0:e.export)switch(e.export){case"grouped":return u;case"entries":return k(u,{...e,export:"levels",levels:["entries"]});case"entries-object":case"entries-obj":case"entriesObject":return k(u,{...e,export:"levels",levels:["entries-object"]});case"object":return k(u,{...e,export:"levels",levels:["object"]});case"map":return k(u,{...e,export:"levels",levels:["map"]});case"keys":return k(u,{...e,export:"levels",levels:["keys"]});case"values":return k(u,{...e,export:"levels",levels:["values"]});case"levels":return k(u,e)}return vn(u,e==null?void 0:e.addGroupKeys)}}_.grouped=n=>({...n,export:"grouped"}),_.entries=n=>({...n,export:"entries"}),_.entriesObject=n=>({...n,export:"entries-object"}),_.object=n=>({...n,export:"object"}),_.map=n=>({...n,export:"map"}),_.keys=n=>({...n,export:"keys"}),_.values=n=>({...n,export:"values"}),_.levels=n=>({...n,export:"levels"});function hn(n,t,e){let r=n;if(!(t==null?void 0:t.length))return r;for(const o of t)r=pn(r,(c,u)=>{let f=o(c,{groupKeys:u});return e!==!1&&(f=f.map(a=>$(a,u))),f});return r}function gn(n,t){const e=S(t).map((o,c)=>{let u;typeof o=="function"?u=o.name?o.name:`group_${c}`:u=o.toString();const s=typeof o=="function"?o:a=>a[o],f=new Map;return a=>{const d=s(a);if(f.has(d))return f.get(d);const i=[u,d];return f.set(d,i),i}});return h.group(n,...e)}function vn(n,t){const e=[];return L(n,e,[],O,(r,o,c)=>{let u=c;t!==!1&&(u=c.map(s=>$(s,o))),r.push(...u)}),e}const _n=n=>n.join("/");function bn(n){var t;const{flat:e,single:r,mapLeaf:o=O,mapLeaves:c=O}=n;let u;return n.flat&&(u=(t=n.compositeKey)!=null?t:_n),{groupFn:(a,d)=>r?o($(a[0],d)):c(a.map(i=>o($(i,d)))),keyFn:e?a=>u(a.map(d=>d[1])):a=>a[a.length-1][1]}}function k(n,t){const{groupFn:e,keyFn:r}=bn(t);let{mapEntry:o=O}=t;const{levels:c=["entries"]}=t,u=[];for(const d of c)switch(d){case"entries":case"entries-object":case"entries-obj":case"entriesObject":{const i=d==="entries-object"||d==="entries-obj"||d==="entriesObject"?([m,y])=>({key:m,values:y}):o;u.push({id:"entries",createEmptySubgroup:()=>[],addSubgroup:(m,y,g,b)=>{m.push(i([g,y],b))},addLeaf:(m,y,g,b)=>{m.push(i([y,g],b))}});break}case"map":u.push({id:"map",createEmptySubgroup:()=>new Map,addSubgroup:(i,m,y)=>{i.set(y,m)},addLeaf:(i,m,y)=>{i.set(m,y)}});break;case"object":u.push({id:"object",createEmptySubgroup:()=>({}),addSubgroup:(i,m,y)=>{i[y]=m},addLeaf:(i,m,y)=>{i[m]=y}});break;case"keys":u.push({id:"keys",createEmptySubgroup:()=>[],addSubgroup:(i,m,y)=>{i.push([y,m])},addLeaf:(i,m)=>{i.push(m)}});break;case"values":u.push({id:"values",createEmptySubgroup:()=>[],addSubgroup:(i,m)=>{i.push(m)},addLeaf:(i,m,y)=>{i.push(y)}});break;default:typeof d=="object"&&u.push(d)}const s=(d,i,m)=>{var y,g;if(t.flat)return d;const b=(y=u[m])!=null?y:u[u.length-1],A=((g=u[m+1])!=null?g:b).createEmptySubgroup();return b.addSubgroup(d,A,r(i),m),A},f=(d,i,m,y)=>{var g;((g=u[y])!=null?g:u[u.length-1]).addLeaf(d,r(i),e(m,i),y)},a=u[0].createEmptySubgroup();return L(n,a,[],s,f)}function H(){return n=>n.length}function P(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.fsum(e,t)}function G(n){return e=>{const{name:r="n",wt:o}=n!=null?n:{};return D({[r]:o==null?H():P(o)})(e)}}function Sn(n,t){return r=>{t=t!=null?t:{};const{name:o="n",sort:c}=t;return z(r,_(n,[G(t)]),c?I(U(o)):O)}}function jn(n){return e=>e.map(r=>{var o;const c={},u=Object.keys(r);for(const s of u){const f=(o=n[s])!=null?o:s;c[f]=r[s]}return c})}function W(n,t){return r=>r.slice(n,t)}const kn=n=>W(0,n),wn=n=>W(-n);function Mn(n,t){return r=>I(t)(r).slice(0,n)}function Kn(n,t){return r=>I(t)(r).slice(-n).reverse()}function Fn(n,t){t=t!=null?t:{};const{replace:e}=t;return o=>{if(!o.length)return o.slice();if(e){const c=[];for(let u=0;u<n;++u)c.push(o[Math.floor(Math.random()*o.length)]);return c}return h.shuffle(o.slice()).slice(0,n)}}function Y(n,t){if(n.length===0||t.length===0)return{};const e=Object.keys(n[0]),r=Object.keys(t[0]),o={};for(const c of e)r.includes(c)&&(o[c]=c);return o}function Z(n){if(Array.isArray(n)){const t={};for(const e of n)t[e]=e;return t}else if(typeof n=="object")return n;return{[n]:n}}function Q(n,t,e){for(const r in e){const o=e[r];if(n[o]!==t[r])return!1}return!0}function In(n,t){return r=>{const o=(t==null?void 0:t.by)==null?Y(r,n):Z(t.by);return r.flatMap(u=>n.filter(f=>Q(u,f,o)).map(f=>({...u,...f})))}}function X(n,t){return r=>{const o=(t==null?void 0:t.by)==null?Y(r,n):Z(t.by);return r.flatMap(u=>{const s=n.filter(f=>Q(u,f,o));return s.length?s.map(f=>({...u,...f})):u})}}function On(n){return e=>{const r=e.map(o=>({...o}));for(const o in n){const c=n[o],u=typeof c=="function"?c(r):c,s=(u==null?void 0:u[Symbol.iterator])&&typeof u!="string"?u:e.map(()=>u);let f=-1;for(const a of r)a[o]=s[++f]}return r}}function M(n){return n.length<1?[]:Object.keys(n[0])}function x(){return n=>M(n)}function nn(n,t){let e=[];for(const c of S(t))typeof c=="function"?e.push(...c(n)):e.push(c);e.length&&e[0][0]==="-"&&(e=[...x()(n),...e]);const r={},o=[];for(let c=e.length-1;c>=0;c--){const u=e[c];if(u[0]==="-"){r[u.substring(1)]=!0;continue}if(r[u]){r[u]=!1;continue}o.unshift(u)}return e=Array.from(new Set(o)),e}function E(n){return e=>{let r=nn(e,n);return r.length?e.map(o=>{const c={};for(const u of r)c[u]=o[u];return c}):e}}function An(n){return e=>{const r=w(n)(e);return E(Object.keys(n))(r)}}function en(n){return e=>typeof n=="function"?[...e,...S(n(e))]:[...e,...S(n)]}function zn(n){return e=>{const{namesFrom:r,valuesFrom:o,valuesFill:c,valuesFillMap:u,namesSep:s="_"}=n,f=Array.isArray(r)?r:[r],a=Array.isArray(o)?o:[o],d=[];if(!e.length)return d;const i=Object.keys(e[0]).filter(p=>!f.includes(p)&&!a.includes(p)),m={};for(const p of e)for(const v of f)m[v]==null&&(m[v]={}),m[v][p[v]]=!0;const y=[];for(const p in m)y.push(Object.keys(m[p]));const g={},b=$n(s,y);for(const p of b){if(a.length===1){g[p]=u!=null?u[a[0]]:c;continue}for(const v of a)g[`${v}${s}${p}`]=u!=null?u[v]:c}function K(p){if(!p.length)return[];const v={...g};for(const j of i)v[j]=p[0][j];for(const j of p){const q=f.map(F=>j[F]).join(s);if(a.length===1){v[q]=j[a[0]];continue}for(const F of a)v[`${F}${s}${q}`]=j[F]}return[v]}return i.length?z(e,_(i,[K])):K(e)}}function $n(n="_",t){function e(o,c,u){if(!u.length&&c!=null){o.push(c);return}const s=u[0],f=u.slice(1);for(const a of s)e(o,c==null?a:`${c}${n}${a}`,f)}const r=[];return e(r,null,t),r}function Ln(n){return e=>{var r;const{namesTo:o,valuesTo:c,namesSep:u="_"}=n,s=(r=n.cols)!=null?r:[],f=nn(e,s),a=Array.isArray(o)?o:[o],d=Array.isArray(c)?c:[c],i=a.length>1,m=d.length>1,y=[];for(const g of e){const b=Object.keys(g).filter(p=>!f.includes(p)),K={};for(const p of b)K[p]=g[p];const A=m?Array.from(new Set(f.map(p=>p.substring(p.indexOf(u)+1)))):f;for(const p of A){const v={...K};for(const j of d){const q=m?`${j}${u}${p}`:p,F=i?p.split(u):[p];let fe=0;for(const ae of a){const ie=F[fe++];v[ae]=ie,v[j]=g[q]}}y.push(v)}}return y}}function tn(n){return e=>{const r=qn(n),o=[];for(const c in r){const u=r[c];let s;typeof u=="function"?s=u(e):Array.isArray(u)?s=u:s=Array.from(new Set(e.map(f=>f[c]))),o.push(s.map(f=>({[c]:f})))}return Tn(o)}}function Tn(n){function t(r,o,c){if(!c.length&&o!=null){r.push(o);return}const u=c[0],s=c.slice(1);for(const f of u)t(r,{...o,...f},s)}const e=[];return t(e,null,n),e}function qn(n){if(Array.isArray(n)){const t={};for(const e of n)t[e]=e;return t}else if(typeof n=="object")return n;return{[n]:n}}function un(n,t=1){let[e,r]=h.extent(n);const o=[];let c=e;for(;c<=r;)o.push(c),c+=t;return o}function C(n,t="day",e=1){let[r,o]=h.extent(n);const c=[];let u=new Date(r);for(;u<=o;)if(c.push(new Date(u)),t==="day"||t==="d"||t==="days")u.setUTCDate(u.getUTCDate()+1*e);else if(t==="week"||t==="w"||t==="weeks")u.setUTCDate(u.getUTCDate()+7*e);else if(t==="month"||t==="m"||t==="months")u.setUTCMonth(u.getUTCMonth()+1*e);else if(t==="year"||t==="y"||t==="years")u.setUTCFullYear(u.getUTCFullYear()+1*e);else throw new Error("Invalid granularity for date sequence: "+t);return c}function Dn(n,t){return function(r){t=t!=null?t:1;const o=typeof n=="function"?n:c=>c[n];return un(r.map(o),t)}}function Rn(n,t,e){return function(o){t=t!=null?t:"day",e=e!=null?e:1;const c=typeof n=="function"?n:u=>u[n];return C(o.map(c),t,e)}}function Wn(n,t,e){return function(o){t=t!=null?t:"day",e=e!=null?e:1;const c=typeof n=="function"?n:u=>u[n];return C(o.map(u=>new Date(c(u))),t,e).map(u=>u.toISOString())}}function rn(n){return e=>{const r=[];for(const o of e){const c={...o};for(const u in n)c[u]==null&&(c[u]=n[u]);r.push(c)}return r}}function En(n,t){return r=>{const o=tn(n)(r),c=X(r)(o);return t?rn(t)(c):c}}function Cn(n){return e=>{const r=S(n),o={};return e.map(c=>{const u={...c};for(const s of r)u[s]!=null?o[s]=u[s]:o[s]!=null&&(u[s]=o[s]);return u})}}function Vn(n,t){return(r,o)=>{var c;let u="[tidy.debug";if((c=o==null?void 0:o.groupKeys)==null?void 0:c.length){const y=o.groupKeys.map(g=>g.join(": ")).join(", ");y.length&&(u+="|"+y)}t=t!=null?t:{};const{limit:s=10,output:f="table"}=t,a="--------------------------------------------------------------------------------";let d=a.length;const i=u+"]"+(n==null?"":" "+n);return d=Math.max(0,d-(i.length+2)),console.log(`${i} ${a.substring(0,d)}`),console[f](s==null||s>=r.length?r:r.slice(0,s)),r}}function T(n,t,e){return n==null||t==null?void 0:t===0&&n===0?0:!e&&t===0?void 0:n/t}var Un=Object.freeze({__proto__:null,rate:T});function Bn(n,t,e){const r=typeof n=="function"?n:s=>s[n],o=typeof t=="function"?t:s=>s[t],{predicate:c,allowDivideByZero:u}=e!=null?e:{};return c==null?s=>{const f=o(s),a=r(s);return T(a,f,u)}:s=>{if(!c(s))return;const f=o(s),a=r(s);return T(a,f,u)}}function Nn(n,t){let e=new h.Adder,r=0;return Float64Array.from(n,o=>e.add(+(t(o,r++,n)||0)))}function Jn(n,t){let e=0;for(let r=0;r<n.length;++r){const o=t(n[r],r,n);+o===o&&(e+=1)}return e?h.fsum(n,t)/e:void 0}function Hn(n){const t=typeof n=="function"?n:e=>e[n];return e=>Nn(e,t)}function Pn(n,t,e){const{partial:r=!1}=e!=null?e:{};return o=>o.map((c,u)=>{const s=u;if(!r&&s-n+1<0)return;const f=Math.max(0,s-n+1),a=o.slice(f,s+1);return t(a,s)})}function Gn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.min(e,t)}function Yn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.max(e,t)}function Zn(n){const t=typeof n=="function"?n:e=>e[n];return e=>Jn(e,t)}function Qn(n,t){const e=typeof n=="function"?n:o=>o[n],r=typeof t=="function"?t:o=>o[t];return o=>{const c=h.fsum(o,e),u=h.fsum(o,r);return T(c,u)}}function Xn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.median(e,t)}function xn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.deviation(e,t)}function ne(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.variance(e,t)}function ee(n){const t=typeof n=="function"?n:e=>e[n];return e=>t(e[0])}function te(n){const t=typeof n=="function"?n:e=>e[n];return e=>t(e[e.length-1])}function ue(n,t=!0){return e=>{const r=new RegExp(`^${n}`,t?"i":void 0);return M(e).filter(c=>r.test(c))}}function re(n,t=!0){return e=>{const r=new RegExp(`${n}$`,t?"i":void 0);return M(e).filter(c=>r.test(c))}}function oe(n,t=!0){return e=>{const r=new RegExp(n,t?"i":void 0);return M(e).filter(c=>r.test(c))}}function ce(n){return t=>M(t).filter(r=>n.test(r))}function se(n,t,e){return r=>{const o=M(r),c=[];for(let u=t[0];u<=t[1];++u){const s=e==null?u:new String("00000000"+u).slice(-e);c.push(`${n}${s}`)}return o.filter(u=>c.includes(u))}}function le(n){return t=>{let e=new Set;for(const o of S(n))if(typeof o=="function"){const c=o(t);for(const u of c)e.add(u)}else e.add(o);return Array.from(e).map(o=>`-${o}`)}}l.TMath=Un,l.addItems=en,l.addRows=en,l.arrange=I,l.asc=V,l.complete=En,l.contains=oe,l.count=Sn,l.cumsum=Hn,l.debug=Vn,l.desc=U,l.deviation=xn,l.distinct=ln,l.endsWith=re,l.everything=x,l.expand=tn,l.fill=Cn,l.filter=on,l.first=ee,l.fixedOrder=fn,l.fullSeq=Dn,l.fullSeqDate=Rn,l.fullSeqDateISOString=Wn,l.groupBy=_,l.innerJoin=In,l.last=te,l.leftJoin=X,l.map=sn,l.matches=ce,l.max=Yn,l.mean=Zn,l.meanRate=Qn,l.median=Xn,l.min=Gn,l.mutate=w,l.mutateWithSummary=On,l.n=H,l.negate=le,l.numRange=se,l.pick=E,l.pivotLonger=Ln,l.pivotWider=zn,l.rate=Bn,l.rename=jn,l.replaceNully=rn,l.roll=Pn,l.select=E,l.slice=W,l.sliceHead=kn,l.sliceMax=Kn,l.sliceMin=Mn,l.sliceSample=Fn,l.sliceTail=wn,l.sort=I,l.startsWith=ue,l.sum=P,l.summarize=D,l.summarizeAll=B,l.summarizeAt=J,l.summarizeIf=N,l.tally=G,l.tidy=z,l.total=an,l.totalAll=mn,l.totalAt=yn,l.totalIf=dn,l.transmute=An,l.variance=ne,l.vectorSeq=un,l.vectorSeqDate=C,l.when=cn,Object.defineProperty(l,"__esModule",{value:!0})}); | ||
(function(l,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("d3-array")):typeof define=="function"&&define.amd?define(["exports","d3-array"],h):(l=typeof globalThis!="undefined"?globalThis:l||self,h(l.Tidy={},l.d3))})(this,function(l,h){"use strict";function z(n,...t){if(typeof n=="function")throw new Error("You must supply the data as the first argument to tidy()");let e=n;for(const o of t)e=o(e);return e}function rn(n){return e=>e.filter(n)}function cn(n,t){return o=>{if(typeof n=="function"){if(!n(o))return o}else if(!n)return o;return z(o,...t)}}function sn(n){return e=>e.map(n)}function S(n){return n==null?[]:Array.isArray(n)?n:[n]}function ln(n){return e=>{if(n=S(n),!n.length){const u=new Set;for(const s of e)u.add(s);return Array.from(u)}const o=new Map,r=[],c=n[n.length-1];for(const u of e){let s=o,f=!1;for(const a of n){const d=typeof a=="function"?a(u):u[a];if(a===c){f=s.has(d),f||(r.push(u),s.set(d,!0));break}s.has(d)||s.set(d,new Map),s=s.get(d)}}return r}}function I(n){return e=>{const o=S(n).map(r=>typeof r=="function"?r:V(r));return e.slice().sort((r,c)=>{for(const u of o){const s=u(r,c);if(s!==0)return s}return 0})}}function V(n){return function(e,o){return h.ascending(e[n],o[n])}}function U(n){return function(e,o){return h.descending(e[n],o[n])}}function fn(n,t,e){let{position:o="start"}=e!=null?e:{};const r=o==="end"?-1:1,c=new Map;for(let s=0;s<t.length;++s)c.set(t[s],s);const u=typeof n=="function"?n:s=>s[n];return function(f,a){var d,i;const m=(d=c.get(u(f)))!=null?d:-1,y=(i=c.get(u(a)))!=null?i:-1;return m>=0&&y>=0?m-y:m>=0?r*-1:y>=0?r*1:0}}function D(n,t){return o=>{t=t!=null?t:{};const r={},c=Object.keys(n);for(const u of c)r[u]=n[u](o);if(t.rest&&o.length){const u=Object.keys(o[0]);for(const s of u)c.includes(s)||(r[s]=t.rest(s)(o))}return[r]}}function R(n,t,e,o){if(!n.length)return[];const r={};let c;if(o==null)c=Object.keys(n[0]);else{c=[];for(const u of S(o))typeof u=="function"?c.push(...u(n)):c.push(u)}for(const u of c){if(e){const s=n.map(f=>f[u]);if(!e(s))continue}r[u]=t(u)(n)}return[r]}function B(n){return e=>R(e,n)}function N(n,t){return o=>R(o,t,n)}function J(n,t){return o=>R(o,t,void 0,n)}function w(n){return e=>{const o=[];for(const r of e){const c={...r};for(const u in n){const s=n[u],f=typeof s=="function"?s(c):s;c[u]=f}o.push(c)}return o}}function an(n,t){return o=>{const r=D(n)(o),c=w(t)(r);return[...o,...c]}}function mn(n,t){return o=>{const r=B(n)(o),c=w(t)(r);return[...o,...c]}}function dn(n,t,e){return r=>{const c=N(n,t)(r),u=w(e)(c);return[...r,...u]}}function yn(n,t,e){return r=>{const c=J(n,t)(r),u=w(e)(c);return[...r,...u]}}function $(n,t){return{...n,...t.reduce((e,o)=>(e[o[0]]=o[1],e),{})}}function L(n,t,e,o,r,c=0){for(const[u,s]of n.entries()){const f=[...e,u];if(s instanceof Map){const a=o(t,f,c);L(s,a,f,o,r,c+1)}else r(t,f,s,c)}return t}function pn(n,t,e=o=>o[o.length-1]){function o(u,s){const f=new Map;return u.set(e(s),f),f}function r(u,s,f){u.set(e(s),t(f,s))}const c=new Map;return L(n,c,[],o,r),c}const O=n=>n;function _(n,t,e){return r=>{const c=gn(r,n),u=hn(c,t,e==null?void 0:e.addGroupKeys);if(e==null?void 0:e.export)switch(e.export){case"grouped":return u;case"entries":return k(u,{...e,export:"levels",levels:["entries"]});case"entries-object":case"entries-obj":case"entriesObject":return k(u,{...e,export:"levels",levels:["entries-object"]});case"object":return k(u,{...e,export:"levels",levels:["object"]});case"map":return k(u,{...e,export:"levels",levels:["map"]});case"keys":return k(u,{...e,export:"levels",levels:["keys"]});case"values":return k(u,{...e,export:"levels",levels:["values"]});case"levels":return k(u,e)}return vn(u,e==null?void 0:e.addGroupKeys)}}_.grouped=n=>({...n,export:"grouped"}),_.entries=n=>({...n,export:"entries"}),_.entriesObject=n=>({...n,export:"entries-object"}),_.object=n=>({...n,export:"object"}),_.map=n=>({...n,export:"map"}),_.keys=n=>({...n,export:"keys"}),_.values=n=>({...n,export:"values"}),_.levels=n=>({...n,export:"levels"});function hn(n,t,e){let o=n;if(!(t==null?void 0:t.length))return o;for(const r of t)o=pn(o,(c,u)=>{let f=r(c,{groupKeys:u});return e!==!1&&(f=f.map(a=>$(a,u))),f});return o}function gn(n,t){const e=S(t).map((r,c)=>{let u;typeof r=="function"?u=r.name?r.name:`group_${c}`:u=r.toString();const s=typeof r=="function"?r:a=>a[r],f=new Map;return a=>{const d=s(a);if(f.has(d))return f.get(d);const i=[u,d];return f.set(d,i),i}});return h.group(n,...e)}function vn(n,t){const e=[];return L(n,e,[],O,(o,r,c)=>{let u=c;t!==!1&&(u=c.map(s=>$(s,r))),o.push(...u)}),e}const _n=n=>n.join("/");function bn(n){var t;const{flat:e,single:o,mapLeaf:r=O,mapLeaves:c=O}=n;let u;return n.flat&&(u=(t=n.compositeKey)!=null?t:_n),{groupFn:(a,d)=>o?r($(a[0],d)):c(a.map(i=>r($(i,d)))),keyFn:e?a=>u(a.map(d=>d[1])):a=>a[a.length-1][1]}}function k(n,t){const{groupFn:e,keyFn:o}=bn(t);let{mapEntry:r=O}=t;const{levels:c=["entries"]}=t,u=[];for(const d of c)switch(d){case"entries":case"entries-object":case"entries-obj":case"entriesObject":{const i=d==="entries-object"||d==="entries-obj"||d==="entriesObject"?([m,y])=>({key:m,values:y}):r;u.push({id:"entries",createEmptySubgroup:()=>[],addSubgroup:(m,y,g,b)=>{m.push(i([g,y],b))},addLeaf:(m,y,g,b)=>{m.push(i([y,g],b))}});break}case"map":u.push({id:"map",createEmptySubgroup:()=>new Map,addSubgroup:(i,m,y)=>{i.set(y,m)},addLeaf:(i,m,y)=>{i.set(m,y)}});break;case"object":u.push({id:"object",createEmptySubgroup:()=>({}),addSubgroup:(i,m,y)=>{i[y]=m},addLeaf:(i,m,y)=>{i[m]=y}});break;case"keys":u.push({id:"keys",createEmptySubgroup:()=>[],addSubgroup:(i,m,y)=>{i.push([y,m])},addLeaf:(i,m)=>{i.push(m)}});break;case"values":u.push({id:"values",createEmptySubgroup:()=>[],addSubgroup:(i,m)=>{i.push(m)},addLeaf:(i,m,y)=>{i.push(y)}});break;default:typeof d=="object"&&u.push(d)}const s=(d,i,m)=>{var y,g;if(t.flat)return d;const b=(y=u[m])!=null?y:u[u.length-1],A=((g=u[m+1])!=null?g:b).createEmptySubgroup();return b.addSubgroup(d,A,o(i),m),A},f=(d,i,m,y)=>{var g;((g=u[y])!=null?g:u[u.length-1]).addLeaf(d,o(i),e(m,i),y)},a=u[0].createEmptySubgroup();return L(n,a,[],s,f)}function H(){return n=>n.length}function P(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.fsum(e,t)}function G(n){return e=>{const{name:o="n",wt:r}=n!=null?n:{};return D({[o]:r==null?H():P(r)})(e)}}function Sn(n,t){return o=>{t=t!=null?t:{};const{name:r="n",sort:c}=t;return z(o,_(n,[G(t)]),c?I(U(r)):O)}}function jn(n){return e=>e.map(o=>{var r;const c={},u=Object.keys(o);for(const s of u){const f=(r=n[s])!=null?r:s;c[f]=o[s]}return c})}function W(n,t){return o=>o.slice(n,t)}const kn=n=>W(0,n),wn=n=>W(-n);function Mn(n,t){return o=>I(t)(o).slice(0,n)}function Kn(n,t){return o=>I(t)(o).slice(-n).reverse()}function Fn(n,t){t=t!=null?t:{};const{replace:e}=t;return r=>{if(!r.length)return r.slice();if(e){const c=[];for(let u=0;u<n;++u)c.push(r[Math.floor(Math.random()*r.length)]);return c}return h.shuffle(r.slice()).slice(0,n)}}function Y(n,t){if(n.length===0||t.length===0)return{};const e=Object.keys(n[0]),o=Object.keys(t[0]),r={};for(const c of e)o.includes(c)&&(r[c]=c);return r}function Z(n){if(Array.isArray(n)){const t={};for(const e of n)t[e]=e;return t}else if(typeof n=="object")return n;return{[n]:n}}function Q(n,t,e){for(const o in e){const r=e[o];if(n[r]!==t[o])return!1}return!0}function In(n,t){return o=>{const r=(t==null?void 0:t.by)==null?Y(o,n):Z(t.by);return o.flatMap(u=>n.filter(f=>Q(u,f,r)).map(f=>({...u,...f})))}}function X(n,t){return o=>{const r=(t==null?void 0:t.by)==null?Y(o,n):Z(t.by);return o.flatMap(u=>{const s=n.filter(f=>Q(u,f,r));return s.length?s.map(f=>({...u,...f})):u})}}function On(n){return e=>{const o=e.map(r=>({...r}));for(const r in n){const c=n[r],u=typeof c=="function"?c(o):c,s=(u==null?void 0:u[Symbol.iterator])&&typeof u!="string"?u:e.map(()=>u);let f=-1;for(const a of o)a[r]=s[++f]}return o}}function M(n){return n.length<1?[]:Object.keys(n[0])}function x(){return n=>M(n)}function nn(n,t){let e=[];for(const c of S(t))typeof c=="function"?e.push(...c(n)):e.push(c);e.length&&e[0][0]==="-"&&(e=[...x()(n),...e]);const o={},r=[];for(let c=e.length-1;c>=0;c--){const u=e[c];if(u[0]==="-"){o[u.substring(1)]=!0;continue}if(o[u]){o[u]=!1;continue}r.unshift(u)}return e=Array.from(new Set(r)),e}function E(n){return e=>{let o=nn(e,n);return o.length?e.map(r=>{const c={};for(const u of o)c[u]=r[u];return c}):e}}function An(n){return e=>{const o=w(n)(e);return E(Object.keys(n))(o)}}function en(n){return e=>typeof n=="function"?[...e,...S(n(e))]:[...e,...S(n)]}function zn(n){return e=>{const{namesFrom:o,valuesFrom:r,valuesFill:c,valuesFillMap:u,namesSep:s="_"}=n,f=Array.isArray(o)?o:[o],a=Array.isArray(r)?r:[r],d=[];if(!e.length)return d;const i=Object.keys(e[0]).filter(p=>!f.includes(p)&&!a.includes(p)),m={};for(const p of e)for(const v of f)m[v]==null&&(m[v]={}),m[v][p[v]]=!0;const y=[];for(const p in m)y.push(Object.keys(m[p]));const g={},b=$n(s,y);for(const p of b){if(a.length===1){g[p]=u!=null?u[a[0]]:c;continue}for(const v of a)g[`${v}${s}${p}`]=u!=null?u[v]:c}function K(p){if(!p.length)return[];const v={...g};for(const j of i)v[j]=p[0][j];for(const j of p){const q=f.map(F=>j[F]).join(s);if(a.length===1){v[q]=j[a[0]];continue}for(const F of a)v[`${F}${s}${q}`]=j[F]}return[v]}return i.length?z(e,_(i,[K])):K(e)}}function $n(n="_",t){function e(r,c,u){if(!u.length&&c!=null){r.push(c);return}const s=u[0],f=u.slice(1);for(const a of s)e(r,c==null?a:`${c}${n}${a}`,f)}const o=[];return e(o,null,t),o}function Ln(n){return e=>{var o;const{namesTo:r,valuesTo:c,namesSep:u="_"}=n,s=(o=n.cols)!=null?o:[],f=nn(e,s),a=Array.isArray(r)?r:[r],d=Array.isArray(c)?c:[c],i=a.length>1,m=d.length>1,y=[];for(const g of e){const b=Object.keys(g).filter(p=>!f.includes(p)),K={};for(const p of b)K[p]=g[p];const A=m?Array.from(new Set(f.map(p=>p.substring(p.indexOf(u)+1)))):f;for(const p of A){const v={...K};for(const j of d){const q=m?`${j}${u}${p}`:p,F=i?p.split(u):[p];let fe=0;for(const ae of a){const ie=F[fe++];v[ae]=ie,v[j]=g[q]}}y.push(v)}}return y}}function tn(n){return e=>{const o=qn(n),r=[];for(const c in o){const u=o[c];let s;typeof u=="function"?s=u(e):Array.isArray(u)?s=u:s=Array.from(new Set(e.map(f=>f[c]))),r.push(s.map(f=>({[c]:f})))}return Tn(r)}}function Tn(n){function t(o,r,c){if(!c.length&&r!=null){o.push(r);return}const u=c[0],s=c.slice(1);for(const f of u)t(o,{...r,...f},s)}const e=[];return t(e,null,n),e}function qn(n){if(Array.isArray(n)){const t={};for(const e of n)t[e]=e;return t}else if(typeof n=="object")return n;return{[n]:n}}function un(n,t=1){let[e,o]=h.extent(n);const r=[];let c=e;for(;c<=o;)r.push(c),c+=t;return r}function C(n,t="day",e=1){let[o,r]=h.extent(n);const c=[];let u=new Date(o);for(;u<=r;)if(c.push(new Date(u)),t==="day"||t==="d"||t==="days")u.setUTCDate(u.getUTCDate()+1*e);else if(t==="week"||t==="w"||t==="weeks")u.setUTCDate(u.getUTCDate()+7*e);else if(t==="month"||t==="m"||t==="months")u.setUTCMonth(u.getUTCMonth()+1*e);else if(t==="year"||t==="y"||t==="years")u.setUTCFullYear(u.getUTCFullYear()+1*e);else throw new Error("Invalid granularity for date sequence: "+t);return c}function Dn(n,t){return function(o){t=t!=null?t:1;const r=typeof n=="function"?n:c=>c[n];return un(o.map(r),t)}}function Rn(n,t,e){return function(r){t=t!=null?t:"day",e=e!=null?e:1;const c=typeof n=="function"?n:u=>u[n];return C(r.map(c),t,e)}}function Wn(n,t,e){return function(r){t=t!=null?t:"day",e=e!=null?e:1;const c=typeof n=="function"?n:u=>u[n];return C(r.map(u=>new Date(c(u))),t,e).map(u=>u.toISOString())}}function on(n){return e=>{const o=[];for(const r of e){const c={...r};for(const u in n)c[u]==null&&(c[u]=n[u]);o.push(c)}return o}}function En(n,t){return o=>{const r=tn(n)(o),c=X(o)(r);return t?on(t)(c):c}}function Cn(n){return e=>{const o=S(n),r={};return e.map(c=>{const u={...c};for(const s of o)u[s]!=null?r[s]=u[s]:r[s]!=null&&(u[s]=r[s]);return u})}}function Vn(n,t){return(o,r)=>{var c;let u="[tidy.debug";if((c=r==null?void 0:r.groupKeys)==null?void 0:c.length){const y=r.groupKeys.map(g=>g.join(": ")).join(", ");y.length&&(u+="|"+y)}t=t!=null?t:{};const{limit:s=10,output:f="table"}=t,a="--------------------------------------------------------------------------------";let d=a.length;const i=u+"]"+(n==null?"":" "+n);return d=Math.max(0,d-(i.length+2)),console.log(`${i} ${a.substring(0,d)}`),console[f](s==null||s>=o.length?o:o.slice(0,s)),o}}function T(n,t,e){return n==null||t==null?void 0:t===0&&n===0?0:!e&&t===0?void 0:n/t}var Un=Object.freeze({__proto__:null,rate:T});function Bn(n,t,e){const o=typeof n=="function"?n:s=>s[n],r=typeof t=="function"?t:s=>s[t],{predicate:c,allowDivideByZero:u}=e!=null?e:{};return c==null?s=>{const f=r(s),a=o(s);return T(a,f,u)}:s=>{if(!c(s))return;const f=r(s),a=o(s);return T(a,f,u)}}function Nn(n,t){let e=new h.Adder,o=0;return Float64Array.from(n,r=>e.add(+(t(r,o++,n)||0)))}function Jn(n,t){let e=0;for(let o=0;o<n.length;++o){const r=t(n[o],o,n);+r===r&&(e+=1)}return e?h.fsum(n,t)/e:void 0}function Hn(n){const t=typeof n=="function"?n:e=>e[n];return e=>Nn(e,t)}function Pn(n,t,e){const{partial:o=!1}=e!=null?e:{};return r=>r.map((c,u)=>{const s=u;if(!o&&s-n+1<0)return;const f=Math.max(0,s-n+1),a=r.slice(f,s+1);return t(a,s)})}function Gn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.min(e,t)}function Yn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.max(e,t)}function Zn(n){const t=typeof n=="function"?n:e=>e[n];return e=>Jn(e,t)}function Qn(n,t){const e=typeof n=="function"?n:r=>r[n],o=typeof t=="function"?t:r=>r[t];return r=>{const c=h.fsum(r,e),u=h.fsum(r,o);return T(c,u)}}function Xn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.median(e,t)}function xn(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.deviation(e,t)}function ne(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.variance(e,t)}function ee(n){const t=typeof n=="function"?n:e=>e[n];return e=>e.length?t(e[0]):void 0}function te(n){const t=typeof n=="function"?n:e=>e[n];return e=>e.length?t(e[e.length-1]):void 0}function ue(n,t=!0){return e=>{const o=new RegExp(`^${n}`,t?"i":void 0);return M(e).filter(c=>o.test(c))}}function oe(n,t=!0){return e=>{const o=new RegExp(`${n}$`,t?"i":void 0);return M(e).filter(c=>o.test(c))}}function re(n,t=!0){return e=>{const o=new RegExp(n,t?"i":void 0);return M(e).filter(c=>o.test(c))}}function ce(n){return t=>M(t).filter(o=>n.test(o))}function se(n,t,e){return o=>{const r=M(o),c=[];for(let u=t[0];u<=t[1];++u){const s=e==null?u:new String("00000000"+u).slice(-e);c.push(`${n}${s}`)}return r.filter(u=>c.includes(u))}}function le(n){return t=>{let e=new Set;for(const r of S(n))if(typeof r=="function"){const c=r(t);for(const u of c)e.add(u)}else e.add(r);return Array.from(e).map(r=>`-${r}`)}}l.TMath=Un,l.addItems=en,l.addRows=en,l.arrange=I,l.asc=V,l.complete=En,l.contains=re,l.count=Sn,l.cumsum=Hn,l.debug=Vn,l.desc=U,l.deviation=xn,l.distinct=ln,l.endsWith=oe,l.everything=x,l.expand=tn,l.fill=Cn,l.filter=rn,l.first=ee,l.fixedOrder=fn,l.fullSeq=Dn,l.fullSeqDate=Rn,l.fullSeqDateISOString=Wn,l.groupBy=_,l.innerJoin=In,l.last=te,l.leftJoin=X,l.map=sn,l.matches=ce,l.max=Yn,l.mean=Zn,l.meanRate=Qn,l.median=Xn,l.min=Gn,l.mutate=w,l.mutateWithSummary=On,l.n=H,l.negate=le,l.numRange=se,l.pick=E,l.pivotLonger=Ln,l.pivotWider=zn,l.rate=Bn,l.rename=jn,l.replaceNully=on,l.roll=Pn,l.select=E,l.slice=W,l.sliceHead=kn,l.sliceMax=Kn,l.sliceMin=Mn,l.sliceSample=Fn,l.sliceTail=wn,l.sort=I,l.startsWith=ue,l.sum=P,l.summarize=D,l.summarizeAll=B,l.summarizeAt=J,l.summarizeIf=N,l.tally=G,l.tidy=z,l.total=an,l.totalAll=mn,l.totalAt=yn,l.totalIf=dn,l.transmute=An,l.variance=ne,l.vectorSeq=un,l.vectorSeqDate=C,l.when=cn,Object.defineProperty(l,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=tidy.min.js.map |
{ | ||
"name": "@tidyjs/tidy", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Tidy up your data with JavaScript, inspired by dplyr and the tidyverse", | ||
@@ -47,3 +47,3 @@ "main": "dist/lib/index.js", | ||
}, | ||
"gitHead": "c67eb2b718760f57554686c350c150d42dd1191a" | ||
"gitHead": "d0ca292ba31fa6c16fded2718ea25e92afc987e1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
705407
5392