jsonstat-toolkit
Advanced tools
+2
-2
@@ -1,2 +0,2 @@ | ||
| // jsonstat-toolkit v2.1.2 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| var JSONstat=function(){"use strict";const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(i,l){const s=(n,i,l)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(l&&!e(l.name)&&(l=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===i)return l&&-1===n.findIndex(t=>null==t)?l.from(n):n;if(1===n.length)return Array(i).fill(n[0])}for(s=0;s<i;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=i)switch(this.class=i.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===i||"object"!=typeof i)return void(this.class=null);if(i.hasOwnProperty("error"))return void(this.error=i.error);if("dataset"===i.class||"collection"===i.class||"dimension"===i.class)return new n(i);const e=Object.keys(i);this.__tree__=i,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=i.hasOwnProperty("__tree__")?i.__tree__:i,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,l),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,i=h.length,l=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=i)return;if(this.length=i,this.id=n,e&&(l("time"),l("geo"),l("metric"),l("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const i=e[n];null!==i&&(t=t.concat(i))}const i=n.filter(e=>!t.includes(e));e.classification=i.length?i:null}this.role=e,this.n=u;for(let e=0,i=this.length;e<i;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const i={};t[n[e]].category.index.forEach((t,e)=>{i[t]=e}),t[n[e]].category.index=i}}else{let i=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=i++}}else this.length=0;break;case"dimension":if(!i.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:i},id:["d"],size:[r(i.category)],value:[null]}).Dimension(0);o=i.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=i.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=i.child;this.id=d,this.length=null===d?0:d.length,this.index=i.index,this.label=i.label,this.note=i.note||null,this.unit=i.unit,this.coordinates=i.coord;break;case"collection":if(this.length=0,this.label=i.label||null,this.note=i.note||null,this.link=i.link||null,this.href=i.href||null,this.updated=i.updated||null,this.source=i.source||null,this.extension=i.extension||null,null!==this.link&&i.link.item){const t=i.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const i=e.find(e=>e.href===t);if(i)return new n(i)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const i=(t,e)=>{if(null!==t)for(let n in t)for(let i=null!==t[n]?t[n].length:0;i--;)if(t[n][i]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const l=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];i(l,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:i(l,t)}):((t,e)=>{let n=[];for(let i in t)n[t[i]]=e[i];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const i=e.index[t];if(void 0===i)return null;const l=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:i,label:e.label[t],note:o,child:r,unit:l,coord:s})},n.prototype.Dice=function(e,i,l){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof i?("boolean"==typeof i&&!0===i&&(s=!0),"boolean"==typeof l&&!0===l||(l=!1)):(s=u(i,"clone"),l=u(i,"drop"),r=u(i,"stringify"),o=u(i,"ovalue"),a=u(i,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),l&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(i=>{const l=e[i];let s=[];l.forEach(e=>{s.push(t[i]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,i={};let l=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(i[n]=l,l++)}),y.__tree__.dimension[t].category.index=i}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,i,l=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let i=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;i*=n>0?a[u-n]:1,s+=i*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let i=0,s=o[0];i<s;i++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(i);l.push(this.Data(s,e))}return l}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let i,l=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(i=e.length;i--;)r[e[i][0]]=e[i][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],i=e[n];l.push("string"==typeof i?i:1===u[t]?s(o[n].category.index):null)}return l})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,i=c.length;n<i;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const i=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let l,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){l=this.toTable(t);let e=[];const i="array"!==t.type?0:1,r="object"!==t.type?l.slice(i):l.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:l.cols,rows:e}:("array"===t.type&&e.unshift(l[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,O=n=>{const l=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===l?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?i||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),l=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const A=l.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const i=f.dimension[e].category;i.unit?w.unit=i.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=l.length,s=0;s<a;s++){for(w={},r=l[s].length;r--;)w[A[r]]=l[s][r],o(A[r],l[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},l={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){l[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${i}${l[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,O(r)}return O(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,i){const l=h(e),s=c(n);i&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:l,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const i=h(t),l=c(e);n&&z.push(l),z.push(i),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,O=_.length;if(O!=x.length)return!1;let A=[],w=1,j=1,D=[],k=[],E=[],P=[],z=[],S=[];for(s=0;s<O;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const i="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(i)}A.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=A.length,s=0;s<a;s++){let t=[];for(let e=0,n=A[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(A[s][e]);k.push(t)}for(a=k.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(k[s][e]),e++,e===k[s].length&&(e=0);E.push(t)}for(o=0;o<w;o++){m=[],a=k.length;for(let t=0;t<a;t++)b(E[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,i=e.length,l=[],s=[],r=new Array(i).fill(0);for(let t=0;t<i;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<i;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,l);void 0!==h&&l.push(h);for(let t=i-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return l},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"===t.type&&void 0===t.field&&(t.field="id");const e="arrobj"!==t.type?"array":"arrobj",n=this.id,i="array"!==e&&t.by&&-1!==n.indexOf(t.by)?t.by:null,l=t.comma||!1,s=null===i&&t.status||!1,r=t.content||"label",o=null===i?t.field||"label":"id",a="id"===t.field?"value":t.vlabel||"Value",u="id"===t.field?"status":t.slabel||"Status",h=t.meta||!1,c=i&&"string"==typeof t.prefix?t.prefix:"",f=t.drop&&t.drop.length>0?t.drop:[],d=l?t=>null===t.value?null:String(t.value).replace(".",","):t=>t.value;let y,p,b;if(f){let t=f.length;for(;t--;)(!this.Dimension(f[t])||this.Dimension(f[t]).length>1)&&f.splice(t,1)}if("array"===e){const t=n.filter(t=>-1===f.indexOf(t)),e="label"===o?t.map(t=>this.Dimension(t).label):t,i=s?[u,a]:[a],l=t.map(t=>this.Dimension(t));b=e.concat(i);const h=s?(t,e)=>t.push(e.status):()=>{};y=(e,n)=>{const i=[];for(let n=0,s=t.length;n<s;n++){const s=t[n],o=l[n];i.push("label"===r?o.Category(e[s]).label:e[s])}return h(i,n),i.push(d(n)),i}}else{const t=new Map,e=[];n.forEach(t=>{if(-1!==f.indexOf(t))return;const n=this.Dimension(t);e.push({id:t,dim:n,prop:"label"===o?n.label:t,isBy:i&&t===i})});const l=s?(t,e)=>{t[u]=e.status}:()=>{};y=(n,s)=>{const o={};let u;for(let t=0,i=e.length;t<i;t++){const i=e[t],l=i.id,s=i.prop,a=i.isBy,h=n[l],c="label"===r?i.dim.Category(h).label:h;a?u=c:o[s]=c}if(i){l(o,s);const e=Object.values(o).join("|");let n=t.get(e),i=!1;n||(n=o,t.set(e,n),i=!0);return n[c+u]=d(s),i?n:void 0}return o[a]=d(s),l(o,s),o}}if(p=this.Unflatten(y),b&&p.unshift(b),h){const t={};return n.forEach(e=>{const n=this.Dimension(e);t[e]={label:n.label,role:n.role,categories:{id:n.id,label:this.Dimension(e,!1)}}}),{meta:{type:e,label:this.label,source:this.source,updated:this.updated,id:n,status:s,by:i,drop:f.length>0?f:null,prefix:null!==i?c||"":null,comma:l,dimensions:t},data:p}}return p};const i=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};return function(t,e,l){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof l&&(l=null),l||"function"!=typeof e||(l=e),"object"==typeof t?new n(t,l):"version"===t?"2.1.2":fetch?fetch(t,s).then(i).then(t=>new n(t,l)).catch(t=>{throw t}):void 0}}(); | ||
| // jsonstat-toolkit v2.2.0 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| var JSONstat=function(){"use strict";const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(l,i){const s=(n,l,i)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(i&&!e(i.name)&&(i=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===l)return i&&-1===n.findIndex(t=>null==t)?i.from(n):n;if(1===n.length)return Array(l).fill(n[0])}for(s=0;s<l;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=l)switch(this.class=l.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===l||"object"!=typeof l)return void(this.class=null);if(l.hasOwnProperty("error"))return void(this.error=l.error);if("dataset"===l.class||"collection"===l.class||"dimension"===l.class)return new n(l);const e=Object.keys(l);this.__tree__=l,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=l.hasOwnProperty("__tree__")?l.__tree__:l,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,i),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,l=h.length,i=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=l)return;if(this.length=l,this.id=n,e&&(i("time"),i("geo"),i("metric"),i("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const l=e[n];null!==l&&(t=t.concat(l))}const l=n.filter(e=>!t.includes(e));e.classification=l.length?l:null}this.role=e,this.n=u;for(let e=0,l=this.length;e<l;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const l={};t[n[e]].category.index.forEach((t,e)=>{l[t]=e}),t[n[e]].category.index=l}}else{let l=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=l++}}else this.length=0;break;case"dimension":if(!l.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:l},id:["d"],size:[r(l.category)],value:[null]}).Dimension(0);o=l.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=l.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=l.child;this.id=d,this.length=null===d?0:d.length,this.index=l.index,this.label=l.label,this.note=l.note||null,this.unit=l.unit,this.coordinates=l.coord;break;case"collection":if(this.length=0,this.label=l.label||null,this.note=l.note||null,this.link=l.link||null,this.href=l.href||null,this.updated=l.updated||null,this.source=l.source||null,this.extension=l.extension||null,null!==this.link&&l.link.item){const t=l.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const l=e.find(e=>e.href===t);if(l)return new n(l)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const l=(t,e)=>{if(null!==t)for(let n in t)for(let l=null!==t[n]?t[n].length:0;l--;)if(t[n][l]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const i=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];l(i,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:l(i,t)}):((t,e)=>{let n=[];for(let l in t)n[t[l]]=e[l];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const l=e.index[t];if(void 0===l)return null;const i=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:l,label:e.label[t],note:o,child:r,unit:i,coord:s})},n.prototype.Dice=function(e,l,i){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof l?("boolean"==typeof l&&!0===l&&(s=!0),"boolean"==typeof i&&!0===i||(i=!1)):(s=u(l,"clone"),i=u(l,"drop"),r=u(l,"stringify"),o=u(l,"ovalue"),a=u(l,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),i&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(l=>{const i=e[l];let s=[];i.forEach(e=>{s.push(t[l]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,l={};let i=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(l[n]=i,i++)}),y.__tree__.dimension[t].category.index=l}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,l,i=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let l=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;l*=n>0?a[u-n]:1,s+=l*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let l=0,s=o[0];l<s;l++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(l);i.push(this.Data(s,e))}return i}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let l,i=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(l=e.length;l--;)r[e[l][0]]=e[l][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],l=e[n];i.push("string"==typeof l?l:1===u[t]?s(o[n].category.index):null)}return i})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,l=c.length;n<l;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const l=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let i,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){i=this.toTable(t);let e=[];const l="array"!==t.type?0:1,r="object"!==t.type?i.slice(l):i.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:i.cols,rows:e}:("array"===t.type&&e.unshift(i[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,O=n=>{const i=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===i?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?l||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),i=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const A=i.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const l=f.dimension[e].category;l.unit?w.unit=l.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=i.length,s=0;s<a;s++){for(w={},r=i[s].length;r--;)w[A[r]]=i[s][r],o(A[r],i[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},i={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){i[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${l}${i[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,O(r)}return O(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,l){const i=h(e),s=c(n);l&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:i,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const l=h(t),i=c(e);n&&z.push(i),z.push(l),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,O=_.length;if(O!=x.length)return!1;let A=[],w=1,j=1,D=[],E=[],k=[],P=[],z=[],S=[];for(s=0;s<O;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const l="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(l)}A.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=A.length,s=0;s<a;s++){let t=[];for(let e=0,n=A[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(A[s][e]);E.push(t)}for(a=E.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(E[s][e]),e++,e===E[s].length&&(e=0);k.push(t)}for(o=0;o<w;o++){m=[],a=E.length;for(let t=0;t<a;t++)b(k[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,l=e.length,i=[],s=[],r=new Array(l).fill(0);for(let t=0;t<l;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<l;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,i);void 0!==h&&i.push(h);for(let t=l-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return i},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const e=this,n="arrobj"!==t.type&&"objarr"!==t.type?"array":t.type,l=e.id,i="array"!==n&&t.by&&l.includes(t.by)?t.by:null,s=t.comma||!1,r=null===i&&t.status||!1,o=t.content||"label",a=null===i?t.field||"label":"id",u="id"===t.field?"value":t.vlabel||"Value",h="id"===t.field?"status":t.slabel||"Status",c=t.meta||!1,f=i&&"string"==typeof t.prefix?t.prefix:"",d=Array.isArray(t.drop)?t.drop.filter(t=>{const n=e.Dimension(t);return n&&1===n.length}):[],y=l.filter(t=>!d.includes(t)),p=t=>null===t?null:String(t).replace(".",","),b=s?p:t=>t;let g,m,v;switch(n){case"array":{const t="label"===a?y.map(t=>e.Dimension(t).label):y,n=r?[h,u]:[u],l=y.map(t=>e.Dimension(t));m=t.concat(n);const i=r?(t,e)=>t.push(e.status):()=>{};g=(t,e)=>{const n=[];for(let e=0,i=y.length;e<i;e++){const i=y[e],s=l[e];n.push("label"===o?s.Category(t[i]).label:t[i])}return i(n,e),n.push(b(e.value)),n},v=e.Unflatten(g);break}case"objarr":{const t=s?t=>t.map(p):t=>t,n="id"===a?t=>t:t=>e.Dimension(t).label,l="id"===o?(t,e)=>e:(t,n)=>e.Dimension(t).Category(n).label,c={};if(i){const t=y.filter(t=>t!==i),s=e.Dimension(i),r=new Map,o={};t.forEach(t=>{c[n(t)]=[]}),s.id.forEach(t=>{const e=f+("id"===a?t:s.Category(t).label);o[t]=e,c[e]=[]});let u=0;g=function(e,s){const a=t.map(t=>e[t]).join("\0");let h;if(r.has(a))h=r.get(a);else{h=u++,r.set(a,h),t.forEach(t=>{c[n(t)].push(l(t,e[t]))});for(const e in c)!t.includes(e)&&c[e].length;Object.values(o).forEach(t=>{c[t].push(null)})}const f=o[e[i]],d=s.value;null!==d&&(c[f][h]=b(d))},e.Unflatten(g)}else r?(c[u]=t(e.value),c[h]=e.status):c[u]=t(e.value),y.forEach(t=>{c[n(t)]=[]}),g=function(t,e){y.forEach(e=>{c[n(e)].push(l(e,t[e]))})},e.Unflatten(g);v=c;break}default:{const t=new Map,n=[];y.forEach(t=>{const l=e.Dimension(t);n.push({id:t,dim:l,prop:"label"===a?l.label:t,isBy:i&&t===i})});const l=r?(t,e)=>{t[h]=e.status}:()=>{};g=(e,s)=>{const r={};let a;for(let t=0,l=n.length;t<l;t++){const l=n[t],i=l.id,s=l.prop,u=l.isBy,h=e[i],c="label"===o?l.dim.Category(h).label:h;u?a=c:r[s]=c}if(i){l(r,s);const e=Object.values(r).join("|");let n=t.get(e),i=!1;n||(n=r,t.set(e,n),i=!0);return n[f+a]=b(s.value),i?n:void 0}return r[u]=b(s.value),l(r,s),r},v=e.Unflatten(g)}}if(m&&v.unshift(m),c){const t={};return l.forEach(n=>{const l=e.Dimension(n);t[n]={label:l.label,role:l.role,categories:{id:l.id,label:e.Dimension(n,!1)}}}),{meta:{type:n,label:e.label,source:e.source,updated:e.updated,id:l,status:r,by:i,drop:d.length>0?d:null,prefix:null!==i?f||"":null,comma:s,dimensions:t},data:v}}return v};const l=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};return function(t,e,i){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof i&&(i=null),i||"function"!=typeof e||(i=e),"object"==typeof t?new n(t,i):"version"===t?"2.2.0":fetch?fetch(t,s).then(l).then(t=>new n(t,i)).catch(t=>{throw t}):void 0}}(); |
+2
-2
@@ -1,2 +0,2 @@ | ||
| // jsonstat-toolkit v2.1.2 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(i,l){const s=(n,i,l)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(l&&!e(l.name)&&(l=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===i)return l&&-1===n.findIndex(t=>null==t)?l.from(n):n;if(1===n.length)return Array(i).fill(n[0])}for(s=0;s<i;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=i)switch(this.class=i.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===i||"object"!=typeof i)return void(this.class=null);if(i.hasOwnProperty("error"))return void(this.error=i.error);if("dataset"===i.class||"collection"===i.class||"dimension"===i.class)return new n(i);const e=Object.keys(i);this.__tree__=i,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=i.hasOwnProperty("__tree__")?i.__tree__:i,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,l),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,i=h.length,l=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=i)return;if(this.length=i,this.id=n,e&&(l("time"),l("geo"),l("metric"),l("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const i=e[n];null!==i&&(t=t.concat(i))}const i=n.filter(e=>!t.includes(e));e.classification=i.length?i:null}this.role=e,this.n=u;for(let e=0,i=this.length;e<i;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const i={};t[n[e]].category.index.forEach((t,e)=>{i[t]=e}),t[n[e]].category.index=i}}else{let i=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=i++}}else this.length=0;break;case"dimension":if(!i.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:i},id:["d"],size:[r(i.category)],value:[null]}).Dimension(0);o=i.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=i.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=i.child;this.id=d,this.length=null===d?0:d.length,this.index=i.index,this.label=i.label,this.note=i.note||null,this.unit=i.unit,this.coordinates=i.coord;break;case"collection":if(this.length=0,this.label=i.label||null,this.note=i.note||null,this.link=i.link||null,this.href=i.href||null,this.updated=i.updated||null,this.source=i.source||null,this.extension=i.extension||null,null!==this.link&&i.link.item){const t=i.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const i=e.find(e=>e.href===t);if(i)return new n(i)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const i=(t,e)=>{if(null!==t)for(let n in t)for(let i=null!==t[n]?t[n].length:0;i--;)if(t[n][i]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const l=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];i(l,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:i(l,t)}):((t,e)=>{let n=[];for(let i in t)n[t[i]]=e[i];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const i=e.index[t];if(void 0===i)return null;const l=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:i,label:e.label[t],note:o,child:r,unit:l,coord:s})},n.prototype.Dice=function(e,i,l){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof i?("boolean"==typeof i&&!0===i&&(s=!0),"boolean"==typeof l&&!0===l||(l=!1)):(s=u(i,"clone"),l=u(i,"drop"),r=u(i,"stringify"),o=u(i,"ovalue"),a=u(i,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),l&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(i=>{const l=e[i];let s=[];l.forEach(e=>{s.push(t[i]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,i={};let l=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(i[n]=l,l++)}),y.__tree__.dimension[t].category.index=i}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,i,l=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let i=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;i*=n>0?a[u-n]:1,s+=i*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let i=0,s=o[0];i<s;i++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(i);l.push(this.Data(s,e))}return l}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let i,l=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(i=e.length;i--;)r[e[i][0]]=e[i][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],i=e[n];l.push("string"==typeof i?i:1===u[t]?s(o[n].category.index):null)}return l})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,i=c.length;n<i;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const i=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let l,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){l=this.toTable(t);let e=[];const i="array"!==t.type?0:1,r="object"!==t.type?l.slice(i):l.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:l.cols,rows:e}:("array"===t.type&&e.unshift(l[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,O=n=>{const l=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===l?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?i||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),l=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const A=l.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const i=f.dimension[e].category;i.unit?w.unit=i.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=l.length,s=0;s<a;s++){for(w={},r=l[s].length;r--;)w[A[r]]=l[s][r],o(A[r],l[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},l={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){l[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${i}${l[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,O(r)}return O(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,i){const l=h(e),s=c(n);i&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:l,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const i=h(t),l=c(e);n&&z.push(l),z.push(i),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,O=_.length;if(O!=x.length)return!1;let A=[],w=1,j=1,D=[],k=[],E=[],P=[],z=[],S=[];for(s=0;s<O;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const i="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(i)}A.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=A.length,s=0;s<a;s++){let t=[];for(let e=0,n=A[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(A[s][e]);k.push(t)}for(a=k.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(k[s][e]),e++,e===k[s].length&&(e=0);E.push(t)}for(o=0;o<w;o++){m=[],a=k.length;for(let t=0;t<a;t++)b(E[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,i=e.length,l=[],s=[],r=new Array(i).fill(0);for(let t=0;t<i;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<i;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,l);void 0!==h&&l.push(h);for(let t=i-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return l},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"===t.type&&void 0===t.field&&(t.field="id");const e="arrobj"!==t.type?"array":"arrobj",n=this.id,i="array"!==e&&t.by&&-1!==n.indexOf(t.by)?t.by:null,l=t.comma||!1,s=null===i&&t.status||!1,r=t.content||"label",o=null===i?t.field||"label":"id",a="id"===t.field?"value":t.vlabel||"Value",u="id"===t.field?"status":t.slabel||"Status",h=t.meta||!1,c=i&&"string"==typeof t.prefix?t.prefix:"",f=t.drop&&t.drop.length>0?t.drop:[],d=l?t=>null===t.value?null:String(t.value).replace(".",","):t=>t.value;let y,p,b;if(f){let t=f.length;for(;t--;)(!this.Dimension(f[t])||this.Dimension(f[t]).length>1)&&f.splice(t,1)}if("array"===e){const t=n.filter(t=>-1===f.indexOf(t)),e="label"===o?t.map(t=>this.Dimension(t).label):t,i=s?[u,a]:[a],l=t.map(t=>this.Dimension(t));b=e.concat(i);const h=s?(t,e)=>t.push(e.status):()=>{};y=(e,n)=>{const i=[];for(let n=0,s=t.length;n<s;n++){const s=t[n],o=l[n];i.push("label"===r?o.Category(e[s]).label:e[s])}return h(i,n),i.push(d(n)),i}}else{const t=new Map,e=[];n.forEach(t=>{if(-1!==f.indexOf(t))return;const n=this.Dimension(t);e.push({id:t,dim:n,prop:"label"===o?n.label:t,isBy:i&&t===i})});const l=s?(t,e)=>{t[u]=e.status}:()=>{};y=(n,s)=>{const o={};let u;for(let t=0,i=e.length;t<i;t++){const i=e[t],l=i.id,s=i.prop,a=i.isBy,h=n[l],c="label"===r?i.dim.Category(h).label:h;a?u=c:o[s]=c}if(i){l(o,s);const e=Object.values(o).join("|");let n=t.get(e),i=!1;n||(n=o,t.set(e,n),i=!0);return n[c+u]=d(s),i?n:void 0}return o[a]=d(s),l(o,s),o}}if(p=this.Unflatten(y),b&&p.unshift(b),h){const t={};return n.forEach(e=>{const n=this.Dimension(e);t[e]={label:n.label,role:n.role,categories:{id:n.id,label:this.Dimension(e,!1)}}}),{meta:{type:e,label:this.label,source:this.source,updated:this.updated,id:n,status:s,by:i,drop:f.length>0?f:null,prefix:null!==i?c||"":null,comma:l,dimensions:t},data:p}}return p};const i=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};function l(t,e,l){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof l&&(l=null),l||"function"!=typeof e||(l=e),"object"==typeof t?new n(t,l):"version"===t?"2.1.2":fetch?fetch(t,s).then(i).then(t=>new n(t,l)).catch(t=>{throw t}):void 0}export{l as default}; | ||
| // jsonstat-toolkit v2.2.0 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(l,i){const s=(n,l,i)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(i&&!e(i.name)&&(i=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===l)return i&&-1===n.findIndex(t=>null==t)?i.from(n):n;if(1===n.length)return Array(l).fill(n[0])}for(s=0;s<l;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=l)switch(this.class=l.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===l||"object"!=typeof l)return void(this.class=null);if(l.hasOwnProperty("error"))return void(this.error=l.error);if("dataset"===l.class||"collection"===l.class||"dimension"===l.class)return new n(l);const e=Object.keys(l);this.__tree__=l,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=l.hasOwnProperty("__tree__")?l.__tree__:l,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,i),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,l=h.length,i=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=l)return;if(this.length=l,this.id=n,e&&(i("time"),i("geo"),i("metric"),i("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const l=e[n];null!==l&&(t=t.concat(l))}const l=n.filter(e=>!t.includes(e));e.classification=l.length?l:null}this.role=e,this.n=u;for(let e=0,l=this.length;e<l;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const l={};t[n[e]].category.index.forEach((t,e)=>{l[t]=e}),t[n[e]].category.index=l}}else{let l=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=l++}}else this.length=0;break;case"dimension":if(!l.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:l},id:["d"],size:[r(l.category)],value:[null]}).Dimension(0);o=l.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=l.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=l.child;this.id=d,this.length=null===d?0:d.length,this.index=l.index,this.label=l.label,this.note=l.note||null,this.unit=l.unit,this.coordinates=l.coord;break;case"collection":if(this.length=0,this.label=l.label||null,this.note=l.note||null,this.link=l.link||null,this.href=l.href||null,this.updated=l.updated||null,this.source=l.source||null,this.extension=l.extension||null,null!==this.link&&l.link.item){const t=l.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const l=e.find(e=>e.href===t);if(l)return new n(l)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const l=(t,e)=>{if(null!==t)for(let n in t)for(let l=null!==t[n]?t[n].length:0;l--;)if(t[n][l]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const i=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];l(i,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:l(i,t)}):((t,e)=>{let n=[];for(let l in t)n[t[l]]=e[l];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const l=e.index[t];if(void 0===l)return null;const i=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:l,label:e.label[t],note:o,child:r,unit:i,coord:s})},n.prototype.Dice=function(e,l,i){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof l?("boolean"==typeof l&&!0===l&&(s=!0),"boolean"==typeof i&&!0===i||(i=!1)):(s=u(l,"clone"),i=u(l,"drop"),r=u(l,"stringify"),o=u(l,"ovalue"),a=u(l,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),i&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(l=>{const i=e[l];let s=[];i.forEach(e=>{s.push(t[l]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,l={};let i=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(l[n]=i,i++)}),y.__tree__.dimension[t].category.index=l}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,l,i=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let l=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;l*=n>0?a[u-n]:1,s+=l*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let l=0,s=o[0];l<s;l++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(l);i.push(this.Data(s,e))}return i}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let l,i=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(l=e.length;l--;)r[e[l][0]]=e[l][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],l=e[n];i.push("string"==typeof l?l:1===u[t]?s(o[n].category.index):null)}return i})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,l=c.length;n<l;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const l=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let i,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){i=this.toTable(t);let e=[];const l="array"!==t.type?0:1,r="object"!==t.type?i.slice(l):i.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:i.cols,rows:e}:("array"===t.type&&e.unshift(i[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,A=n=>{const i=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===i?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?l||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),i=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const O=i.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const l=f.dimension[e].category;l.unit?w.unit=l.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=i.length,s=0;s<a;s++){for(w={},r=i[s].length;r--;)w[O[r]]=i[s][r],o(O[r],i[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},i={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){i[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${l}${i[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,A(r)}return A(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,l){const i=h(e),s=c(n);l&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:i,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const l=h(t),i=c(e);n&&z.push(i),z.push(l),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,A=_.length;if(A!=x.length)return!1;let O=[],w=1,j=1,D=[],E=[],k=[],P=[],z=[],S=[];for(s=0;s<A;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const l="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(l)}O.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=O.length,s=0;s<a;s++){let t=[];for(let e=0,n=O[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(O[s][e]);E.push(t)}for(a=E.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(E[s][e]),e++,e===E[s].length&&(e=0);k.push(t)}for(o=0;o<w;o++){m=[],a=E.length;for(let t=0;t<a;t++)b(k[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,l=e.length,i=[],s=[],r=new Array(l).fill(0);for(let t=0;t<l;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<l;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,i);void 0!==h&&i.push(h);for(let t=l-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return i},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const e=this,n="arrobj"!==t.type&&"objarr"!==t.type?"array":t.type,l=e.id,i="array"!==n&&t.by&&l.includes(t.by)?t.by:null,s=t.comma||!1,r=null===i&&t.status||!1,o=t.content||"label",a=null===i?t.field||"label":"id",u="id"===t.field?"value":t.vlabel||"Value",h="id"===t.field?"status":t.slabel||"Status",c=t.meta||!1,f=i&&"string"==typeof t.prefix?t.prefix:"",d=Array.isArray(t.drop)?t.drop.filter(t=>{const n=e.Dimension(t);return n&&1===n.length}):[],y=l.filter(t=>!d.includes(t)),p=t=>null===t?null:String(t).replace(".",","),b=s?p:t=>t;let g,m,v;switch(n){case"array":{const t="label"===a?y.map(t=>e.Dimension(t).label):y,n=r?[h,u]:[u],l=y.map(t=>e.Dimension(t));m=t.concat(n);const i=r?(t,e)=>t.push(e.status):()=>{};g=(t,e)=>{const n=[];for(let e=0,i=y.length;e<i;e++){const i=y[e],s=l[e];n.push("label"===o?s.Category(t[i]).label:t[i])}return i(n,e),n.push(b(e.value)),n},v=e.Unflatten(g);break}case"objarr":{const t=s?t=>t.map(p):t=>t,n="id"===a?t=>t:t=>e.Dimension(t).label,l="id"===o?(t,e)=>e:(t,n)=>e.Dimension(t).Category(n).label,c={};if(i){const t=y.filter(t=>t!==i),s=e.Dimension(i),r=new Map,o={};t.forEach(t=>{c[n(t)]=[]}),s.id.forEach(t=>{const e=f+("id"===a?t:s.Category(t).label);o[t]=e,c[e]=[]});let u=0;g=function(e,s){const a=t.map(t=>e[t]).join("\0");let h;if(r.has(a))h=r.get(a);else{h=u++,r.set(a,h),t.forEach(t=>{c[n(t)].push(l(t,e[t]))});for(const e in c)!t.includes(e)&&c[e].length;Object.values(o).forEach(t=>{c[t].push(null)})}const f=o[e[i]],d=s.value;null!==d&&(c[f][h]=b(d))},e.Unflatten(g)}else r?(c[u]=t(e.value),c[h]=e.status):c[u]=t(e.value),y.forEach(t=>{c[n(t)]=[]}),g=function(t,e){y.forEach(e=>{c[n(e)].push(l(e,t[e]))})},e.Unflatten(g);v=c;break}default:{const t=new Map,n=[];y.forEach(t=>{const l=e.Dimension(t);n.push({id:t,dim:l,prop:"label"===a?l.label:t,isBy:i&&t===i})});const l=r?(t,e)=>{t[h]=e.status}:()=>{};g=(e,s)=>{const r={};let a;for(let t=0,l=n.length;t<l;t++){const l=n[t],i=l.id,s=l.prop,u=l.isBy,h=e[i],c="label"===o?l.dim.Category(h).label:h;u?a=c:r[s]=c}if(i){l(r,s);const e=Object.values(r).join("|");let n=t.get(e),i=!1;n||(n=r,t.set(e,n),i=!0);return n[f+a]=b(s.value),i?n:void 0}return r[u]=b(s.value),l(r,s),r},v=e.Unflatten(g)}}if(m&&v.unshift(m),c){const t={};return l.forEach(n=>{const l=e.Dimension(n);t[n]={label:l.label,role:l.role,categories:{id:l.id,label:e.Dimension(n,!1)}}}),{meta:{type:n,label:e.label,source:e.source,updated:e.updated,id:l,status:r,by:i,drop:d.length>0?d:null,prefix:null!==i?f||"":null,comma:s,dimensions:t},data:v}}return v};const l=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};function i(t,e,i){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof i&&(i=null),i||"function"!=typeof e||(i=e),"object"==typeof t?new n(t,i):"version"===t?"2.2.0":fetch?fetch(t,s).then(l).then(t=>new n(t,i)).catch(t=>{throw t}):void 0}export{i as default}; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| // jsonstat-toolkit v2.1.2 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| "use strict";const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(i,l){const s=(n,i,l)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(l&&!e(l.name)&&(l=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===i)return l&&-1===n.findIndex(t=>null==t)?l.from(n):n;if(1===n.length)return Array(i).fill(n[0])}for(s=0;s<i;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=i)switch(this.class=i.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===i||"object"!=typeof i)return void(this.class=null);if(i.hasOwnProperty("error"))return void(this.error=i.error);if("dataset"===i.class||"collection"===i.class||"dimension"===i.class)return new n(i);const e=Object.keys(i);this.__tree__=i,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=i.hasOwnProperty("__tree__")?i.__tree__:i,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,l),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,i=h.length,l=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=i)return;if(this.length=i,this.id=n,e&&(l("time"),l("geo"),l("metric"),l("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const i=e[n];null!==i&&(t=t.concat(i))}const i=n.filter(e=>!t.includes(e));e.classification=i.length?i:null}this.role=e,this.n=u;for(let e=0,i=this.length;e<i;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const i={};t[n[e]].category.index.forEach((t,e)=>{i[t]=e}),t[n[e]].category.index=i}}else{let i=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=i++}}else this.length=0;break;case"dimension":if(!i.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:i},id:["d"],size:[r(i.category)],value:[null]}).Dimension(0);o=i.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=i.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=i.child;this.id=d,this.length=null===d?0:d.length,this.index=i.index,this.label=i.label,this.note=i.note||null,this.unit=i.unit,this.coordinates=i.coord;break;case"collection":if(this.length=0,this.label=i.label||null,this.note=i.note||null,this.link=i.link||null,this.href=i.href||null,this.updated=i.updated||null,this.source=i.source||null,this.extension=i.extension||null,null!==this.link&&i.link.item){const t=i.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const i=e.find(e=>e.href===t);if(i)return new n(i)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const i=(t,e)=>{if(null!==t)for(let n in t)for(let i=null!==t[n]?t[n].length:0;i--;)if(t[n][i]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const l=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];i(l,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:i(l,t)}):((t,e)=>{let n=[];for(let i in t)n[t[i]]=e[i];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const i=e.index[t];if(void 0===i)return null;const l=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:i,label:e.label[t],note:o,child:r,unit:l,coord:s})},n.prototype.Dice=function(e,i,l){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof i?("boolean"==typeof i&&!0===i&&(s=!0),"boolean"==typeof l&&!0===l||(l=!1)):(s=u(i,"clone"),l=u(i,"drop"),r=u(i,"stringify"),o=u(i,"ovalue"),a=u(i,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),l&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(i=>{const l=e[i];let s=[];l.forEach(e=>{s.push(t[i]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,i={};let l=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(i[n]=l,l++)}),y.__tree__.dimension[t].category.index=i}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,i,l=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let i=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;i*=n>0?a[u-n]:1,s+=i*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let i=0,s=o[0];i<s;i++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(i);l.push(this.Data(s,e))}return l}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let i,l=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(i=e.length;i--;)r[e[i][0]]=e[i][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],i=e[n];l.push("string"==typeof i?i:1===u[t]?s(o[n].category.index):null)}return l})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,i=c.length;n<i;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const i=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let l,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){l=this.toTable(t);let e=[];const i="array"!==t.type?0:1,r="object"!==t.type?l.slice(i):l.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:l.cols,rows:e}:("array"===t.type&&e.unshift(l[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,O=n=>{const l=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===l?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?i||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),l=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const A=l.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const i=f.dimension[e].category;i.unit?w.unit=i.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=l.length,s=0;s<a;s++){for(w={},r=l[s].length;r--;)w[A[r]]=l[s][r],o(A[r],l[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},l={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){l[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${i}${l[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,O(r)}return O(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,i){const l=h(e),s=c(n);i&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:l,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const i=h(t),l=c(e);n&&z.push(l),z.push(i),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,O=_.length;if(O!=x.length)return!1;let A=[],w=1,j=1,D=[],k=[],E=[],P=[],z=[],S=[];for(s=0;s<O;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const i="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(i)}A.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=A.length,s=0;s<a;s++){let t=[];for(let e=0,n=A[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(A[s][e]);k.push(t)}for(a=k.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(k[s][e]),e++,e===k[s].length&&(e=0);E.push(t)}for(o=0;o<w;o++){m=[],a=k.length;for(let t=0;t<a;t++)b(E[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,i=e.length,l=[],s=[],r=new Array(i).fill(0);for(let t=0;t<i;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<i;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,l);void 0!==h&&l.push(h);for(let t=i-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return l},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"===t.type&&void 0===t.field&&(t.field="id");const e="arrobj"!==t.type?"array":"arrobj",n=this.id,i="array"!==e&&t.by&&-1!==n.indexOf(t.by)?t.by:null,l=t.comma||!1,s=null===i&&t.status||!1,r=t.content||"label",o=null===i?t.field||"label":"id",a="id"===t.field?"value":t.vlabel||"Value",u="id"===t.field?"status":t.slabel||"Status",h=t.meta||!1,c=i&&"string"==typeof t.prefix?t.prefix:"",f=t.drop&&t.drop.length>0?t.drop:[],d=l?t=>null===t.value?null:String(t.value).replace(".",","):t=>t.value;let y,p,b;if(f){let t=f.length;for(;t--;)(!this.Dimension(f[t])||this.Dimension(f[t]).length>1)&&f.splice(t,1)}if("array"===e){const t=n.filter(t=>-1===f.indexOf(t)),e="label"===o?t.map(t=>this.Dimension(t).label):t,i=s?[u,a]:[a],l=t.map(t=>this.Dimension(t));b=e.concat(i);const h=s?(t,e)=>t.push(e.status):()=>{};y=(e,n)=>{const i=[];for(let n=0,s=t.length;n<s;n++){const s=t[n],o=l[n];i.push("label"===r?o.Category(e[s]).label:e[s])}return h(i,n),i.push(d(n)),i}}else{const t=new Map,e=[];n.forEach(t=>{if(-1!==f.indexOf(t))return;const n=this.Dimension(t);e.push({id:t,dim:n,prop:"label"===o?n.label:t,isBy:i&&t===i})});const l=s?(t,e)=>{t[u]=e.status}:()=>{};y=(n,s)=>{const o={};let u;for(let t=0,i=e.length;t<i;t++){const i=e[t],l=i.id,s=i.prop,a=i.isBy,h=n[l],c="label"===r?i.dim.Category(h).label:h;a?u=c:o[s]=c}if(i){l(o,s);const e=Object.values(o).join("|");let n=t.get(e),i=!1;n||(n=o,t.set(e,n),i=!0);return n[c+u]=d(s),i?n:void 0}return o[a]=d(s),l(o,s),o}}if(p=this.Unflatten(y),b&&p.unshift(b),h){const t={};return n.forEach(e=>{const n=this.Dimension(e);t[e]={label:n.label,role:n.role,categories:{id:n.id,label:this.Dimension(e,!1)}}}),{meta:{type:e,label:this.label,source:this.source,updated:this.updated,id:n,status:s,by:i,drop:f.length>0?f:null,prefix:null!==i?c||"":null,comma:l,dimensions:t},data:p}}return p};const i=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};module.exports=function(t,e,l){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof l&&(l=null),l||"function"!=typeof e||(l=e),"object"==typeof t?new n(t,l):"version"===t?"2.1.2":fetch?fetch(t,s).then(i).then(t=>new n(t,l)).catch(t=>{throw t}):void 0}; | ||
| // jsonstat-toolkit v2.2.0 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| "use strict";const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(l,i){const s=(n,l,i)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(i&&!e(i.name)&&(i=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===l)return i&&-1===n.findIndex(t=>null==t)?i.from(n):n;if(1===n.length)return Array(l).fill(n[0])}for(s=0;s<l;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=l)switch(this.class=l.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===l||"object"!=typeof l)return void(this.class=null);if(l.hasOwnProperty("error"))return void(this.error=l.error);if("dataset"===l.class||"collection"===l.class||"dimension"===l.class)return new n(l);const e=Object.keys(l);this.__tree__=l,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=l.hasOwnProperty("__tree__")?l.__tree__:l,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,i),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,l=h.length,i=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=l)return;if(this.length=l,this.id=n,e&&(i("time"),i("geo"),i("metric"),i("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const l=e[n];null!==l&&(t=t.concat(l))}const l=n.filter(e=>!t.includes(e));e.classification=l.length?l:null}this.role=e,this.n=u;for(let e=0,l=this.length;e<l;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const l={};t[n[e]].category.index.forEach((t,e)=>{l[t]=e}),t[n[e]].category.index=l}}else{let l=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=l++}}else this.length=0;break;case"dimension":if(!l.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:l},id:["d"],size:[r(l.category)],value:[null]}).Dimension(0);o=l.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=l.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=l.child;this.id=d,this.length=null===d?0:d.length,this.index=l.index,this.label=l.label,this.note=l.note||null,this.unit=l.unit,this.coordinates=l.coord;break;case"collection":if(this.length=0,this.label=l.label||null,this.note=l.note||null,this.link=l.link||null,this.href=l.href||null,this.updated=l.updated||null,this.source=l.source||null,this.extension=l.extension||null,null!==this.link&&l.link.item){const t=l.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const l=e.find(e=>e.href===t);if(l)return new n(l)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const l=(t,e)=>{if(null!==t)for(let n in t)for(let l=null!==t[n]?t[n].length:0;l--;)if(t[n][l]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const i=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];l(i,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:l(i,t)}):((t,e)=>{let n=[];for(let l in t)n[t[l]]=e[l];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const l=e.index[t];if(void 0===l)return null;const i=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:l,label:e.label[t],note:o,child:r,unit:i,coord:s})},n.prototype.Dice=function(e,l,i){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof l?("boolean"==typeof l&&!0===l&&(s=!0),"boolean"==typeof i&&!0===i||(i=!1)):(s=u(l,"clone"),i=u(l,"drop"),r=u(l,"stringify"),o=u(l,"ovalue"),a=u(l,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),i&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(l=>{const i=e[l];let s=[];i.forEach(e=>{s.push(t[l]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,l={};let i=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(l[n]=i,i++)}),y.__tree__.dimension[t].category.index=l}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,l,i=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let l=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;l*=n>0?a[u-n]:1,s+=l*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let l=0,s=o[0];l<s;l++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(l);i.push(this.Data(s,e))}return i}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let l,i=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(l=e.length;l--;)r[e[l][0]]=e[l][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],l=e[n];i.push("string"==typeof l?l:1===u[t]?s(o[n].category.index):null)}return i})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,l=c.length;n<l;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const l=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let i,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){i=this.toTable(t);let e=[];const l="array"!==t.type?0:1,r="object"!==t.type?i.slice(l):i.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:i.cols,rows:e}:("array"===t.type&&e.unshift(i[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,A=n=>{const i=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===i?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?l||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),i=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const O=i.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const l=f.dimension[e].category;l.unit?w.unit=l.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=i.length,s=0;s<a;s++){for(w={},r=i[s].length;r--;)w[O[r]]=i[s][r],o(O[r],i[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},i={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){i[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${l}${i[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,A(r)}return A(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,l){const i=h(e),s=c(n);l&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:i,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const l=h(t),i=c(e);n&&z.push(i),z.push(l),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,A=_.length;if(A!=x.length)return!1;let O=[],w=1,j=1,D=[],E=[],k=[],P=[],z=[],S=[];for(s=0;s<A;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const l="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(l)}O.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=O.length,s=0;s<a;s++){let t=[];for(let e=0,n=O[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(O[s][e]);E.push(t)}for(a=E.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(E[s][e]),e++,e===E[s].length&&(e=0);k.push(t)}for(o=0;o<w;o++){m=[],a=E.length;for(let t=0;t<a;t++)b(k[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,l=e.length,i=[],s=[],r=new Array(l).fill(0);for(let t=0;t<l;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<l;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,i);void 0!==h&&i.push(h);for(let t=l-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return i},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const e=this,n="arrobj"!==t.type&&"objarr"!==t.type?"array":t.type,l=e.id,i="array"!==n&&t.by&&l.includes(t.by)?t.by:null,s=t.comma||!1,r=null===i&&t.status||!1,o=t.content||"label",a=null===i?t.field||"label":"id",u="id"===t.field?"value":t.vlabel||"Value",h="id"===t.field?"status":t.slabel||"Status",c=t.meta||!1,f=i&&"string"==typeof t.prefix?t.prefix:"",d=Array.isArray(t.drop)?t.drop.filter(t=>{const n=e.Dimension(t);return n&&1===n.length}):[],y=l.filter(t=>!d.includes(t)),p=t=>null===t?null:String(t).replace(".",","),b=s?p:t=>t;let g,m,v;switch(n){case"array":{const t="label"===a?y.map(t=>e.Dimension(t).label):y,n=r?[h,u]:[u],l=y.map(t=>e.Dimension(t));m=t.concat(n);const i=r?(t,e)=>t.push(e.status):()=>{};g=(t,e)=>{const n=[];for(let e=0,i=y.length;e<i;e++){const i=y[e],s=l[e];n.push("label"===o?s.Category(t[i]).label:t[i])}return i(n,e),n.push(b(e.value)),n},v=e.Unflatten(g);break}case"objarr":{const t=s?t=>t.map(p):t=>t,n="id"===a?t=>t:t=>e.Dimension(t).label,l="id"===o?(t,e)=>e:(t,n)=>e.Dimension(t).Category(n).label,c={};if(i){const t=y.filter(t=>t!==i),s=e.Dimension(i),r=new Map,o={};t.forEach(t=>{c[n(t)]=[]}),s.id.forEach(t=>{const e=f+("id"===a?t:s.Category(t).label);o[t]=e,c[e]=[]});let u=0;g=function(e,s){const a=t.map(t=>e[t]).join("\0");let h;if(r.has(a))h=r.get(a);else{h=u++,r.set(a,h),t.forEach(t=>{c[n(t)].push(l(t,e[t]))});for(const e in c)!t.includes(e)&&c[e].length;Object.values(o).forEach(t=>{c[t].push(null)})}const f=o[e[i]],d=s.value;null!==d&&(c[f][h]=b(d))},e.Unflatten(g)}else r?(c[u]=t(e.value),c[h]=e.status):c[u]=t(e.value),y.forEach(t=>{c[n(t)]=[]}),g=function(t,e){y.forEach(e=>{c[n(e)].push(l(e,t[e]))})},e.Unflatten(g);v=c;break}default:{const t=new Map,n=[];y.forEach(t=>{const l=e.Dimension(t);n.push({id:t,dim:l,prop:"label"===a?l.label:t,isBy:i&&t===i})});const l=r?(t,e)=>{t[h]=e.status}:()=>{};g=(e,s)=>{const r={};let a;for(let t=0,l=n.length;t<l;t++){const l=n[t],i=l.id,s=l.prop,u=l.isBy,h=e[i],c="label"===o?l.dim.Category(h).label:h;u?a=c:r[s]=c}if(i){l(r,s);const e=Object.values(r).join("|");let n=t.get(e),i=!1;n||(n=r,t.set(e,n),i=!0);return n[f+a]=b(s.value),i?n:void 0}return r[u]=b(s.value),l(r,s),r},v=e.Unflatten(g)}}if(m&&v.unshift(m),c){const t={};return l.forEach(n=>{const l=e.Dimension(n);t[n]={label:l.label,role:l.role,categories:{id:l.id,label:e.Dimension(n,!1)}}}),{meta:{type:n,label:e.label,source:e.source,updated:e.updated,id:l,status:r,by:i,drop:d.length>0?d:null,prefix:null!==i?f||"":null,comma:s,dimensions:t},data:v}}return v};const l=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};module.exports=function(t,e,i){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof i&&(i=null),i||"function"!=typeof e||(i=e),"object"==typeof t?new n(t,i):"version"===t?"2.2.0":fetch?fetch(t,s).then(l).then(t=>new n(t,i)).catch(t=>{throw t}):void 0}; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| // jsonstat-toolkit v2.1.2 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(i,l){const s=(n,i,l)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(l&&!e(l.name)&&(l=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===i)return l&&-1===n.findIndex(t=>null==t)?l.from(n):n;if(1===n.length)return Array(i).fill(n[0])}for(s=0;s<i;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=i)switch(this.class=i.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===i||"object"!=typeof i)return void(this.class=null);if(i.hasOwnProperty("error"))return void(this.error=i.error);if("dataset"===i.class||"collection"===i.class||"dimension"===i.class)return new n(i);const e=Object.keys(i);this.__tree__=i,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=i.hasOwnProperty("__tree__")?i.__tree__:i,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,l),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,i=h.length,l=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=i)return;if(this.length=i,this.id=n,e&&(l("time"),l("geo"),l("metric"),l("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const i=e[n];null!==i&&(t=t.concat(i))}const i=n.filter(e=>!t.includes(e));e.classification=i.length?i:null}this.role=e,this.n=u;for(let e=0,i=this.length;e<i;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const i={};t[n[e]].category.index.forEach((t,e)=>{i[t]=e}),t[n[e]].category.index=i}}else{let i=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=i++}}else this.length=0;break;case"dimension":if(!i.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:i},id:["d"],size:[r(i.category)],value:[null]}).Dimension(0);o=i.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=i.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=i.child;this.id=d,this.length=null===d?0:d.length,this.index=i.index,this.label=i.label,this.note=i.note||null,this.unit=i.unit,this.coordinates=i.coord;break;case"collection":if(this.length=0,this.label=i.label||null,this.note=i.note||null,this.link=i.link||null,this.href=i.href||null,this.updated=i.updated||null,this.source=i.source||null,this.extension=i.extension||null,null!==this.link&&i.link.item){const t=i.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const i=e.find(e=>e.href===t);if(i)return new n(i)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const i=(t,e)=>{if(null!==t)for(let n in t)for(let i=null!==t[n]?t[n].length:0;i--;)if(t[n][i]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const l=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];i(l,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:i(l,t)}):((t,e)=>{let n=[];for(let i in t)n[t[i]]=e[i];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const i=e.index[t];if(void 0===i)return null;const l=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:i,label:e.label[t],note:o,child:r,unit:l,coord:s})},n.prototype.Dice=function(e,i,l){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof i?("boolean"==typeof i&&!0===i&&(s=!0),"boolean"==typeof l&&!0===l||(l=!1)):(s=u(i,"clone"),l=u(i,"drop"),r=u(i,"stringify"),o=u(i,"ovalue"),a=u(i,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),l&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(i=>{const l=e[i];let s=[];l.forEach(e=>{s.push(t[i]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,i={};let l=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(i[n]=l,l++)}),y.__tree__.dimension[t].category.index=i}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,i,l=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let i=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;i*=n>0?a[u-n]:1,s+=i*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let i=0,s=o[0];i<s;i++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(i);l.push(this.Data(s,e))}return l}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let i,l=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(i=e.length;i--;)r[e[i][0]]=e[i][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],i=e[n];l.push("string"==typeof i?i:1===u[t]?s(o[n].category.index):null)}return l})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,i=c.length;n<i;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const i=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let l,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){l=this.toTable(t);let e=[];const i="array"!==t.type?0:1,r="object"!==t.type?l.slice(i):l.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:l.cols,rows:e}:("array"===t.type&&e.unshift(l[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,O=n=>{const l=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===l?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?i||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),l=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const A=l.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const i=f.dimension[e].category;i.unit?w.unit=i.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=l.length,s=0;s<a;s++){for(w={},r=l[s].length;r--;)w[A[r]]=l[s][r],o(A[r],l[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},l={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){l[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${i}${l[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${i}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,O(r)}return O(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,i){const l=h(e),s=c(n);i&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:l,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const i=h(t),l=c(e);n&&z.push(l),z.push(i),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,O=_.length;if(O!=x.length)return!1;let A=[],w=1,j=1,D=[],k=[],E=[],P=[],z=[],S=[];for(s=0;s<O;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const i="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(i)}A.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=A.length,s=0;s<a;s++){let t=[];for(let e=0,n=A[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(A[s][e]);k.push(t)}for(a=k.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(k[s][e]),e++,e===k[s].length&&(e=0);E.push(t)}for(o=0;o<w;o++){m=[],a=k.length;for(let t=0;t<a;t++)b(E[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,i=e.length,l=[],s=[],r=new Array(i).fill(0);for(let t=0;t<i;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<i;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,l);void 0!==h&&l.push(h);for(let t=i-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return l},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"===t.type&&void 0===t.field&&(t.field="id");const e="arrobj"!==t.type?"array":"arrobj",n=this.id,i="array"!==e&&t.by&&-1!==n.indexOf(t.by)?t.by:null,l=t.comma||!1,s=null===i&&t.status||!1,r=t.content||"label",o=null===i?t.field||"label":"id",a="id"===t.field?"value":t.vlabel||"Value",u="id"===t.field?"status":t.slabel||"Status",h=t.meta||!1,c=i&&"string"==typeof t.prefix?t.prefix:"",f=t.drop&&t.drop.length>0?t.drop:[],d=l?t=>null===t.value?null:String(t.value).replace(".",","):t=>t.value;let y,p,b;if(f){let t=f.length;for(;t--;)(!this.Dimension(f[t])||this.Dimension(f[t]).length>1)&&f.splice(t,1)}if("array"===e){const t=n.filter(t=>-1===f.indexOf(t)),e="label"===o?t.map(t=>this.Dimension(t).label):t,i=s?[u,a]:[a],l=t.map(t=>this.Dimension(t));b=e.concat(i);const h=s?(t,e)=>t.push(e.status):()=>{};y=(e,n)=>{const i=[];for(let n=0,s=t.length;n<s;n++){const s=t[n],o=l[n];i.push("label"===r?o.Category(e[s]).label:e[s])}return h(i,n),i.push(d(n)),i}}else{const t=new Map,e=[];n.forEach(t=>{if(-1!==f.indexOf(t))return;const n=this.Dimension(t);e.push({id:t,dim:n,prop:"label"===o?n.label:t,isBy:i&&t===i})});const l=s?(t,e)=>{t[u]=e.status}:()=>{};y=(n,s)=>{const o={};let u;for(let t=0,i=e.length;t<i;t++){const i=e[t],l=i.id,s=i.prop,a=i.isBy,h=n[l],c="label"===r?i.dim.Category(h).label:h;a?u=c:o[s]=c}if(i){l(o,s);const e=Object.values(o).join("|");let n=t.get(e),i=!1;n||(n=o,t.set(e,n),i=!0);return n[c+u]=d(s),i?n:void 0}return o[a]=d(s),l(o,s),o}}if(p=this.Unflatten(y),b&&p.unshift(b),h){const t={};return n.forEach(e=>{const n=this.Dimension(e);t[e]={label:n.label,role:n.role,categories:{id:n.id,label:this.Dimension(e,!1)}}}),{meta:{type:e,label:this.label,source:this.source,updated:this.updated,id:n,status:s,by:i,drop:f.length>0?f:null,prefix:null!==i?c||"":null,comma:l,dimensions:t},data:p}}return p};const i=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};function l(t,e,l){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof l&&(l=null),l||"function"!=typeof e||(l=e),"object"==typeof t?new n(t,l):"version"===t?"2.1.2":fetch?fetch(t,s).then(i).then(t=>new n(t,l)).catch(t=>{throw t}):void 0}export{l as default}; | ||
| // jsonstat-toolkit v2.2.0 Copyright 2026 Xavier Badosa https://jsonstat.com | ||
| const t=t=>"[object ArrayBuffer]"===Object.prototype.toString.call(t.buffer),e=t=>["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t);function n(l,i){const s=(n,l,i)=>{if(0===Object.entries(n).length)return null;let s,r=[];if(i&&!e(i.name)&&(i=null),"string"==typeof n&&(n=[n]),Array.isArray(n)||t(n)){if(n.length===l)return i&&-1===n.findIndex(t=>null==t)?i.from(n):n;if(1===n.length)return Array(l).fill(n[0])}for(s=0;s<l;s++)r.push(void 0===n[s]?null:n[s]);return r},r=t=>{const e=void 0===t.index?t.label:t.index;return Array.isArray(e)?e.length:Object.keys(e).length};let o,a;if(this.length=0,this.id=[],null!=l)switch(this.class=l.class||"bundle",this.class){case"bundle":if(this.error=null,this.length=0,null===l||"object"!=typeof l)return void(this.class=null);if(l.hasOwnProperty("error"))return void(this.error=l.error);if("dataset"===l.class||"collection"===l.class||"dimension"===l.class)return new n(l);const e=Object.keys(l);this.__tree__=l,this.length=e.length,this.id=e;break;case"dataset":this.__tree__=o=l.hasOwnProperty("__tree__")?l.__tree__:l,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.updated=o.updated||null,this.source=o.source||null,this.extension=o.extension||null;let u=0;const h=o.size||o.dimension&&o.dimension.size;if(this.size=h,this.value=o.hasOwnProperty("value")&&null!==o.value&&0!==o.value.length?o.value:{},u=Array.isArray(this.value)||t(this.value)?this.value.length:h.reduce((t,e)=>t*e,1),this.value=s(this.value,u,i),this.status=o.hasOwnProperty("status")&&null!==o.status?s(o.status,u):null,o.hasOwnProperty("dimension")){const t=o.dimension,e=o.role||!o.version&&t.role||null,n=o.id||t.id,l=h.length,i=t=>{e.hasOwnProperty(t)||(e[t]=null)};if(!Array.isArray(n)||!Array.isArray(h)||n.length!=l)return;if(this.length=l,this.id=n,e&&(i("time"),i("geo"),i("metric"),i("classification")),e&&null===e.classification){let t=[];for(const n of["time","geo","metric"]){const l=e[n];null!==l&&(t=t.concat(l))}const l=n.filter(e=>!t.includes(e));e.classification=l.length?l:null}this.role=e,this.n=u;for(let e=0,l=this.length;e<l;e++)if(t[n[e]].category.hasOwnProperty("index")){if(Array.isArray(t[n[e]].category.index)){const l={};t[n[e]].category.index.forEach((t,e)=>{l[t]=e}),t[n[e]].category.index=l}}else{let l=0;for(a in t[n[e]].category.index={},t[n[e]].category.label)t[n[e]].category.index[a]=l++}}else this.length=0;break;case"dimension":if(!l.hasOwnProperty("__tree__"))return new n({version:"2.0",class:"dataset",dimension:{d:l},id:["d"],size:[r(l.category)],value:[null]}).Dimension(0);o=l.__tree__;const c=[],f=o.category;if(!o.hasOwnProperty("category"))return;if(!f.hasOwnProperty("label"))for(a in f.label={},f.index)f.label[a]=a;for(a in f.index)c[f.index[a]]=a;this.__tree__=o,this.label=o.label||null,this.note=o.note||null,this.link=o.link||null,this.href=o.href||null,this.id=c,this.length=c.length,this.role=l.role,this.hierarchy=f.hasOwnProperty("child"),this.extension=o.extension||null;break;case"category":const d=l.child;this.id=d,this.length=null===d?0:d.length,this.index=l.index,this.label=l.label,this.note=l.note||null,this.unit=l.unit,this.coordinates=l.coord;break;case"collection":if(this.length=0,this.label=l.label||null,this.note=l.note||null,this.link=l.link||null,this.href=l.href||null,this.updated=l.updated||null,this.source=l.source||null,this.extension=l.extension||null,null!==this.link&&l.link.item){const t=l.link.item;this.length=Array.isArray(t)?t.length:0,this.length&&(this.id=t.map(t=>t.href))}}}n.prototype.Item=function(t){return null!==this&&"collection"===this.class&&this.length?"number"==typeof t?t>this.length||t<0?null:this.link.item[t]:"object"!=typeof t||null===t?this.link.item:t.class?this.link.item.filter(e=>{if(e.class!==t.class)return!1;if("dataset"===t.class&&"boolean"==typeof t.embedded){const n=e.id&&e.size&&e.dimension;return t.embedded?n:!n}return!0}):null:null},n.prototype.Dataset=function(t){if(null===this)return null;if("dataset"===this.class)return void 0!==t?this:[this];if("collection"===this.class){const e=this.Item({class:"dataset",embedded:!0});if(void 0===t)return e.map(t=>new n(t));if("number"==typeof t&&t>=0&&t<e.length)return new n(e[t]);if("string"==typeof t){const l=e.find(e=>e.href===t);if(l)return new n(l)}return null}if("bundle"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dataset(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Dataset(e):null}const e=this.__tree__[t];return void 0===e?null:new n({class:"dataset",__tree__:e})},n.prototype.Dimension=function(t,e){e="boolean"!=typeof e||e;const l=(t,e)=>{if(null!==t)for(let n in t)for(let l=null!==t[n]?t[n].length:0;l--;)if(t[n][l]===e)return n;return null};if(null===this||"dataset"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Dimension(t));if("number"==typeof t){const n=this.id[t];return void 0!==n?this.Dimension(n,e):null}const i=this.role;if("object"==typeof t){if(t.hasOwnProperty("role")){const n=[];for(let s=0,r=this.id.length;s<r;s++){const r=this.id[s];l(i,r)===t.role&&n.push(this.Dimension(r,e))}return void 0===n[0]?null:n}return null}const s=this.__tree__.dimension;if(void 0===s)return null;const r=s[t];return void 0===r?null:e?new n({class:"dimension",__tree__:r,role:l(i,t)}):((t,e)=>{let n=[];for(let l in t)n[t[l]]=e[l];return n})(r.category.index,r.category.label)},n.prototype.Category=function(t){if(null===this||"dimension"!==this.class)return null;if(void 0===t)return this.id.map(t=>this.Category(t));if("number"==typeof t){const e=this.id[t];return void 0!==e?this.Category(e):null}const e=this.__tree__.category;if(void 0===e)return null;const l=e.index[t];if(void 0===l)return null;const i=e.unit&&e.unit[t]||null,s=e.coordinates&&e.coordinates[t]||null,r=e.child&&e.child[t]||null,o=e.note&&e.note[t]||null;return new n({class:"category",index:l,label:e.label[t],note:o,child:r,unit:i,coord:s})},n.prototype.Dice=function(e,l,i){let s,r,o,a;const u=(t,e)=>t.hasOwnProperty(e)&&!!t[e];if(null===this||"dataset"!==this.class||null===this.value)return null;if("object"!=typeof e)return this;"object"!=typeof l?("boolean"==typeof l&&!0===l&&(s=!0),"boolean"==typeof i&&!0===i||(i=!1)):(s=u(l,"clone"),i=u(l,"drop"),r=u(l,"stringify"),o=u(l,"ovalue"),a=u(l,"ostatus"));let h,c=[],f=[];const d=this.value,y=s?new n(JSON.parse(JSON.stringify(this))):this,p=y.status,b=(t,e)=>{const n=((t,e)=>{const n={};return Array.isArray(t[e])?(t[e].forEach((t,e)=>{null!==t&&(n[String(e)]=t)}),n):t[e]})(t,e);delete t[e],t[e]=n};Array.isArray(e)&&(e=(t=>{const e={};return t.forEach(t=>{e[t[0]]=t[1]}),e})(e)),null===e&&(e={});const g=Object.keys(e);return g.length>0&&(g.forEach(t=>{const n=e[t];Array.isArray(n)||(e[t]=[n]),0===e[t].length&&delete e[t]}),i&&(e=(t=>{const e={};return Object.keys(t).forEach(n=>{e[n]=y.Dimension(n).id.filter(e=>-1===t[n].indexOf(e))}),e})(e)),y.Transform({type:"arrobj",content:"id",field:"id",status:!0}).forEach(t=>{let n=[];g.forEach(l=>{const i=e[l];let s=[];i.forEach(e=>{s.push(t[l]===e)}),n.push(-1!==s.indexOf(!0))}),-1===n.indexOf(!1)&&(c.push(t.value),f.push(t.status))}),g.forEach(t=>{const n=y.Dimension(t).id,l={};let i=0;y.size[y.id.indexOf(t)]=e[t].length,n.forEach(n=>{-1!==e[t].indexOf(n)&&(l[n]=i,i++)}),y.__tree__.dimension[t].category.index=l}),y.n=c.length,y.value=y.__tree__.value=t(d)?((t,e)=>e.from(t))(c,d.constructor):c,y.status=y.__tree__.status=null!==p?f:null),r?(h=y.__tree__,h.hasOwnProperty("id")||(h.version="2.0",h.hasOwnProperty("class")||(h.class="dataset"),h.id=h.dimension.id,h.size=h.dimension.size,delete h.dimension.id,delete h.dimension.size,h.dimension.hasOwnProperty("role")&&(h.role=h.dimension.role,delete h.dimension.role)),h.hasOwnProperty("status")&&-1!==["null","{}","[]"].indexOf(JSON.stringify(h.status))&&delete h.status,h.hasOwnProperty("role")&&(delete h.role.classification,["geo","time","metric"].forEach(t=>{null===h.role[t]&&delete h.role[t]})),o&&b(h,"value"),a&&h.hasOwnProperty("status")&&b(h,"status"),JSON.stringify(h)):y},n.prototype.Slice=function(t){return null===this||"dataset"!==this.class||0===Object.entries(this.value).length?null:void 0===t?this:(Array.isArray(t)||(t=Object.keys(t).map(e=>[e,t[e]])),this.Dice(t.map(t=>[t[0],[t[1]]])))},n.prototype.Data=function(t,e){let n,l,i=[],s=t=>{for(let e in t)if(t.hasOwnProperty(e))return e};if(null===this||"dataset"!==this.class||null===this.value)return null;if(void 0===t)return this.value.map((t,e)=>this.Data(e));if("boolean"!=typeof e&&(e=!0),"number"==typeof t){const n=this.value[t];return void 0===n?null:e?{value:n,status:this.status?this.status[t]:null}:n}let r="object";const o=this.__tree__,a=o.size||o.dimension&&o.dimension.size,u=a.length;if(Array.isArray(t)){if(!Array.isArray(t[0])){if(this.length!==t.length)return null;let l=1,s=0,r=[],o=[];for(n=0;n<u;n++)if(void 0!==t[n]){if("number"!=typeof t[n]||t[n]>=a[n])return null;l*=n>0?a[u-n]:1,s+=l*t[u-n-1]}else r.push(n),o.push(a[n]);if(r.length>1)return null;if(1===r.length){for(let l=0,s=o[0];l<s;l++){let s=[];for(n=0;n<u;n++)n!==r[0]?s.push(t[n]):s.push(l);i.push(this.Data(s,e))}return i}return e?{value:this.value[s],status:this.status?this.status[s]:null}:this.value[s]}r="array"}let h=[];const c=((t,e,n)=>{let l,i=[],r={};const o=t.dimension,a=t.id||o.id,u=t.size||o&&o.size;if("array"===n){for(l=e.length;l--;)r[e[l][0]]=e[l][1];e=r}for(let t=0,n=a.length;t<n;t++){const n=a[t],l=e[n];i.push("string"==typeof l?l:1===u[t]?s(o[n].category.index):null)}return i})(o,t,r),f=o.dimension,d=o.id||f.id;for(n=0,l=c.length;n<l;n++)h.push(f[d[n]].category.index[c[n]]);return this.Data(h,e)},n.prototype.toTable=function(t,n){if(null===this||"dataset"!==this.class||null===this.value)return null;1==arguments.length&&"function"==typeof t&&(n=t,t=null);const l=void 0!==(t=t||{field:"label",content:"label",vlabel:"Value",slabel:"Status",type:"array",status:!1,unit:!1,by:null,prefix:"",drop:[],meta:!1,comma:!1,bylabel:!1}).prefix?t.prefix:"";let i,s,r,o,a;"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const u="id"===t.field,h=t=>(u?"value":t)||"Value",c=t=>(u?"status":t)||"Status",f=this.__tree__;let d=!0===t.status;if("function"==typeof n){i=this.toTable(t);let e=[];const l="array"!==t.type?0:1,r="object"!==t.type?i.slice(l):i.rows.slice(0);for(a=r.length,s=0;s<a;s++){const t=n.call(this,r[s],s);void 0!==t&&e.push(t)}return"object"===t.type?{cols:i.cols,rows:e}:("array"===t.type&&e.unshift(i[0]),e)}if("arrobj"===t.type||"objarr"===t.type){let n=[],o=function(){},u={};const c=f.role&&f.role.metric,y=this,p=y.id,b=t.by&&-1!==p.indexOf(t.by)?t.by:null,g=!0===t.meta,m=void 0!==t.drop&&Array.isArray(t.drop)?t.drop:[],v=!0===t.comma,_=!0===t.bylabel,x=y.value.constructor,A=n=>{const i=h(t.vlabel);let s,r={};return"objarr"===t.type&&(s=null===b&&e(x.name)?t=>{r[t]=t===i?x.from(n,e=>e[t]):n.map(e=>e[t])}:t=>{r[t]=n.map(e=>e[t])},Object.keys(n[0]).forEach(s),n=r),g?(r={},p.forEach(t=>{const e=y.Dimension(t);r[t]={label:e.label,role:e.role,categories:{id:e.id,label:y.Dimension(t,!1)}}}),{meta:{label:y.label,source:y.source,updated:y.updated,id:p,status:d,unit:t.unit,by:b,bylabel:_,drop:null!==b&&m.length>0?m:null,prefix:null!==b?l||"":null,comma:v,dimensions:r},data:n}):n};b&&(t.field="id"),i=this.toTable({field:t.field,vlabel:t.vlabel,slabel:t.slabel,content:t.content,status:d});const O=i.shift();let w;if(null===b&&t.unit&&c){if("id"!==t.content)for(let t=c.length;t--;){const e=this.Dimension(c[t]);u[c[t]]={};for(let n=e.length;n--;)u[c[t]][e.Category(n).label]=e.id[n]}o=function(e,n){if(-1!==c.indexOf(e)){const l=f.dimension[e].category;l.unit?w.unit=l.unit["id"!==t.content?u[e][n]:n]:w.unit=null}},t.unit=!0}else t.unit=!1;for(a=i.length,s=0;s<a;s++){for(w={},r=i[s].length;r--;)w[O[r]]=i[s][r],o(O[r],i[s][r]);n.push(w)}if(v){const e=h(t.vlabel);n.forEach(function(t){null!==t[e]&&(t[e]=String(t[e]).replace(".",","))})}if(null!==b){const e={},i={};let s,r=[];m.forEach(function(t,e){(!y.Dimension(t)||y.Dimension(t).length>1)&&(m[e]="")});const o=p.filter(function(t){return t!==b&&-1===m.indexOf(t)}),a=y.Dimension(b),u=function(t,e){let n=[];return e.forEach(function(e){n.push(t[e])}),n.join("\t")},h=function(t,e){const n={};return e.forEach(function(e){n[e]=t[e]}),n};"id"!==t.content?_?s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value}:(a.Category().forEach(function(t,e){i[t.label]=a.id[e]}),s=function(t,e,n){t[e][`${l}${i[n[b]]}`]=n.value}):s=function(t,e,n){t[e][`${l}${n[b]}`]=n.value},n.forEach(function(t){const n=u(t,o);void 0===e[n]&&(e[n]=h(t,o)),s(e,n,t,b)});for(let t in e)r.push(e[t]);return d=!1,A(r)}return A(n)}let y,p,b,g,m=[];if("object"===t.type){const t="number"==typeof this.value[0]||null===this.value[0]?"number":"string";y=function(t,e){const n=u&&t||e||t;z.push({id:t,label:n,type:"string"})},p=function(e,n,l){const i=h(e),s=c(n);l&&z.push({id:"status",label:s,type:"string"}),z.push({id:"value",label:i,type:t})},b=function(t){m.push({v:t})},g=function(t){m.push({v:t}),S.push({c:m})}}else y=function(t,e){const n=u&&t||e||t;z.push(n)},p=function(t,e,n){const l=h(t),i=c(e);n&&z.push(i),z.push(l),P.push(z)},b=function(t){m.push(t)},g=function(t){m.push(t),P.push(m)};const v=f.dimension,_=f.id||v.id,x=f.size||v.size,A=_.length;if(A!=x.length)return!1;let O=[],w=1,j=1,D=[],E=[],k=[],P=[],z=[],S=[];for(s=0;s<A;s++){const e=_[s];y(e,v[e].label),w*=x[s],j*=x[s];let n=[];for(r=0;r<x[s];r++)for(let e in v[_[s]].category.index)if(v[_[s]].category.index[e]===r){const l="id"!==t.content&&v[_[s]].category.label?v[_[s]].category.label[e]:e;n.push(l)}O.push(n),D.push(j)}for(p(t.vlabel,t.slabel,d),a=O.length,s=0;s<a;s++){let t=[];for(let e=0,n=O[s].length;e<n;e++)for(let n=0;n<w/D[s];n++)t.push(O[s][e]);E.push(t)}for(a=E.length,s=0;s<a;s++){let t=[],e=0;for(o=0;o<w;o++)t.push(E[s][e]),e++,e===E[s].length&&(e=0);k.push(t)}for(o=0;o<w;o++){m=[],a=E.length;for(let t=0;t<a;t++)b(k[t][o]);d&&b(this.status?this.status[o]:null),g(this.value[o])}return"object"===t.type?{cols:z,rows:S}:P},n.prototype.node=function(){return this.__tree__},n.prototype.toString=function(){return this.class},n.prototype.Unflatten=function(t){if(null===this||"dataset"!==this.class||null===this.value||"function"!=typeof t)return null;const e=this.id,n=this.size,l=e.length,i=[],s=[],r=new Array(l).fill(0);for(let t=0;t<l;t++)s.push(this.Dimension(t).id);for(let o=0;o<this.n;o++){const a={},u={value:this.value[o],status:this.status?this.status[o]:null};for(let t=0;t<l;t++)a[e[t]]=s[t][r[t]];const h=t(a,u,o,i);void 0!==h&&i.push(h);for(let t=l-1;t>=0&&(r[t]++,!(r[t]<n[t]));t--)r[t]=0}return i},n.prototype.Transform=function(t){if(null===this||"dataset"!==this.class||null===this.value)return null;if(null!=t){if("object"!=typeof t||void 0!==t.type&&"string"!=typeof t.type)return null}else t={};"arrobj"!==t.type&&"objarr"!==t.type||void 0!==t.field||(t.field="id");const e=this,n="arrobj"!==t.type&&"objarr"!==t.type?"array":t.type,l=e.id,i="array"!==n&&t.by&&l.includes(t.by)?t.by:null,s=t.comma||!1,r=null===i&&t.status||!1,o=t.content||"label",a=null===i?t.field||"label":"id",u="id"===t.field?"value":t.vlabel||"Value",h="id"===t.field?"status":t.slabel||"Status",c=t.meta||!1,f=i&&"string"==typeof t.prefix?t.prefix:"",d=Array.isArray(t.drop)?t.drop.filter(t=>{const n=e.Dimension(t);return n&&1===n.length}):[],y=l.filter(t=>!d.includes(t)),p=t=>null===t?null:String(t).replace(".",","),b=s?p:t=>t;let g,m,v;switch(n){case"array":{const t="label"===a?y.map(t=>e.Dimension(t).label):y,n=r?[h,u]:[u],l=y.map(t=>e.Dimension(t));m=t.concat(n);const i=r?(t,e)=>t.push(e.status):()=>{};g=(t,e)=>{const n=[];for(let e=0,i=y.length;e<i;e++){const i=y[e],s=l[e];n.push("label"===o?s.Category(t[i]).label:t[i])}return i(n,e),n.push(b(e.value)),n},v=e.Unflatten(g);break}case"objarr":{const t=s?t=>t.map(p):t=>t,n="id"===a?t=>t:t=>e.Dimension(t).label,l="id"===o?(t,e)=>e:(t,n)=>e.Dimension(t).Category(n).label,c={};if(i){const t=y.filter(t=>t!==i),s=e.Dimension(i),r=new Map,o={};t.forEach(t=>{c[n(t)]=[]}),s.id.forEach(t=>{const e=f+("id"===a?t:s.Category(t).label);o[t]=e,c[e]=[]});let u=0;g=function(e,s){const a=t.map(t=>e[t]).join("\0");let h;if(r.has(a))h=r.get(a);else{h=u++,r.set(a,h),t.forEach(t=>{c[n(t)].push(l(t,e[t]))});for(const e in c)!t.includes(e)&&c[e].length;Object.values(o).forEach(t=>{c[t].push(null)})}const f=o[e[i]],d=s.value;null!==d&&(c[f][h]=b(d))},e.Unflatten(g)}else r?(c[u]=t(e.value),c[h]=e.status):c[u]=t(e.value),y.forEach(t=>{c[n(t)]=[]}),g=function(t,e){y.forEach(e=>{c[n(e)].push(l(e,t[e]))})},e.Unflatten(g);v=c;break}default:{const t=new Map,n=[];y.forEach(t=>{const l=e.Dimension(t);n.push({id:t,dim:l,prop:"label"===a?l.label:t,isBy:i&&t===i})});const l=r?(t,e)=>{t[h]=e.status}:()=>{};g=(e,s)=>{const r={};let a;for(let t=0,l=n.length;t<l;t++){const l=n[t],i=l.id,s=l.prop,u=l.isBy,h=e[i],c="label"===o?l.dim.Category(h).label:h;u?a=c:r[s]=c}if(i){l(r,s);const e=Object.values(r).join("|");let n=t.get(e),i=!1;n||(n=r,t.set(e,n),i=!0);return n[f+a]=b(s.value),i?n:void 0}return r[u]=b(s.value),l(r,s),r},v=e.Unflatten(g)}}if(m&&v.unshift(m),c){const t={};return l.forEach(n=>{const l=e.Dimension(n);t[n]={label:l.label,role:l.role,categories:{id:l.id,label:e.Dimension(n,!1)}}}),{meta:{type:n,label:e.label,source:e.source,updated:e.updated,id:l,status:r,by:i,drop:d.length>0?d:null,prefix:null!==i?f||"":null,comma:s,dimensions:t},data:v}}return v};const l=t=>{if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()};function i(t,e,i){const s="object"==typeof e?e:{method:"GET"};return"function"!=typeof i&&(i=null),i||"function"!=typeof e||(i=e),"object"==typeof t?new n(t,i):"version"===t?"2.2.0":fetch?fetch(t,s).then(l).then(t=>new n(t,i)).catch(t=>{throw t}):void 0}export{i as default}; |
+1
-1
| { | ||
| "name": "jsonstat-toolkit", | ||
| "version": "2.1.2", | ||
| "version": "2.2.0", | ||
| "description": "JSON-stat JavaScript Toolkit: a library to deal with JSON-stat responses.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://jsonstat.com", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
82047
3.85%317
3.93%