@tidyjs/tidy 2.5.2 → 2.6.1

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.
Files changed (245) hide show
  1. package/dist/es/addRows.js.map +1 -1
  2. package/dist/es/arrange.js +9 -5
  3. package/dist/es/arrange.js.map +1 -1
  4. package/dist/es/complete.js.map +1 -1
  5. package/dist/es/count.js +6 -2
  6. package/dist/es/count.js.map +1 -1
  7. package/dist/es/debug.js +4 -2
  8. package/dist/es/debug.js.map +1 -1
  9. package/dist/es/distinct.js +3 -3
  10. package/dist/es/distinct.js.map +1 -1
  11. package/dist/es/expand.js +18 -13
  12. package/dist/es/expand.js.map +1 -1
  13. package/dist/es/fill.js +10 -3
  14. package/dist/es/fill.js.map +1 -1
  15. package/dist/es/filter.js.map +1 -1
  16. package/dist/es/fullJoin.js +23 -20
  17. package/dist/es/fullJoin.js.map +1 -1
  18. package/dist/es/groupBy.js +56 -28
  19. package/dist/es/groupBy.js.map +1 -1
  20. package/dist/es/helpers/assignGroupKeys.js +4 -4
  21. package/dist/es/helpers/assignGroupKeys.js.map +1 -1
  22. package/dist/es/helpers/groupMap.js +2 -2
  23. package/dist/es/helpers/groupMap.js.map +1 -1
  24. package/dist/es/helpers/groupTraversal.js +5 -4
  25. package/dist/es/helpers/groupTraversal.js.map +1 -1
  26. package/dist/es/helpers/identity.js.map +1 -1
  27. package/dist/es/helpers/isObject.js.map +1 -1
  28. package/dist/es/helpers/keysFromItems.js +1 -2
  29. package/dist/es/helpers/keysFromItems.js.map +1 -1
  30. package/dist/es/helpers/singleOrArray.js.map +1 -1
  31. package/dist/es/helpers/summation.js +11 -3
  32. package/dist/es/helpers/summation.js.map +1 -1
  33. package/dist/es/innerJoin.js +37 -12
  34. package/dist/es/innerJoin.js.map +1 -1
  35. package/dist/es/item/rate.js +2 -3
  36. package/dist/es/item/rate.js.map +1 -1
  37. package/dist/es/leftJoin.js +13 -8
  38. package/dist/es/leftJoin.js.map +1 -1
  39. package/dist/es/map.js.map +1 -1
  40. package/dist/es/math/math.js.map +1 -1
  41. package/dist/es/mutate.js +1 -1
  42. package/dist/es/mutate.js.map +1 -1
  43. package/dist/es/mutateWithSummary.js +1 -1
  44. package/dist/es/mutateWithSummary.js.map +1 -1
  45. package/dist/es/pivotLonger.js +31 -7
  46. package/dist/es/pivotLonger.js.map +1 -1
  47. package/dist/es/pivotWider.js +24 -19
  48. package/dist/es/pivotWider.js.map +1 -1
  49. package/dist/es/rename.js.map +1 -1
  50. package/dist/es/replaceNully.js +1 -1
  51. package/dist/es/replaceNully.js.map +1 -1
  52. package/dist/es/select.js +3 -3
  53. package/dist/es/select.js.map +1 -1
  54. package/dist/es/selectors/contains.js.map +1 -1
  55. package/dist/es/selectors/endsWith.js.map +1 -1
  56. package/dist/es/selectors/everything.js.map +1 -1
  57. package/dist/es/selectors/matches.js.map +1 -1
  58. package/dist/es/selectors/negate.js +2 -2
  59. package/dist/es/selectors/negate.js.map +1 -1
  60. package/dist/es/selectors/numRange.js.map +1 -1
  61. package/dist/es/selectors/startsWith.js.map +1 -1
  62. package/dist/es/sequences/fullSeq.js +5 -1
  63. package/dist/es/sequences/fullSeq.js.map +1 -1
  64. package/dist/es/slice.js +2 -3
  65. package/dist/es/slice.js.map +1 -1
  66. package/dist/es/summarize.js +6 -4
  67. package/dist/es/summarize.js.map +1 -1
  68. package/dist/es/summary/deviation.js.map +1 -1
  69. package/dist/es/summary/first.js.map +1 -1
  70. package/dist/es/summary/last.js.map +1 -1
  71. package/dist/es/summary/max.js.map +1 -1
  72. package/dist/es/summary/mean.js.map +1 -1
  73. package/dist/es/summary/meanRate.js.map +1 -1
  74. package/dist/es/summary/median.js.map +1 -1
  75. package/dist/es/summary/min.js.map +1 -1
  76. package/dist/es/summary/n.js.map +1 -1
  77. package/dist/es/summary/nDistinct.js +2 -2
  78. package/dist/es/summary/nDistinct.js.map +1 -1
  79. package/dist/es/summary/sum.js.map +1 -1
  80. package/dist/es/summary/variance.js.map +1 -1
  81. package/dist/es/tally.js +4 -2
  82. package/dist/es/tally.js.map +1 -1
  83. package/dist/es/tidy.js.map +1 -1
  84. package/dist/es/total.js.map +1 -1
  85. package/dist/es/transmute.js.map +1 -1
  86. package/dist/es/vector/cumsum.js.map +1 -1
  87. package/dist/es/vector/lag.js +1 -1
  88. package/dist/es/vector/lag.js.map +1 -1
  89. package/dist/es/vector/lead.js +1 -1
  90. package/dist/es/vector/lead.js.map +1 -1
  91. package/dist/es/vector/roll.js +1 -1
  92. package/dist/es/vector/roll.js.map +1 -1
  93. package/dist/es/vector/rowNumber.js.map +1 -1
  94. package/dist/es/when.js +1 -2
  95. package/dist/es/when.js.map +1 -1
  96. package/dist/lib/addRows.js +0 -2
  97. package/dist/lib/addRows.js.map +1 -1
  98. package/dist/lib/arrange.js +9 -7
  99. package/dist/lib/arrange.js.map +1 -1
  100. package/dist/lib/complete.js +0 -2
  101. package/dist/lib/complete.js.map +1 -1
  102. package/dist/lib/count.js +6 -4
  103. package/dist/lib/count.js.map +1 -1
  104. package/dist/lib/debug.js +4 -4
  105. package/dist/lib/debug.js.map +1 -1
  106. package/dist/lib/distinct.js +3 -5
  107. package/dist/lib/distinct.js.map +1 -1
  108. package/dist/lib/expand.js +18 -15
  109. package/dist/lib/expand.js.map +1 -1
  110. package/dist/lib/fill.js +10 -5
  111. package/dist/lib/fill.js.map +1 -1
  112. package/dist/lib/filter.js +0 -2
  113. package/dist/lib/filter.js.map +1 -1
  114. package/dist/lib/fullJoin.js +22 -21
  115. package/dist/lib/fullJoin.js.map +1 -1
  116. package/dist/lib/groupBy.js +56 -30
  117. package/dist/lib/groupBy.js.map +1 -1
  118. package/dist/lib/helpers/assignGroupKeys.js +4 -6
  119. package/dist/lib/helpers/assignGroupKeys.js.map +1 -1
  120. package/dist/lib/helpers/groupMap.js +2 -4
  121. package/dist/lib/helpers/groupMap.js.map +1 -1
  122. package/dist/lib/helpers/groupTraversal.js +5 -6
  123. package/dist/lib/helpers/groupTraversal.js.map +1 -1
  124. package/dist/lib/helpers/identity.js +0 -2
  125. package/dist/lib/helpers/identity.js.map +1 -1
  126. package/dist/lib/helpers/isObject.js +0 -2
  127. package/dist/lib/helpers/isObject.js.map +1 -1
  128. package/dist/lib/helpers/keysFromItems.js +1 -4
  129. package/dist/lib/helpers/keysFromItems.js.map +1 -1
  130. package/dist/lib/helpers/singleOrArray.js +0 -2
  131. package/dist/lib/helpers/singleOrArray.js.map +1 -1
  132. package/dist/lib/helpers/summation.js +10 -4
  133. package/dist/lib/helpers/summation.js.map +1 -1
  134. package/dist/lib/index.js +0 -2
  135. package/dist/lib/index.js.map +1 -1
  136. package/dist/lib/innerJoin.js +38 -14
  137. package/dist/lib/innerJoin.js.map +1 -1
  138. package/dist/lib/item/rate.js +2 -5
  139. package/dist/lib/item/rate.js.map +1 -1
  140. package/dist/lib/leftJoin.js +12 -9
  141. package/dist/lib/leftJoin.js.map +1 -1
  142. package/dist/lib/map.js +0 -2
  143. package/dist/lib/map.js.map +1 -1
  144. package/dist/lib/math/math.js +0 -2
  145. package/dist/lib/math/math.js.map +1 -1
  146. package/dist/lib/mutate.js +1 -3
  147. package/dist/lib/mutate.js.map +1 -1
  148. package/dist/lib/mutateWithSummary.js +1 -3
  149. package/dist/lib/mutateWithSummary.js.map +1 -1
  150. package/dist/lib/pivotLonger.js +31 -9
  151. package/dist/lib/pivotLonger.js.map +1 -1
  152. package/dist/lib/pivotWider.js +24 -21
  153. package/dist/lib/pivotWider.js.map +1 -1
  154. package/dist/lib/rename.js +0 -2
  155. package/dist/lib/rename.js.map +1 -1
  156. package/dist/lib/replaceNully.js +1 -3
  157. package/dist/lib/replaceNully.js.map +1 -1
  158. package/dist/lib/select.js +3 -5
  159. package/dist/lib/select.js.map +1 -1
  160. package/dist/lib/selectors/contains.js +0 -2
  161. package/dist/lib/selectors/contains.js.map +1 -1
  162. package/dist/lib/selectors/endsWith.js +0 -2
  163. package/dist/lib/selectors/endsWith.js.map +1 -1
  164. package/dist/lib/selectors/everything.js +0 -2
  165. package/dist/lib/selectors/everything.js.map +1 -1
  166. package/dist/lib/selectors/matches.js +0 -2
  167. package/dist/lib/selectors/matches.js.map +1 -1
  168. package/dist/lib/selectors/negate.js +2 -4
  169. package/dist/lib/selectors/negate.js.map +1 -1
  170. package/dist/lib/selectors/numRange.js +0 -2
  171. package/dist/lib/selectors/numRange.js.map +1 -1
  172. package/dist/lib/selectors/startsWith.js +0 -2
  173. package/dist/lib/selectors/startsWith.js.map +1 -1
  174. package/dist/lib/sequences/fullSeq.js +5 -3
  175. package/dist/lib/sequences/fullSeq.js.map +1 -1
  176. package/dist/lib/slice.js +2 -5
  177. package/dist/lib/slice.js.map +1 -1
  178. package/dist/lib/summarize.js +6 -6
  179. package/dist/lib/summarize.js.map +1 -1
  180. package/dist/lib/summary/deviation.js +0 -2
  181. package/dist/lib/summary/deviation.js.map +1 -1
  182. package/dist/lib/summary/first.js +0 -2
  183. package/dist/lib/summary/first.js.map +1 -1
  184. package/dist/lib/summary/last.js +0 -2
  185. package/dist/lib/summary/last.js.map +1 -1
  186. package/dist/lib/summary/max.js +0 -2
  187. package/dist/lib/summary/max.js.map +1 -1
  188. package/dist/lib/summary/mean.js +0 -2
  189. package/dist/lib/summary/mean.js.map +1 -1
  190. package/dist/lib/summary/meanRate.js +0 -2
  191. package/dist/lib/summary/meanRate.js.map +1 -1
  192. package/dist/lib/summary/median.js +0 -2
  193. package/dist/lib/summary/median.js.map +1 -1
  194. package/dist/lib/summary/min.js +0 -2
  195. package/dist/lib/summary/min.js.map +1 -1
  196. package/dist/lib/summary/n.js +0 -2
  197. package/dist/lib/summary/n.js.map +1 -1
  198. package/dist/lib/summary/nDistinct.js +2 -4
  199. package/dist/lib/summary/nDistinct.js.map +1 -1
  200. package/dist/lib/summary/sum.js +0 -2
  201. package/dist/lib/summary/sum.js.map +1 -1
  202. package/dist/lib/summary/variance.js +0 -2
  203. package/dist/lib/summary/variance.js.map +1 -1
  204. package/dist/lib/tally.js +4 -4
  205. package/dist/lib/tally.js.map +1 -1
  206. package/dist/lib/tidy.js +0 -2
  207. package/dist/lib/tidy.js.map +1 -1
  208. package/dist/lib/total.js +0 -2
  209. package/dist/lib/total.js.map +1 -1
  210. package/dist/lib/transmute.js +0 -2
  211. package/dist/lib/transmute.js.map +1 -1
  212. package/dist/lib/vector/cumsum.js +0 -2
  213. package/dist/lib/vector/cumsum.js.map +1 -1
  214. package/dist/lib/vector/lag.js +1 -3
  215. package/dist/lib/vector/lag.js.map +1 -1
  216. package/dist/lib/vector/lead.js +1 -3
  217. package/dist/lib/vector/lead.js.map +1 -1
  218. package/dist/lib/vector/roll.js +1 -3
  219. package/dist/lib/vector/roll.js.map +1 -1
  220. package/dist/lib/vector/rowNumber.js +0 -2
  221. package/dist/lib/vector/rowNumber.js.map +1 -1
  222. package/dist/lib/when.js +1 -4
  223. package/dist/lib/when.js.map +1 -1
  224. package/dist/tidy.d.ts +217 -1775
  225. package/dist/umd/tidy.js +307 -184
  226. package/dist/umd/tidy.js.map +1 -1
  227. package/dist/umd/tidy.min.js +1 -1
  228. package/dist/umd/tidy.min.js.map +1 -1
  229. package/genai-docs/api-core.md +357 -0
  230. package/genai-docs/api-grouping.md +400 -0
  231. package/genai-docs/api-joins.md +118 -0
  232. package/genai-docs/api-other.md +238 -0
  233. package/genai-docs/api-pivot.md +112 -0
  234. package/genai-docs/api-selectors.md +159 -0
  235. package/genai-docs/api-sequences.md +127 -0
  236. package/genai-docs/api-slice.md +137 -0
  237. package/genai-docs/api-summarize.md +528 -0
  238. package/genai-docs/api-vector.md +239 -0
  239. package/genai-docs/gotchas.md +193 -0
  240. package/genai-docs/index.md +44 -0
  241. package/genai-docs/mental-model.md +270 -0
  242. package/genai-docs/patterns.md +384 -0
  243. package/genai-docs/quick-reference.md +125 -0
  244. package/package.json +16 -10
  245. package/LICENSE +0 -21
@@ -1,2 +1,2 @@
1
- (function(f,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("d3-array")):typeof define=="function"&&define.amd?define(["exports","d3-array"],h):(f=typeof globalThis!="undefined"?globalThis:f||self,h(f.Tidy={},f.d3))})(this,function(f,h){"use strict";function I(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 u of t)u&&(e=u(e));return e}function ln(n){return e=>e.filter(n)}function sn(n,t){return u=>{if(typeof n=="function"){if(!n(u))return u}else if(!n)return u;return I(u,...t)}}function fn(n){return e=>e.map(n)}function j(n){return n==null?[]:Array.isArray(n)?n:[n]}function an(n){return e=>{if(n=j(n),!n.length){const o=new Set;for(const l of e)o.add(l);return Array.from(o)}const u=new Map,r=[],c=n[n.length-1];for(const o of e){let l=u,s=!1;for(const i of n){const a=typeof i=="function"?i(o):o[i];if(i===c){s=l.has(a),s||(r.push(o),l.set(a,!0));break}l.has(a)||l.set(a,new Map),l=l.get(a)}}return r}}function k(n){return e=>{const u=j(n).map(r=>typeof r=="function"?r.length===1?C(r):r:C(r));return e.slice().sort((r,c)=>{for(const o of u){const l=o(r,c);if(l)return l}return 0})}}function C(n){const t=typeof n=="function"?n:e=>e[n];return function(u,r){return P(t(u),t(r),!1)}}function L(n){const t=typeof n=="function"?n:e=>e[n];return function(u,r){return P(t(u),t(r),!0)}}function mn(n,t,e){let{position:u="start"}=e!=null?e:{};const r=u==="end"?-1:1,c=new Map;for(let l=0;l<t.length;++l)c.set(t[l],l);const o=typeof n=="function"?n:l=>l[n];return function(s,i){var a,m;const d=(a=c.get(o(s)))!=null?a:-1,y=(m=c.get(o(i)))!=null?m:-1;return d>=0&&y>=0?d-y:d>=0?r*-1:y>=0?r*1:0}}function P(n,t,e){let u=e?t:n,r=e?n:t;if(z(u)&&z(r)){const l=(u!==u?0:u===null?1:2)-(r!==r?0:r===null?1:2);return e?-l:l}return z(u)?e?-1:1:z(r)?e?1:-1:h.ascending(u,r)}function z(n){return n==null||n!==n}function W(n,t){return u=>{t=t!=null?t:{};const r={},c=Object.keys(n);for(const o of c)r[o]=n[o](u);if(t.rest&&u.length){const o=Object.keys(u[0]);for(const l of o)c.includes(l)||(r[l]=t.rest(l)(u))}return[r]}}function R(n,t,e,u){if(!n.length)return[];const r={};let c;if(u==null)c=Object.keys(n[0]);else{c=[];for(const o of j(u))typeof o=="function"?c.push(...o(n)):c.push(o)}for(const o of c){if(e){const l=n.map(s=>s[o]);if(!e(l))continue}r[o]=t(o)(n)}return[r]}function Y(n){return e=>R(e,n)}function J(n,t){return u=>R(u,t,n)}function Z(n,t){return u=>R(u,t,void 0,n)}function M(n){return e=>{const u=e.map(c=>({...c}));let r=0;for(const c of u){for(const o in n){const l=n[o],s=typeof l=="function"?l(c,r,u):l;c[o]=s}++r}return u}}function dn(n,t){return u=>{const r=W(n)(u),c=M(t)(r);return[...u,...c]}}function yn(n,t){return u=>{const r=Y(n)(u),c=M(t)(r);return[...u,...c]}}function pn(n,t,e){return r=>{const c=J(n,t)(r),o=M(e)(c);return[...r,...o]}}function hn(n,t,e){return r=>{const c=Z(n,t)(r),o=M(e)(c);return[...r,...o]}}function $(n,t){if(n==null||typeof n!="object"||Array.isArray(n))return n;const e=Object.fromEntries(t.filter(u=>typeof u[0]!="function"&&u[0]!=null));return Object.assign(e,n)}function E(n,t,e,u,r,c=0){for(const[o,l]of n.entries()){const s=[...e,o];if(l instanceof Map){const i=u(t,s,c);E(l,i,s,u,r,c+1)}else r(t,s,l,c)}return t}function gn(n,t,e=u=>u[u.length-1]){function u(o,l){const s=new Map;return o.set(e(l),s),s}function r(o,l,s){o.set(e(l),t(s,l))}const c=new Map;return E(n,c,[],u,r),c}const K=n=>n;function _n(n){const t=typeof n;return n!=null&&(t==="object"||t==="function")}function v(n,t,e){return typeof t=="function"?t=[t]:arguments.length===2&&t!=null&&!Array.isArray(t)&&(e=t),r=>{const c=bn(r,n),o=vn(c,t,e==null?void 0:e.addGroupKeys);if(e==null?void 0:e.export)switch(e.export){case"grouped":return o;case"levels":return T(o,e);case"entries-obj":case"entriesObject":return T(o,{...e,export:"levels",levels:["entries-object"]});default:return T(o,{...e,export:"levels",levels:[e.export]})}return jn(o,e==null?void 0:e.addGroupKeys)}}v.grouped=n=>({...n,export:"grouped"}),v.entries=n=>({...n,export:"entries"}),v.entriesObject=n=>({...n,export:"entries-object"}),v.object=n=>({...n,export:"object"}),v.map=n=>({...n,export:"map"}),v.keys=n=>({...n,export:"keys"}),v.values=n=>({...n,export:"values"}),v.levels=n=>({...n,export:"levels"});function vn(n,t,e){let u=n;if(!(t==null?void 0:t.length))return u;for(const r of t)!r||(u=gn(u,(c,o)=>{let s=r(c,{groupKeys:o});return e!==!1&&(s=s.map(i=>$(i,o))),s}));return u}function bn(n,t){const e=j(t).map((r,c)=>{const o=typeof r=="function"?r:s=>s[r],l=new Map;return s=>{const i=o(s),a=_n(i)?i.valueOf():i;if(l.has(a))return l.get(a);const m=[r,i];return l.set(a,m),m}});return h.group(n,...e)}function jn(n,t){const e=[];return E(n,e,[],K,(u,r,c)=>{let o=c;t!==!1&&(o=c.map(l=>$(l,r))),u.push(...o)}),e}const Sn=n=>n.join("/");function kn(n){var t;const{flat:e,single:u,mapLeaf:r=K,mapLeaves:c=K,addGroupKeys:o}=n;let l;return n.flat&&(l=(t=n.compositeKey)!=null?t:Sn),{groupFn:(a,m)=>u?r(o===!1?a[0]:$(a[0],m)):c(a.map(d=>r(o===!1?d:$(d,m)))),keyFn:e?a=>l(a.map(m=>m[1])):a=>a[a.length-1][1]}}function T(n,t){const{groupFn:e,keyFn:u}=kn(t);let{mapEntry:r=K}=t;const{levels:c=["entries"]}=t,o=[];for(const a of c)switch(a){case"entries":case"entries-object":case"entries-obj":case"entriesObject":{const m=(a==="entries-object"||a==="entries-obj"||a==="entriesObject")&&t.mapEntry==null?([d,y])=>({key:d,values:y}):r;o.push({id:"entries",createEmptySubgroup:()=>[],addSubgroup:(d,y,g,b)=>{d.push(m([g,y],b))},addLeaf:(d,y,g,b)=>{d.push(m([y,g],b))}});break}case"map":o.push({id:"map",createEmptySubgroup:()=>new Map,addSubgroup:(m,d,y)=>{m.set(y,d)},addLeaf:(m,d,y)=>{m.set(d,y)}});break;case"object":o.push({id:"object",createEmptySubgroup:()=>({}),addSubgroup:(m,d,y)=>{m[y]=d},addLeaf:(m,d,y)=>{m[d]=y}});break;case"keys":o.push({id:"keys",createEmptySubgroup:()=>[],addSubgroup:(m,d,y)=>{m.push([y,d])},addLeaf:(m,d)=>{m.push(d)}});break;case"values":o.push({id:"values",createEmptySubgroup:()=>[],addSubgroup:(m,d)=>{m.push(d)},addLeaf:(m,d,y)=>{m.push(y)}});break;default:typeof a=="object"&&o.push(a)}const l=(a,m,d)=>{var y,g;if(t.flat)return a;const b=(y=o[d])!=null?y:o[o.length-1],A=((g=o[d+1])!=null?g:b).createEmptySubgroup();return b.addSubgroup(a,A,u(m),d),A},s=(a,m,d,y)=>{var g;((g=o[y])!=null?g:o[o.length-1]).addLeaf(a,u(m),e(d,m),y)},i=o[0].createEmptySubgroup();return E(n,i,[],l,s)}function Q(n){if(n==null?void 0:n.predicate){const t=n.predicate;return e=>e.reduce((u,r,c)=>t(r,c,e)?u+1:u,0)}return t=>t.length}function X(n,t){let e=typeof n=="function"?n:u=>u[n];if(t==null?void 0:t.predicate){const u=e,r=t.predicate;e=(c,o,l)=>r(c,o,l)?u(c,o,l):0}return u=>h.fsum(u,e)}function x(n){return e=>{const{name:u="n",wt:r}=n!=null?n:{};return W({[u]:r==null?Q():X(r)})(e)}}function Mn(n,t){return u=>{t=t!=null?t:{};const{name:r="n",sort:c}=t;return I(u,v(n,[x(t)]),c?k(L(r)):K)}}function wn(n){return e=>e.map(u=>{var r;const c={},o=Object.keys(u);for(const l of o){const s=(r=n[l])!=null?r:l;c[s]=u[l]}return c})}function V(n,t){return u=>u.slice(n,t)}const Fn=n=>V(0,n),On=n=>V(-n);function Kn(n,t){return u=>k(t)(u).slice(0,n)}function An(n,t){return u=>typeof t=="function"?k(t)(u).slice(-n).reverse():k(L(t))(u).slice(0,n)}function In(n,t){t=t!=null?t:{};const{replace:e}=t;return r=>{if(!r.length)return r.slice();if(e){const c=[];for(let o=0;o<n;++o)c.push(r[Math.floor(Math.random()*r.length)]);return c}return h.shuffle(r.slice()).slice(0,n)}}function U(n,t){if(n.length===0||t.length===0)return{};const e=Object.keys(n[0]),u=Object.keys(t[0]),r={};for(const c of e)u.includes(c)&&(r[c]=c);return r}function N(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 B(n,t,e){for(const u in e){const r=e[u];if(n[r]!==t[u])return!1}return!0}function zn(n,t){return u=>{const r=(t==null?void 0:t.by)==null?U(u,n):N(t.by);return u.flatMap(o=>n.filter(s=>B(o,s,r)).map(s=>({...o,...s})))}}function nn(n,t){return u=>{if(!n.length)return u;const r=(t==null?void 0:t.by)==null?U(u,n):N(t.by),c=Object.keys(n[0]);return u.flatMap(l=>{const s=n.filter(a=>B(l,a,r));if(s.length)return s.map(a=>({...l,...a}));const i=Object.fromEntries(c.filter(a=>l[a]==null).map(a=>[a,void 0]));return{...l,...i}})}}function $n(n,t){return u=>{if(!n.length)return u;if(!u.length)return n;const r=(t==null?void 0:t.by)==null?U(u,n):N(t.by),c=new Map,o=Object.keys(n[0]),l=u.flatMap(s=>{const i=n.filter(m=>{const d=B(s,m,r);return d&&c.set(m,!0),d});if(i.length)return i.map(m=>({...s,...m}));const a=Object.fromEntries(o.filter(m=>s[m]==null).map(m=>[m,void 0]));return{...s,...a}});if(c.size<n.length){const s=Object.fromEntries(Object.keys(u[0]).map(i=>[i,void 0]));for(const i of n)c.has(i)||l.push({...s,...i})}return l}}function En(n){return e=>{const u=e.map(r=>({...r}));for(const r in n){const c=n[r],o=typeof c=="function"?c(u):c,l=(o==null?void 0:o[Symbol.iterator])&&typeof o!="string"?o:e.map(()=>o);let s=-1;for(const i of u)i[r]=l[++s]}return u}}function w(n){return n.length<1?[]:Object.keys(n[0])}function tn(){return n=>w(n)}function en(n,t){let e=[];for(const c of j(t))typeof c=="function"?e.push(...c(n)):e.push(c);e.length&&e[0][0]==="-"&&(e=[...tn()(n),...e]);const u={},r=[];for(let c=e.length-1;c>=0;c--){const o=e[c];if(o[0]==="-"){u[o.substring(1)]=!0;continue}if(u[o]){u[o]=!1;continue}r.unshift(o)}return e=Array.from(new Set(r)),e}function G(n){return e=>{let u=en(e,n);return u.length?e.map(r=>{const c={};for(const o of u)c[o]=r[o];return c}):e}}function Dn(n){return e=>{const u=M(n)(e);return G(Object.keys(n))(u)}}function un(n){return e=>typeof n=="function"?[...e,...j(n(e))]:[...e,...j(n)]}function qn(n){return e=>{const{namesFrom:u,valuesFrom:r,valuesFill:c,valuesFillMap:o,namesSep:l="_"}=n,s=Array.isArray(u)?u:[u],i=Array.isArray(r)?r:[r],a=[];if(!e.length)return a;const m=Object.keys(e[0]).filter(p=>!s.includes(p)&&!i.includes(p)),d={};for(const p of e)for(const _ of s)d[_]==null&&(d[_]={}),d[_][p[_]]=!0;const y=[];for(const p in d)y.push(Object.keys(d[p]));const g={},b=Cn(l,y);for(const p of b){if(i.length===1){g[p]=o!=null?o[i[0]]:c;continue}for(const _ of i)g[`${_}${l}${p}`]=o!=null?o[_]:c}function F(p){if(!p.length)return[];const _={...g};for(const S of m)_[S]=p[0][S];for(const S of p){const q=s.map(O=>S[O]).join(l);if(i.length===1){_[q]=S[i[0]];continue}for(const O of i)_[`${O}${l}${q}`]=S[O]}return[_]}return m.length?I(e,v(m,[F])):F(e)}}function Cn(n="_",t){function e(r,c,o){if(!o.length&&c!=null){r.push(c);return}const l=o[0],s=o.slice(1);for(const i of l)e(r,c==null?i:`${c}${n}${i}`,s)}const u=[];return e(u,null,t),u}function Ln(n){return e=>{var u;const{namesTo:r,valuesTo:c,namesSep:o="_"}=n,l=(u=n.cols)!=null?u:[],s=en(e,l),i=Array.isArray(r)?r:[r],a=Array.isArray(c)?c:[c],m=i.length>1,d=a.length>1,y=[];for(const g of e){const b=Object.keys(g).filter(p=>!s.includes(p)),F={};for(const p of b)F[p]=g[p];const A=d?Array.from(new Set(s.map(p=>p.substring(p.indexOf(o)+1)))):s;for(const p of A){const _={...F};for(const S of a){const q=d?`${S}${o}${p}`:p,O=m?p.split(o):[p];let vt=0;for(const bt of i){const jt=O[vt++];_[bt]=jt,_[S]=g[q]}}y.push(_)}}return y}}function rn(n){return e=>{const u=Rn(n),r=[];for(const c in u){const o=u[c];let l;typeof o=="function"?l=o(e):Array.isArray(o)?l=o:l=Array.from(new Set(e.map(s=>s[c]))),r.push(l.map(s=>({[c]:s})))}return Wn(r)}}function Wn(n){function t(u,r,c){if(!c.length&&r!=null){u.push(r);return}const o=c[0],l=c.slice(1);for(const s of o)t(u,{...r,...s},l)}const e=[];return t(e,null,n),e}function Rn(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 on(n,t=1){let[e,u]=h.extent(n);const r=[];let c=e;for(;c<=u;)r.push(c),c+=t;return r}function H(n,t="day",e=1){let[u,r]=h.extent(n);const c=[];let o=new Date(u);for(;o<=r;)if(c.push(new Date(o)),t==="second"||t==="s"||t==="seconds")o.setUTCSeconds(o.getUTCSeconds()+1*e);else if(t==="minute"||t==="min"||t==="minutes")o.setUTCMinutes(o.getUTCMinutes()+1*e);else if(t==="day"||t==="d"||t==="days")o.setUTCDate(o.getUTCDate()+1*e);else if(t==="week"||t==="w"||t==="weeks")o.setUTCDate(o.getUTCDate()+7*e);else if(t==="month"||t==="m"||t==="months")o.setUTCMonth(o.getUTCMonth()+1*e);else if(t==="year"||t==="y"||t==="years")o.setUTCFullYear(o.getUTCFullYear()+1*e);else throw new Error("Invalid granularity for date sequence: "+t);return c}function Tn(n,t){return function(u){t=t!=null?t:1;const r=typeof n=="function"?n:c=>c[n];return on(u.map(r),t)}}function Vn(n,t,e){return function(r){t=t!=null?t:"day",e=e!=null?e:1;const c=typeof n=="function"?n:o=>o[n];return H(r.map(c),t,e)}}function Un(n,t,e){return function(r){t=t!=null?t:"day",e=e!=null?e:1;const c=typeof n=="function"?n:o=>o[n];return H(r.map(o=>new Date(c(o))),t,e).map(o=>o.toISOString())}}function cn(n){return e=>{const u=[];for(const r of e){const c={...r};for(const o in n)c[o]==null&&(c[o]=n[o]);u.push(c)}return u}}function Nn(n,t){return u=>{const r=rn(n)(u),c=nn(u)(r);return t?cn(t)(c):c}}function Bn(n){return e=>{const u=j(n),r={};return e.map(c=>{const o={...c};for(const l of u)o[l]!=null?r[l]=o[l]:r[l]!=null&&(o[l]=r[l]);return o})}}function Gn(n,t){return(u,r)=>{var c;let o="[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&&(o+="|"+y)}t=t!=null?t:{};const{limit:l=10,output:s="table"}=t,i="--------------------------------------------------------------------------------";let a=i.length;const m=o+"]"+(n==null?"":" "+n);return a=Math.max(0,a-(m.length+2)),console.log(`${m} ${i.substring(0,a)}`),console[s](l==null||l>=u.length?u:u.slice(0,l)),u}}function D(n,t,e){return n==null||t==null?void 0:t===0&&n===0?0:!e&&t===0?void 0:n/t}function Hn(n,t,e){return n==null||t==null?e?(n!=null?n:0)-(t!=null?t:0):void 0:n-t}function Pn(n,t,e){return n==null||t==null?e?(n!=null?n:0)+(t!=null?t:0):void 0:n+t}var Yn=Object.freeze({__proto__:null,rate:D,subtract:Hn,add:Pn});function Jn(n,t,e){const u=typeof n=="function"?n:l=>l[n],r=typeof t=="function"?t:l=>l[t],{predicate:c,allowDivideByZero:o}=e!=null?e:{};return c==null?(l,s,i)=>{const a=r(l,s,i),m=u(l,s,i);return D(m,a,o)}:(l,s,i)=>{if(!c(l,s,i))return;const a=r(l,s,i),m=u(l,s,i);return D(m,a,o)}}function Zn(n,t){let e=new h.Adder,u=0;return Float64Array.from(n,r=>e.add(+(t(r,u++,n)||0)))}function Qn(n,t){let e=0;for(let u=0;u<n.length;++u){const r=t(n[u],u,n);+r===r&&(e+=1)}return e?h.fsum(n,t)/e:void 0}function Xn(n){const t=typeof n=="function"?n:e=>e[n];return e=>Zn(e,t)}function xn(n,t,e){const{partial:u=!1,align:r="right"}=e!=null?e:{},c=Math.floor(n/2);return o=>o.map((l,s)=>{const i=r==="right"?s:r==="center"?s+c:s+n-1;if(!u&&(i-n+1<0||i>=o.length))return;const a=Math.max(0,i-n+1),m=o.slice(a,i+1);return t(m,i)})}function nt(n,t){const e=typeof n=="function"?n:c=>c[n],{n:u=1,default:r}=t!=null?t:{};return c=>c.map((o,l)=>{const s=c[l-u];return s==null?r:e(s,l,c)})}function tt(n,t){const e=typeof n=="function"?n:c=>c[n],{n:u=1,default:r}=t!=null?t:{};return c=>c.map((o,l)=>{const s=c[l+u];return s==null?r:e(s,l,c)})}function et(n){var t;const e=(t=n==null?void 0:n.startAt)!=null?t:0;return u=>u.map((r,c)=>c+e)}function ut(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.min(e,t)}function rt(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.max(e,t)}function ot(n){const t=typeof n=="function"?n:e=>e[n];return e=>Qn(e,t)}function ct(n,t){const e=typeof n=="function"?n:r=>r[n],u=typeof t=="function"?t:r=>r[t];return r=>{const c=h.fsum(r,e),o=h.fsum(r,u);return D(c,o)}}function lt(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.median(e,t)}function st(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.deviation(e,t)}function ft(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.variance(e,t)}function it(n,t={}){const e=typeof n=="function"?n:u=>u[n];return u=>{const r=new Map;let c=0,o=0;for(const l of u){const s=e(l,o++,u);if(!r.has(s)){if(!t.includeUndefined&&s===void 0||t.includeNull===!1&&s===null)continue;c+=1,r.set(s,!0)}}return c}}function at(n){const t=typeof n=="function"?n:e=>e[n];return e=>e.length?t(e[0]):void 0}function mt(n){const t=typeof n=="function"?n:e=>e[n];return e=>e.length?t(e[e.length-1]):void 0}function dt(n,t=!0){return e=>{const u=new RegExp(`^${n}`,t?"i":void 0);return w(e).filter(c=>u.test(c))}}function yt(n,t=!0){return e=>{const u=new RegExp(`${n}$`,t?"i":void 0);return w(e).filter(c=>u.test(c))}}function pt(n,t=!0){return e=>{const u=new RegExp(n,t?"i":void 0);return w(e).filter(c=>u.test(c))}}function ht(n){return t=>w(t).filter(u=>n.test(u))}function gt(n,t,e){return u=>{const r=w(u),c=[];for(let o=t[0];o<=t[1];++o){const l=e==null?o:new String("00000000"+o).slice(-e);c.push(`${n}${l}`)}return r.filter(o=>c.includes(o))}}function _t(n){return t=>{let e=new Set;for(const r of j(n))if(typeof r=="function"){const c=r(t);for(const o of c)e.add(o)}else e.add(r);return Array.from(e).map(r=>`-${r}`)}}f.TMath=Yn,f.addItems=un,f.addRows=un,f.arrange=k,f.asc=C,f.complete=Nn,f.contains=pt,f.count=Mn,f.cumsum=Xn,f.debug=Gn,f.desc=L,f.deviation=st,f.distinct=an,f.endsWith=yt,f.everything=tn,f.expand=rn,f.fill=Bn,f.filter=ln,f.first=at,f.fixedOrder=mn,f.fullJoin=$n,f.fullSeq=Tn,f.fullSeqDate=Vn,f.fullSeqDateISOString=Un,f.groupBy=v,f.innerJoin=zn,f.lag=nt,f.last=mt,f.lead=tt,f.leftJoin=nn,f.map=fn,f.matches=ht,f.max=rt,f.mean=ot,f.meanRate=ct,f.median=lt,f.min=ut,f.mutate=M,f.mutateWithSummary=En,f.n=Q,f.nDistinct=it,f.negate=_t,f.numRange=gt,f.pick=G,f.pivotLonger=Ln,f.pivotWider=qn,f.rate=Jn,f.rename=wn,f.replaceNully=cn,f.roll=xn,f.rowNumber=et,f.select=G,f.slice=V,f.sliceHead=Fn,f.sliceMax=An,f.sliceMin=Kn,f.sliceSample=In,f.sliceTail=On,f.sort=k,f.startsWith=dt,f.sum=X,f.summarize=W,f.summarizeAll=Y,f.summarizeAt=Z,f.summarizeIf=J,f.tally=x,f.tidy=I,f.total=dn,f.totalAll=yn,f.totalAt=hn,f.totalIf=pn,f.transmute=Dn,f.variance=ft,f.vectorSeq=on,f.vectorSeqDate=H,f.when=sn,Object.defineProperty(f,"__esModule",{value:!0})});
1
+ (function(f,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("d3-array")):typeof define=="function"&&define.amd?define(["exports","d3-array"],h):(f=typeof globalThis!="undefined"?globalThis:f||self,h(f.Tidy={},f.d3))})(this,(function(f,h){"use strict";function E(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)r&&(e=r(e));return e}function an(n){return t=>t.filter(n)}function dn(n,t){return e=>{if(typeof n=="function"){if(!n(e))return e}else if(!n)return e;return E(e,...t)}}function mn(n){return t=>t.map(n)}function k(n){return n==null?[]:Array.isArray(n)?n:[n]}function pn(n){return t=>{if(n=k(n),!n.length){const o=new Set;for(const c of t)o.add(c);return Array.from(o)}const e=new Map,r=[],u=n[n.length-1];for(const o of t){let c=e,i=!1;for(const l of n){const a=typeof l=="function"?l(o):o[l];if(l===u){i=c.has(a),i||(r.push(o),c.set(a,!0));break}c.has(a)||c.set(a,new Map),c=c.get(a)}}return r}}function T(n){return t=>{const e=k(n).map(r=>typeof r=="function"?r.length===1?I(r):r:I(r));return t.slice().sort((r,u)=>{for(const o of e){const c=o(r,u);if(c)return c}return 0})}}function I(n){const t=typeof n=="function"?n:e=>e[n];return function(e,r){return P(t(e),t(r),!1)}}function K(n){const t=typeof n=="function"?n:e=>e[n];return function(e,r){return P(t(e),t(r),!0)}}function yn(n,t,e){let{position:r="start"}=e!=null?e:{};const u=r==="end"?-1:1,o=new Map;for(let i=0;i<t.length;++i)o.set(t[i],i);const c=typeof n=="function"?n:i=>i[n];return function(i,l){var a,d;const s=(a=o.get(c(i)))!=null?a:-1,m=(d=o.get(c(l)))!=null?d:-1;return s>=0&&m>=0?s-m:s>=0?u*-1:m>=0?u*1:0}}function P(n,t,e){let r=e?t:n,u=e?n:t;if(D(r)&&D(u)){const o=(r!==r?0:r===null?1:2)-(u!==u?0:u===null?1:2);return e?-o:o}return D(r)?e?-1:1:D(u)?e?1:-1:h.ascending(r,u)}function D(n){return n==null||n!==n}function z(n,t){return e=>{t=t!=null?t:{};const r={},u=Object.keys(n);for(const o of u)r[o]=n[o](e);if(t.rest&&e.length){const o=new Set(u),c=Object.keys(e[0]);for(const i of c)o.has(i)||(r[i]=t.rest(i)(e))}return[r]}}function R(n,t,e,r){if(!n.length)return[];const u={};let o;if(r==null)o=Object.keys(n[0]);else{o=[];for(const c of k(r))typeof c=="function"?o.push(...c(n)):o.push(c)}for(const c of o){if(e){const i=n.map(l=>l[c]);if(!e(i))continue}u[c]=t(c)(n)}return[u]}function V(n){return t=>R(t,n)}function Z(n,t){return e=>R(e,t,n)}function Q(n,t){return e=>R(e,t,void 0,n)}function M(n){return t=>{const e=t.map(u=>({...u}));let r=0;for(const u of e){for(const o in n){const c=n[o],i=typeof c=="function"?c(u,r,e):c;u[o]=i}++r}return e}}function gn(n,t){return e=>{const r=z(n)(e),u=M(t)(r);return[...e,...u]}}function hn(n,t){return e=>{const r=V(n)(e),u=M(t)(r);return[...e,...u]}}function bn(n,t,e){return r=>{const u=Z(n,t)(r),o=M(e)(u);return[...r,...o]}}function vn(n,t,e){return r=>{const u=Q(n,t)(r),o=M(e)(u);return[...r,...o]}}function U(n,t,e){if(n==null||typeof n!="object"||Array.isArray(n))return n;const r=e!=null?e:t.filter(o=>typeof o[0]!="function"&&o[0]!=null),u=Object.fromEntries(r);return Object.assign(u,n)}function F(n,t,e,r,u,o=0){for(const[c,i]of n.entries()){if(e.push(c),i instanceof Map){const l=r(t,e,o);F(i,l,e,r,u,o+1)}else u(t,e,i,o);e.pop()}return t}function Sn(n,t,e=r=>r[r.length-1]){function r(c,i){const l=new Map;return c.set(e(i),l),l}function u(c,i,l){c.set(e(i),t(l,i))}const o=new Map;return F(n,o,[],r,u),o}const A=n=>n;function jn(n){const t=typeof n;return n!=null&&(t==="object"||t==="function")}function w(n,t,e){return typeof t=="function"?t=[t]:arguments.length===2&&t!=null&&!Array.isArray(t)&&(e=t),(r=>{const u=kn(r,n),o=wn(u,t,e==null?void 0:e.addGroupKeys);if(e!=null&&e.export)switch(e.export){case"grouped":return o;case"levels":return W(o,e);case"entries-obj":case"entriesObject":return W(o,{...e,export:"levels",levels:["entries-object"]});default:return W(o,{...e,export:"levels",levels:[e.export]})}return On(o,e==null?void 0:e.addGroupKeys)})}w.grouped=n=>({...n,export:"grouped"}),w.entries=n=>({...n,export:"entries"}),w.entriesObject=n=>({...n,export:"entries-object"}),w.object=n=>({...n,export:"object"}),w.map=n=>({...n,export:"map"}),w.keys=n=>({...n,export:"keys"}),w.values=n=>({...n,export:"values"}),w.levels=n=>({...n,export:"levels"});function wn(n,t,e){let r=n;if(!(t!=null&&t.length))return r;for(const u of t)u&&(r=Sn(r,(o,c)=>{const i=c.slice();let l=u(o,{groupKeys:i});if(e!==!1){const a=i.filter(d=>typeof d[0]!="function"&&d[0]!=null);l=l.map(d=>U(d,i,a))}return l}));return r}function kn(n,t){const e=k(t).map(r=>{const u=typeof r=="function"?r:c=>c[r],o=new Map;return c=>{const i=u(c),l=jn(i)?i.valueOf():i;if(o.has(l))return o.get(l);const a=[r,i];return o.set(l,a),a}});return h.group(n,...e)}function On(n,t){const e=[];return F(n,e,[],A,(r,u,o)=>{let c=o;if(t!==!1){const i=u.filter(l=>typeof l[0]!="function"&&l[0]!=null);c=o.map(l=>U(l,u,i))}r.push(...c)}),e}const Tn=n=>n.join("/");function Mn(n){var t;const{flat:e,single:r,mapLeaf:u=A,mapLeaves:o=A,addGroupKeys:c}=n;let i;return n.flat&&(i=(t=n.compositeKey)!=null?t:Tn),{groupFn:(l,a)=>r?u(c===!1?l[0]:U(l[0],a)):o(l.map(d=>u(c===!1?d:U(d,a)))),keyFn:e?l=>i(l.map(a=>a[1])):l=>l[l.length-1][1]}}function W(n,t){const{groupFn:e,keyFn:r}=Mn(t);let{mapEntry:u=A}=t;const{levels:o=["entries"]}=t,c=[];for(const d of o)switch(d){case"entries":case"entries-object":case"entries-obj":case"entriesObject":{const s=(d==="entries-object"||d==="entries-obj"||d==="entriesObject")&&t.mapEntry==null?([m,p])=>({key:m,values:p}):u;c.push({id:"entries",createEmptySubgroup:()=>[],addSubgroup:(m,p,y,S)=>{m.push(s([y,p],S))},addLeaf:(m,p,y,S)=>{m.push(s([p,y],S))}});break}case"map":c.push({id:"map",createEmptySubgroup:()=>new Map,addSubgroup:(s,m,p)=>{s.set(p,m)},addLeaf:(s,m,p)=>{s.set(m,p)}});break;case"object":c.push({id:"object",createEmptySubgroup:()=>({}),addSubgroup:(s,m,p)=>{s[p]=m},addLeaf:(s,m,p)=>{s[m]=p}});break;case"keys":c.push({id:"keys",createEmptySubgroup:()=>[],addSubgroup:(s,m,p)=>{s.push([p,m])},addLeaf:(s,m)=>{s.push(m)}});break;case"values":c.push({id:"values",createEmptySubgroup:()=>[],addSubgroup:(s,m)=>{s.push(m)},addLeaf:(s,m,p)=>{s.push(p)}});break;default:typeof d=="object"&&c.push(d)}const i=(d,s,m)=>{var p,y;if(t.flat)return d;const S=(p=c[m])!=null?p:c[c.length-1],b=((y=c[m+1])!=null?y:S).createEmptySubgroup();return S.addSubgroup(d,b,r(s),m),b},l=(d,s,m,p)=>{var y;((y=c[p])!=null?y:c[c.length-1]).addLeaf(d,r(s),e(m,s),p)},a=c[0].createEmptySubgroup();return F(n,a,[],i,l)}function X(n){if(n!=null&&n.predicate){const t=n.predicate;return e=>e.reduce((r,u,o)=>t(u,o,e)?r+1:r,0)}return t=>t.length}function x(n,t){let e=typeof n=="function"?n:r=>r[n];if(t!=null&&t.predicate){const r=e,u=t.predicate;e=(o,c,i)=>u(o,c,i)?r(o,c,i):0}return r=>h.fsum(r,e)}function nn(n){return t=>{const{name:e="n",wt:r}=n!=null?n:{};return z({[e]:r==null?X():x(r)})(t)}}function $n(n,t){return e=>{t=t!=null?t:{};const{name:r="n",sort:u}=t;return E(e,w(n,[nn(t)]),u?T(K(r)):A)}}function An(n){return t=>t.map(e=>{var r;const u={},o=Object.keys(e);for(const c of o){const i=(r=n[c])!=null?r:c;u[i]=e[c]}return u})}function J(n,t){return e=>e.slice(n,t)}const En=n=>J(0,n),Dn=n=>J(-n);function Un(n,t){return e=>T(t)(e).slice(0,n)}function Fn(n,t){return e=>typeof t=="function"?T(t)(e).slice(-n).reverse():T(K(t))(e).slice(0,n)}function Ln(n,t){t=t!=null?t:{};const{replace:e}=t;return r=>{if(!r.length)return r.slice();if(e){const u=[];for(let o=0;o<n;++o)u.push(r[Math.floor(Math.random()*r.length)]);return u}return h.shuffle(r.slice()).slice(0,n)}}function N(n,t){if(n.length===0||t.length===0)return{};const e=Object.keys(n[0]),r=Object.keys(t[0]),u={};for(const o of e)r.includes(o)&&(u[o]=o);return u}function _(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}}const qn="\0",Cn="N",In="U";function tn(n){return n===null?Cn:n===void 0?In:String(n)}function L(n,t){if(t.length===1)return tn(n[t[0]]);let e="";for(let r=0;r<t.length;r++)r>0&&(e+=qn),e+=tn(n[t[r]]);return e}function B(n,t){const e=new Map;for(const r of n){const u=L(r,t);let o=e.get(u);o===void 0&&(o=[],e.set(u,o)),o.push(r)}return e}function Kn(n,t){return e=>{const r=(t==null?void 0:t.by)==null?N(e,n):_(t.by),u=Object.keys(r),o=u.map(i=>r[i]),c=B(n,u);return e.flatMap(i=>{const l=L(i,o),a=c.get(l);return a===void 0?[]:a.map(d=>({...i,...d}))})}}function en(n,t){return e=>{if(!n.length)return e;const r=(t==null?void 0:t.by)==null?N(e,n):_(t.by),u=Object.keys(r),o=u.map(l=>r[l]),c=B(n,u),i=Object.keys(n[0]);return e.flatMap(l=>{const a=L(l,o),d=c.get(a);if(d!==void 0)return d.map(m=>({...l,...m}));const s=Object.fromEntries(i.filter(m=>l[m]==null).map(m=>[m,void 0]));return{...l,...s}})}}function zn(n,t){return e=>{if(!n.length)return e;if(!e.length)return n;const r=(t==null?void 0:t.by)==null?N(e,n):_(t.by),u=Object.keys(r),o=u.map(d=>r[d]),c=B(n,u),i=new Set,l=Object.keys(n[0]),a=e.flatMap(d=>{const s=L(d,o),m=c.get(s);if(m!==void 0){for(const y of m)i.add(y);return m.map(y=>({...d,...y}))}const p=Object.fromEntries(l.filter(y=>d[y]==null).map(y=>[y,void 0]));return{...d,...p}});if(i.size<n.length){const d=Object.fromEntries(Object.keys(e[0]).map(s=>[s,void 0]));for(const s of n)i.has(s)||a.push({...d,...s})}return a}}function Rn(n){return t=>{const e=t.map(r=>({...r}));for(const r in n){const u=n[r],o=typeof u=="function"?u(e):u,c=o!=null&&o[Symbol.iterator]&&typeof o!="string"?o:t.map(()=>o);let i=-1;for(const l of e)l[r]=c[++i]}return e}}function $(n){return n.length<1?[]:Object.keys(n[0])}function rn(){return n=>$(n)}function on(n,t){let e=[];for(const o of k(t))typeof o=="function"?e.push(...o(n)):e.push(o);e.length&&e[0][0]==="-"&&(e=[...rn()(n),...e]);const r={},u=[];for(let o=e.length-1;o>=0;o--){const c=e[o];if(c[0]==="-"){r[c.substring(1)]=!0;continue}if(r[c]){r[c]=!1;continue}u.push(c)}return u.reverse(),e=Array.from(new Set(u)),e}function G(n){return t=>{let e=on(t,n);return e.length?t.map(r=>{const u={};for(const o of e)u[o]=r[o];return u}):t}}function Wn(n){return t=>{const e=M(n)(t);return G(Object.keys(n))(e)}}function un(n){return t=>typeof n=="function"?[...t,...k(n(t))]:[...t,...k(n)]}function Jn(n){return t=>{const{namesFrom:e,valuesFrom:r,valuesFill:u,valuesFillMap:o,namesSep:c="_"}=n,i=Array.isArray(e)?e:[e],l=Array.isArray(r)?r:[r],a=[];if(!t.length)return a;const d=Object.keys(t[0]).filter(b=>!i.includes(b)&&!l.includes(b)),s={};for(const b of t)for(const v of i)s[v]==null&&(s[v]={}),s[v][b[v]]=!0;const m=[];for(const b in s)m.push(Object.keys(s[b]));const p={},y=_n(c,m);for(const b of y){if(l.length===1){p[b]=o!=null?o[l[0]]:u;continue}for(const v of l)p[`${String(v)}${c}${b}`]=o!=null?o[v]:u}function S(b){if(!b.length)return[];const v={...p};for(const g of d)v[g]=b[0][g];for(const g of b){const O=i.map(j=>g[j]).join(c);if(l.length===1){v[O]=g[l[0]];continue}for(const j of l)v[`${String(j)}${c}${O}`]=g[j]}return[v]}return d.length?E(t,w(d,[S])):S(t)}}const Nn=1e5;function _n(n="_",t){if(!t.length)return[];const e=t.reduce((u,o)=>u*o.length,1);e>Nn&&console.warn(`tidy pivotWider: generating ${e.toLocaleString()} column combinations. This may be slow or use excessive memory.`);let r=[null];for(const u of t){const o=[];for(const c of r)for(const i of u)o.push(c==null?i:`${c}${n}${i}`);r=o}return r}function Bn(n){return t=>{var e;const{namesTo:r,valuesTo:u,namesSep:o="_"}=n,c=(e=n.cols)!=null?e:[],i=on(t,c),l=Array.isArray(r)?r:[r],a=Array.isArray(u)?u:[u],d=l.length>1,s=a.length>1,m=[];if(!t.length)return m;const p=new Set(i),y=Object.keys(t[0]).filter(g=>!p.has(g)),S=s?Array.from(new Set(i.map(g=>g.substring(g.indexOf(o)+1)))):i,b=d?new Map(S.map(g=>[g,g.split(o)])):null,v=s?new Map(S.map(g=>[g,a.map(O=>`${String(O)}${o}${String(g)}`)])):null;for(const g of t){const O={};for(const j of y)O[j]=g[j];for(const j of S){const H={...O},$t=b?b.get(j):[j],sn=v?v.get(j):null;for(let C=0;C<a.length;C++){const At=a[C],Et=sn?sn[C]:j;let Dt=0;for(const Ut of l){const Ft=$t[Dt++];H[Ut]=Ft,H[At]=g[Et]}}m.push(H)}}return m}}function cn(n){return t=>{const e=Hn(n),r=[];for(const u in e){const o=e[u];let c;typeof o=="function"?c=o(t):Array.isArray(o)?c=o:c=Array.from(new Set(t.map(i=>i[u]))),r.push(c.map(i=>({[u]:i})))}return Yn(r)}}const Gn=1e5;function Yn(n){if(!n.length)return[];const t=n.reduce((r,u)=>r*u.length,1);t>Gn&&console.warn(`tidy expand: generating ${t.toLocaleString()} combinations. This may be slow or use excessive memory.`);let e=[null];for(const r of n){const u=[];for(const o of e)for(const c of r)u.push(o==null?c:{...o,...c});e=u}return e}function Hn(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 ln(n,t=1){let[e,r]=h.extent(n);const u=[];let o=e;for(;o<=r;)u.push(o),o+=t;return u}function Y(n,t="day",e=1){let[r,u]=h.extent(n);const o=[];let c=new Date(r);for(;c<=u;)if(o.push(new Date(c)),t==="second"||t==="s"||t==="seconds")c.setUTCSeconds(c.getUTCSeconds()+1*e);else if(t==="minute"||t==="min"||t==="minutes")c.setUTCMinutes(c.getUTCMinutes()+1*e);else if(t==="day"||t==="d"||t==="days")c.setUTCDate(c.getUTCDate()+1*e);else if(t==="week"||t==="w"||t==="weeks")c.setUTCDate(c.getUTCDate()+7*e);else if(t==="month"||t==="m"||t==="months")c.setUTCMonth(c.getUTCMonth()+1*e);else if(t==="year"||t==="y"||t==="years")c.setUTCFullYear(c.getUTCFullYear()+1*e);else throw new Error("Invalid granularity for date sequence: "+t);return o}function Pn(n,t){return function(e){t=t!=null?t:1;const r=typeof n=="function"?n:u=>u[n];return ln(e.map(r),t)}}function Vn(n,t,e){return function(r){t=t!=null?t:"day",e=e!=null?e:1;const u=typeof n=="function"?n:o=>o[n];return Y(r.map(u),t,e)}}function Zn(n,t,e){return function(r){t=t!=null?t:"day",e=e!=null?e:1;const u=typeof n=="function"?n:o=>o[n];return Y(r.map(o=>new Date(u(o))),t,e).map(o=>o.toISOString())}}function fn(n){return t=>{const e=[];for(const r of t){const u={...r};for(const o in n)u[o]==null&&(u[o]=n[o]);e.push(u)}return e}}function Qn(n,t){return e=>{const r=cn(n)(e),u=en(e)(r);return t?fn(t)(u):u}}function Xn(n){return t=>{const e=k(n),r={};return t.map(u=>{let o=!1;for(const i of e)u[i]!=null?r[i]=u[i]:r[i]!=null&&(o=!0);if(!o)return u;const c={...u};for(const i of e)c[i]==null&&r[i]!=null&&(c[i]=r[i]);return c})}}function xn(n,t){return(e,r)=>{var u;let o="[tidy.debug";if((u=r==null?void 0:r.groupKeys)!=null&&u.length){const s=r.groupKeys.map(m=>m.join(": ")).join(", ");s.length&&(o+="|"+s)}t=t!=null?t:{};const{limit:c=10,output:i="table"}=t,l="--------------------------------------------------------------------------------";let a=l.length;const d=o+"]"+(n==null?"":" "+n);return a=Math.max(0,a-(d.length+2)),console.log(`${d} ${l.substring(0,a)}`),console[i](c==null||c>=e.length?e:e.slice(0,c)),e}}function q(n,t,e){return n==null||t==null?void 0:t===0&&n===0?0:!e&&t===0?void 0:n/t}function nt(n,t,e){return n==null||t==null?e?(n!=null?n:0)-(t!=null?t:0):void 0:n-t}function tt(n,t,e){return n==null||t==null?e?(n!=null?n:0)+(t!=null?t:0):void 0:n+t}var et=Object.freeze({__proto__:null,add:tt,rate:q,subtract:nt});function rt(n,t,e){const r=typeof n=="function"?n:i=>i[n],u=typeof t=="function"?t:i=>i[t],{predicate:o,allowDivideByZero:c}=e!=null?e:{};return o==null?(i,l,a)=>{const d=u(i,l,a),s=r(i,l,a);return q(s,d,c)}:(i,l,a)=>{if(!o(i,l,a))return;const d=u(i,l,a),s=r(i,l,a);return q(s,d,c)}}function ot(n,t){let e=new h.Adder,r=0;return Float64Array.from(n,u=>e.add(+(t(u,r++,n)||0)))}function ut(n,t){let e=0;const r=new h.Adder;for(let u=0;u<n.length;++u){const o=t(n[u],u,n);+o===o&&(r.add(+o),e+=1)}return e?+r/e:void 0}function ct(n){const t=typeof n=="function"?n:e=>e[n];return e=>ot(e,t)}function it(n,t,e){const{partial:r=!1,align:u="right"}=e!=null?e:{},o=Math.floor(n/2);return c=>c.map((i,l)=>{const a=u==="right"?l:u==="center"?l+o:l+n-1;if(!r&&(a-n+1<0||a>=c.length))return;const d=Math.max(0,a-n+1),s=c.slice(d,a+1);return t(s,a)})}function lt(n,t){const e=typeof n=="function"?n:o=>o[n],{n:r=1,default:u}=t!=null?t:{};return o=>o.map((c,i)=>{const l=o[i-r];return l==null?u:e(l,i,o)})}function ft(n,t){const e=typeof n=="function"?n:o=>o[n],{n:r=1,default:u}=t!=null?t:{};return o=>o.map((c,i)=>{const l=o[i+r];return l==null?u:e(l,i,o)})}function st(n){var t;const e=(t=n==null?void 0:n.startAt)!=null?t:0;return r=>r.map((u,o)=>o+e)}function at(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.min(e,t)}function dt(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.max(e,t)}function mt(n){const t=typeof n=="function"?n:e=>e[n];return e=>ut(e,t)}function pt(n,t){const e=typeof n=="function"?n:u=>u[n],r=typeof t=="function"?t:u=>u[t];return u=>{const o=h.fsum(u,e),c=h.fsum(u,r);return q(o,c)}}function yt(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.median(e,t)}function gt(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.deviation(e,t)}function ht(n){const t=typeof n=="function"?n:e=>e[n];return e=>h.variance(e,t)}function bt(n,t={}){const e=typeof n=="function"?n:r=>r[n];return r=>{const u=new Set;let o=0,c=0;for(const i of r){const l=e(i,c++,r);if(!u.has(l)){if(!t.includeUndefined&&l===void 0||t.includeNull===!1&&l===null)continue;o+=1,u.add(l)}}return o}}function vt(n){const t=typeof n=="function"?n:e=>e[n];return e=>e.length?t(e[0]):void 0}function St(n){const t=typeof n=="function"?n:e=>e[n];return e=>e.length?t(e[e.length-1]):void 0}function jt(n,t=!0){return e=>{const r=new RegExp(`^${n}`,t?"i":void 0);return $(e).filter(u=>r.test(u))}}function wt(n,t=!0){return e=>{const r=new RegExp(`${n}$`,t?"i":void 0);return $(e).filter(u=>r.test(u))}}function kt(n,t=!0){return e=>{const r=new RegExp(n,t?"i":void 0);return $(e).filter(u=>r.test(u))}}function Ot(n){return t=>$(t).filter(e=>n.test(e))}function Tt(n,t,e){return r=>{const u=$(r),o=[];for(let c=t[0];c<=t[1];++c){const i=e==null?c:new String("00000000"+c).slice(-e);o.push(`${n}${i}`)}return u.filter(c=>o.includes(c))}}function Mt(n){return t=>{let e=new Set;for(const r of k(n))if(typeof r=="function"){const u=r(t);for(const o of u)e.add(o)}else e.add(r);return Array.from(e).map(r=>`-${String(r)}`)}}f.TMath=et,f.addItems=un,f.addRows=un,f.arrange=T,f.asc=I,f.complete=Qn,f.contains=kt,f.count=$n,f.cumsum=ct,f.debug=xn,f.desc=K,f.deviation=gt,f.distinct=pn,f.endsWith=wt,f.everything=rn,f.expand=cn,f.fill=Xn,f.filter=an,f.first=vt,f.fixedOrder=yn,f.fullJoin=zn,f.fullSeq=Pn,f.fullSeqDate=Vn,f.fullSeqDateISOString=Zn,f.groupBy=w,f.innerJoin=Kn,f.lag=lt,f.last=St,f.lead=ft,f.leftJoin=en,f.map=mn,f.matches=Ot,f.max=dt,f.mean=mt,f.meanRate=pt,f.median=yt,f.min=at,f.mutate=M,f.mutateWithSummary=Rn,f.n=X,f.nDistinct=bt,f.negate=Mt,f.numRange=Tt,f.pick=G,f.pivotLonger=Bn,f.pivotWider=Jn,f.rate=rt,f.rename=An,f.replaceNully=fn,f.roll=it,f.rowNumber=st,f.select=G,f.slice=J,f.sliceHead=En,f.sliceMax=Fn,f.sliceMin=Un,f.sliceSample=Ln,f.sliceTail=Dn,f.sort=T,f.startsWith=jt,f.sum=x,f.summarize=z,f.summarizeAll=V,f.summarizeAt=Q,f.summarizeIf=Z,f.tally=nn,f.tidy=E,f.total=gn,f.totalAll=hn,f.totalAt=vn,f.totalIf=bn,f.transmute=Wn,f.variance=ht,f.vectorSeq=ln,f.vectorSeqDate=Y,f.when=dn}));
2
2
  //# sourceMappingURL=tidy.min.js.map