csv-sort 6.0.10 → 6.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2 -7
- package/dist/csv-sort.esm.js +3 -3
- package/dist/csv-sort.umd.js +19 -19
- package/package.json +5 -3
- package/types/index.d.ts +3 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -26,14 +26,12 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `5.1.0`.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
npm i csv-sort
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
If you need a legacy version which works with `require`, use version 5.1.0
|
|
36
|
-
|
|
37
35
|
## Quick Take
|
|
38
36
|
|
|
39
37
|
```js
|
|
@@ -80,10 +78,7 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
80
78
|
|
|
81
79
|
MIT License
|
|
82
80
|
|
|
83
|
-
Copyright (c) 2010-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
86
82
|
List of [currency signs](https://github.com/bengourley/currency-symbol-map) - Copyright © 2017 Ben Gourley - see its [BSD-2-Clause disclaimer](https://opensource.org/licenses/BSD-2-Clause)
|
|
87
83
|
|
|
88
84
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
89
|
-
|
package/dist/csv-sort.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name csv-sort
|
|
3
3
|
* @fileoverview Sorts double-entry bookkeeping CSV coming from internet banking
|
|
4
|
-
* @version 6.0.
|
|
4
|
+
* @version 6.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/csv-sort/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import B from"lodash.pull";import{splitEasy as O}from"csv-split-easy";import R from"currency.js";function E(i){return typeof i=="number"&&!isNaN(i)?!0:(i=(i||"").toString().trim(),i?!isNaN(+i):!1)}var N=["\u062F.\u0625","\u060B","L","\u058F","\u0192","Kz","$","\u0192","\u20BC","KM","\u09F3","\u043B\u0432",".\u062F.\u0628","FBu","$b","R$","\u0E3F","Nu.","P","p.","BZ$","FC","CHF","\xA5","\u20A1","\u20B1","K\u010D","Fdj","kr","RD$","\u062F\u062C","kr","Nfk","Br","\u039E","\u20AC","\u20BE","\u20B5","GH\u20B5","D","FG","Q","L","kn","G","Ft","Rp","\u20AA","\u20B9","\u0639.\u062F","\uFDFC","kr","J$","JD","\xA5","KSh","\u043B\u0432","\u17DB","CF","\u20A9","\u20A9","KD","\u043B\u0432","\u20AD","\u20A8","M","\u0141","Lt","Ls","LD","MAD","lei","Ar","\u0434\u0435\u043D","K","\u20AE","MOP$","UM","\u20A8","Rf","MK","RM","MT","\u20A6","C$","kr","\u20A8","\uFDFC","B/.","S/.","K","\u20B1","\u20A8","z\u0142","Gs","\uFDFC","\uFFE5","lei","\u0414\u0438\u043D.","\u20BD","R\u20A3","\uFDFC","\u20A8","\u062C.\u0633.","kr","\xA3","Le","S","Db","E","\u0E3F","SM","T","\u062F.\u062A","T$","\u20A4","\u20BA","TT$","NT$","TSh","\u20B4","USh","$U","\u043B\u0432","Bs","\u20AB","VT","WS$","FCFA","\u0243","CFA","\u20A3","\uFDFC","R","Z$"];function f(i){return E(i)||N.some(b=>E(i.replace(b,"").replace(/[,.]/g,"")))?"numeric":i.trim()?"text":"empty"}var x="6.0.
|
|
11
|
-
${JSON.stringify(i,null,4)}`);if(!i.trim())return{res:[[""]],msgContent:b,msgType:
|
|
10
|
+
import B from"lodash.pull";import{splitEasy as O}from"csv-split-easy";import R from"currency.js";function E(i){return typeof i=="number"&&!isNaN(i)?!0:(i=(i||"").toString().trim(),i?!isNaN(+i):!1)}var N=["\u062F.\u0625","\u060B","L","\u058F","\u0192","Kz","$","\u0192","\u20BC","KM","\u09F3","\u043B\u0432",".\u062F.\u0628","FBu","$b","R$","\u0E3F","Nu.","P","p.","BZ$","FC","CHF","\xA5","\u20A1","\u20B1","K\u010D","Fdj","kr","RD$","\u062F\u062C","kr","Nfk","Br","\u039E","\u20AC","\u20BE","\u20B5","GH\u20B5","D","FG","Q","L","kn","G","Ft","Rp","\u20AA","\u20B9","\u0639.\u062F","\uFDFC","kr","J$","JD","\xA5","KSh","\u043B\u0432","\u17DB","CF","\u20A9","\u20A9","KD","\u043B\u0432","\u20AD","\u20A8","M","\u0141","Lt","Ls","LD","MAD","lei","Ar","\u0434\u0435\u043D","K","\u20AE","MOP$","UM","\u20A8","Rf","MK","RM","MT","\u20A6","C$","kr","\u20A8","\uFDFC","B/.","S/.","K","\u20B1","\u20A8","z\u0142","Gs","\uFDFC","\uFFE5","lei","\u0414\u0438\u043D.","\u20BD","R\u20A3","\uFDFC","\u20A8","\u062C.\u0633.","kr","\xA3","Le","S","Db","E","\u0E3F","SM","T","\u062F.\u062A","T$","\u20A4","\u20BA","TT$","NT$","TSh","\u20B4","USh","$U","\u043B\u0432","Bs","\u20AB","VT","WS$","FCFA","\u0243","CFA","\u20A3","\uFDFC","R","Z$"];function f(i){return E(i)||N.some(b=>E(i.replace(b,"").replace(/[,.]/g,"")))?"numeric":i.trim()?"text":"empty"}var x="6.0.11";var K=x;function _(i){let b=null,C=null;if(typeof i!="string")throw new TypeError(`csv-sort/csvSort(): [THROW_ID_01] The input is of a wrong type! We accept either string of array of arrays. We got instead: ${typeof i}, equal to:
|
|
11
|
+
${JSON.stringify(i,null,4)}`);if(!i.trim())return{res:[[""]],msgContent:b,msgType:C};let n=O(i),s=[],g=!1,S=!0,v=[],o=null;for(let t=n.length-1;t>=0;t--)if(s.length){t===0&&(g=n[t].every(l=>f(l)==="text"||f(l)==="empty")),!g&&s.length!==n[t].length&&(S=!1);let e=null;for(let l=0,p=n[t].length;l<p;l++)if(e===null&&f(n[t][l].trim())==="empty"&&(e=l),e!==null&&f(n[t][l].trim())!=="empty"&&(e=null),f(n[t][l].trim())!==s[l]&&!g){let a=f(n[t][l].trim());if(Array.isArray(s[l]))s[l].includes(a)||s[l].push(f(n[t][l].trim()));else if(s[l]!==a){let u=s[l];s[l]=[],s[l].push(u),s[l].push(a)}}o!==null&&e!==null&&e>o&&(!g||g&&t!==0)&&(o=e)}else if(n[t].length!==1||n[t][0]!=="")for(let e=0,l=n[t].length;e<l;e++)s.push(f(n[t][e].trim())),o===null&&f(n[t][e].trim())==="empty"&&(o=e),o!==null&&f(n[t][e].trim())!=="empty"&&(o=null);o||(o=s.length);let w=0;for(let t=0,e=s.length;t<e&&s[t]==="empty";t++)w=t;w!==0&&(n=n.map(t=>t.slice(w+1,o)),s=s.slice(w+1,o));let V=[],m;s.forEach((t,e)=>{t==="numeric"&&V.push(e)});let k=g?1:0;if(V.length===1)m=V[0];else{if(V.length===0)throw new Error('csv-sort/csvSort(): [THROW_ID_03] Your CSV file does not contain numeric-only columns and computer was not able to detect the "Balance" column!');{let t=Array.from(V),e=[];for(let l=0,p=t.length;l<p;l++){let a=t[l],u,d=!0,y,h=!0;for(let c=k,I=n.length;c<I&&(d&&(u==null?u=n[c][a]:u===n[c][a]?(e.push(a),d=!1):u=n[c][a]),h&&(y==null?y=n[c][a]:n[c][a]!==y&&(h=!1)),!!d);c++);h&&v.push(a)}if(t=B(t,...e),t.length===1)m=t[0];else if(t.length===0)throw new Error(`csv-sort/csvSort(): [THROW_ID_04] The computer can't find the "Balance" column! It saw some numeric-only columns, but they all seem to have certain rows with the same values as rows right below/above them!`)}}if(!m)throw new Error("csv-sort/csvSort(): [THROW_ID_05] Sadly computer couldn't find its way in this CSV and had to stop working on it.");let D=B(Array.from(s.reduce((t,e,l)=>((typeof e=="string"&&e==="numeric"||Array.isArray(e)&&e.includes("numeric"))&&t.push(l),t),[])),m,...v),r=[];r.push(n[n.length-1].slice(0,o));let $=[],T=g?1:0;for(let t=n.length-2;t>=T;t--)for(let e=n.length-2;e>=T;e--)if(!$.includes(e)){let l=!1;for(let p=0,a=D.length;p<a;p++){let u=null;n[e][D[p]]!==""&&(u=R(n[e][D[p]]));let d=null;n[e][m]!==""&&(d=R(n[e][m]));let y=null;r[0][m]!==""&&(y=R(r[0][m]).format());let h=null;r[r.length-1][D[p]]!==""&&(h=R(r[r.length-1][D[p]]).format());let c=null;if(r[r.length-1][m]!==""&&(c=R(r[r.length-1][m])),u&&d.add(u).format()===y){r.unshift(n[e].slice(0,o)),$.push(e),l=!0;break}else if(u&&d.subtract(u).format()===y){r.unshift(n[e].slice(0,o)),$.push(e),l=!0;break}else if(h&&c.add(h).format()===d.format()){r.push(n[e].slice(0,o)),$.push(e),l=!0;break}else if(h&&c.subtract(h).format()===d.format()){r.push(n[e].slice(0,o)),$.push(e),l=!0;break}}if(l){l=!1;break}}return g&&(S&&n[0].length>s.length&&(n[0].length=s.length),r.unshift(n[0].slice(0,o))),n.length-(g?2:1)!==$.length&&(b="Not all rows were recognised!",C="alert"),{res:r,msgContent:b,msgType:C}}export{f as findType,E as isNumeric,_ as sort,K as version};
|
package/dist/csv-sort.umd.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name csv-sort
|
|
3
3
|
* @fileoverview Sorts double-entry bookkeeping CSV coming from internet banking
|
|
4
|
-
* @version 6.0.
|
|
4
|
+
* @version 6.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/csv-sort/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var csvSort=(()=>{var Ve=Object.create;var x=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols,_e=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var W=(e,
|
|
11
|
-
${JSON.stringify(
|
|
10
|
+
var csvSort=(()=>{var Ve=Object.create;var x=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols,_e=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var W=(e,r,s)=>r in e?x(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,b=(e,r)=>{for(var s in r||(r={}))Y.call(r,s)&&W(e,s,r[s]);if(z)for(var s of z(r))je.call(r,s)&&W(e,s,r[s]);return e};var Z=e=>x(e,"__esModule",{value:!0});var J=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),We=(e,r)=>{for(var s in r)x(e,s,{get:r[s],enumerable:!0})},Q=(e,r,s,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of Fe(r))!Y.call(e,a)&&(s||a!=="default")&&x(e,a,{get:()=>r[a],enumerable:!(n=Ce(r,a))||n.enumerable});return e},k=(e,r)=>Q(Z(x(e!=null?Ve(_e(e)):{},"default",!r&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),Je=(e=>(r,s)=>e&&e.get(r)||(s=Q(Z({}),r,1),e&&e.set(r,s),s))(typeof WeakMap!="undefined"?new WeakMap:0);var H=(e,r,s)=>(W(e,typeof r!="symbol"?r+"":r,s),s);var re=J((Jt,te)=>{function ke(e,r,s){switch(s.length){case 0:return e.call(r);case 1:return e.call(r,s[0]);case 2:return e.call(r,s[0],s[1]);case 3:return e.call(r,s[0],s[1],s[2])}return e.apply(r,s)}function He(e,r){for(var s=-1,n=e?e.length:0,a=Array(n);++s<n;)a[s]=r(e[s],s,e);return a}function Me(e,r,s,n){for(var a=e.length,t=s+(n?1:-1);n?t--:++t<a;)if(r(e[t],t,e))return t;return-1}function Be(e,r,s){if(r!==r)return Me(e,Pe,s);for(var n=s-1,a=e.length;++n<a;)if(e[n]===r)return n;return-1}function qe(e,r,s,n){for(var a=s-1,t=e.length;++a<t;)if(n(e[a],r))return a;return-1}function Pe(e){return e!==e}function Ue(e){return function(r){return e(r)}}var Ke=Array.prototype,X=Ke.splice,ee=Math.max;function Le(e,r,s,n){var a=n?qe:Be,t=-1,l=r.length,u=e;for(e===r&&(r=ze(r)),s&&(u=He(e,Ue(s)));++t<l;)for(var i=0,o=r[t],f=s?s(o):o;(i=a(u,f,i,n))>-1;)u!==e&&X.call(u,i,1),X.call(e,i,1);return e}function Ge(e,r){return r=ee(r===void 0?e.length-1:r,0),function(){for(var s=arguments,n=-1,a=ee(s.length-r,0),t=Array(a);++n<a;)t[n]=s[r+n];n=-1;for(var l=Array(r+1);++n<r;)l[n]=s[n];return l[r]=t,ke(e,this,l)}}function ze(e,r){var s=-1,n=e.length;for(r||(r=Array(n));++s<n;)r[s]=e[s];return r}var Ye=Ge(Ze);function Ze(e,r){return e&&e.length&&r&&r.length?Le(e,r):e}te.exports=Ye});var Oe=J((zt,Ne)=>{var nt=1/0,st="[object Symbol]",ot=/^\s+|\s+$/g,q="\\ud800-\\udfff",fe="\\u0300-\\u036f\\ufe20-\\ufe23",ge="\\u20d0-\\u20f0",ce="\\ufe0e\\ufe0f",it="["+q+"]",P="["+fe+ge+"]",U="\\ud83c[\\udffb-\\udfff]",lt="(?:"+P+"|"+U+")",pe="[^"+q+"]",he="(?:\\ud83c[\\udde6-\\uddff]){2}",me="[\\ud800-\\udbff][\\udc00-\\udfff]",ye="\\u200d",de=lt+"?",be="["+ce+"]?",at="(?:"+ye+"(?:"+[pe,he,me].join("|")+")"+be+de+")*",ut=be+de+at,ft="(?:"+[pe+P+"?",P,he,me,it].join("|")+")",gt=RegExp(U+"(?="+U+")|"+ft+ut,"g"),ct=RegExp("["+ye+q+fe+ge+ce+"]"),pt=typeof global=="object"&&global&&global.Object===Object&&global,ht=typeof self=="object"&&self&&self.Object===Object&&self,mt=pt||ht||Function("return this")();function yt(e){return e.split("")}function dt(e,r,s,n){for(var a=e.length,t=s+(n?1:-1);n?t--:++t<a;)if(r(e[t],t,e))return t;return-1}function Te(e,r,s){if(r!==r)return dt(e,bt,s);for(var n=s-1,a=e.length;++n<a;)if(e[n]===r)return n;return-1}function bt(e){return e!==e}function Tt(e,r){for(var s=-1,n=e.length;++s<n&&Te(r,e[s],0)>-1;);return s}function $t(e,r){for(var s=e.length;s--&&Te(r,e[s],0)>-1;);return s}function wt(e){return ct.test(e)}function $e(e){return wt(e)?vt(e):yt(e)}function vt(e){return e.match(gt)||[]}var St=Object.prototype,Rt=St.toString,we=mt.Symbol,ve=we?we.prototype:void 0,Se=ve?ve.toString:void 0;function Nt(e,r,s){var n=-1,a=e.length;r<0&&(r=-r>a?0:a+r),s=s>a?a:s,s<0&&(s+=a),a=r>s?0:s-r>>>0,r>>>=0;for(var t=Array(a);++n<a;)t[n]=e[n+r];return t}function Re(e){if(typeof e=="string")return e;if(Dt(e))return Se?Se.call(e):"";var r=e+"";return r=="0"&&1/e==-nt?"-0":r}function Ot(e,r,s){var n=e.length;return s=s===void 0?n:s,!r&&s>=n?e:Nt(e,r,s)}function Et(e){return!!e&&typeof e=="object"}function Dt(e){return typeof e=="symbol"||Et(e)&&Rt.call(e)==st}function It(e){return e==null?"":Re(e)}function At(e,r,s){if(e=It(e),e&&(s||r===void 0))return e.replace(ot,"");if(!e||!(r=Re(r)))return e;var n=$e(e),a=$e(r),t=Tt(n,a),l=$t(n,a)+1;return Ot(n,t,l).join("")}Ne.exports=At});var Ie=J((K,L)=>{(function(e,r){typeof K=="object"&&typeof L!="undefined"?L.exports=r():typeof define=="function"&&define.amd?define(r):(e=e||self,e.currency=r())})(K,function(){function e(t,l){if(!(this instanceof e))return new e(t,l);l=Object.assign({},s,l);var u=Math.pow(10,l.precision);this.intValue=t=r(t,l),this.value=t/u,l.increment=l.increment||1/u,l.groups=l.useVedic?a:n,this.s=l,this.p=u}function r(t,l){var u=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0,i=l.decimal,o=l.errorOnInvalid,f=l.fromCents,g=Math.pow(10,l.precision),y=t instanceof e;if(y&&f)return t.intValue;if(typeof t=="number"||y)i=y?t.value:t;else if(typeof t=="string")o=new RegExp("[^-\\d"+i+"]","g"),i=new RegExp("\\"+i,"g"),i=(i=t.replace(/\((.*)\)/,"-$1").replace(o,"").replace(i,"."))||0;else{if(o)throw Error("Invalid Input");i=0}return f||(i=(i*g).toFixed(4)),u?Math.round(i):i}var s={symbol:"$",separator:",",decimal:".",errorOnInvalid:!1,precision:2,pattern:"!#",negativePattern:"-!#",format:function(t,l){var u=l.pattern,i=l.negativePattern,o=l.symbol,f=l.separator,g=l.decimal;l=l.groups;var y=(""+t).replace(/^-/,"").split("."),m=y[0];return y=y[1],(0<=t.value?u:i).replace("!",o).replace("#",m.replace(l,"$1"+f)+(y?g+y:""))},fromCents:!1},n=/(\d)(?=(\d{3})+\b)/g,a=/(\d)(?=(\d\d)+\d\b)/g;return e.prototype={add:function(t){var l=this.s,u=this.p;return e((this.intValue+r(t,l))/(l.fromCents?1:u),l)},subtract:function(t){var l=this.s,u=this.p;return e((this.intValue-r(t,l))/(l.fromCents?1:u),l)},multiply:function(t){var l=this.s;return e(this.intValue*t/(l.fromCents?1:Math.pow(10,l.precision)),l)},divide:function(t){var l=this.s;return e(this.intValue/r(t,l,!1),l)},distribute:function(t){var l=this.intValue,u=this.p,i=this.s,o=[],f=Math[0<=l?"floor":"ceil"](l/t),g=Math.abs(l-f*t);for(u=i.fromCents?1:u;t!==0;t--){var y=e(f/u,i);0<g--&&(y=y[0<=l?"add":"subtract"](1/u)),o.push(y)}return o},dollars:function(){return~~this.value},cents:function(){return~~(this.intValue%this.p)},format:function(t){var l=this.s;return typeof t=="function"?t(this,l):l.format(this,Object.assign({},l,t))},toString:function(){var t=this.s,l=t.increment;return(Math.round(this.intValue/this.p/l)*l).toFixed(t.precision)},toJSON:function(){return this.value}},e})});var jt={};We(jt,{findType:()=>w,isNumeric:()=>j,sort:()=>_t,version:()=>Ft});var G=k(re(),1);var Qe={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function M(e,r){if(!Array.isArray(e)||!e.length)return e;let s=b(b({},Qe),r),n,a;if(s.strictlyTwoElementsInRangeArrays&&!e.every((u,i)=>!Array.isArray(u)||u.length!==2?(n=i,a=u.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${a} elements!`);if(!e.every((u,i)=>!Array.isArray(u)||!Number.isInteger(u[0])||u[0]<0||!Number.isInteger(u[1])||u[1]<0?(n=i,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let t=e.length**2,l=0;return Array.from(e).sort((u,i)=>(s.progressFn&&(l+=1,s.progressFn(Math.floor(l*100/t))),u[0]===i[0]?u[1]<i[1]?-1:u[1]>i[1]?1:0:u[0]<i[0]?-1:1))}var ne={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function se(e,r){function s(o){return o&&typeof o=="object"&&!Array.isArray(o)}if(!Array.isArray(e)||!e.length)return null;let n;if(r)if(s(r)){if(n=b(b({},ne),r),n.progressFn&&s(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(![1,2,"1","2"].includes(n.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
|
|
11
|
+
${JSON.stringify(r,null,4)} (type ${typeof r})`);else n=b({},ne);let a=e.filter(o=>Array.isArray(o)).map(o=>[...o]).filter(o=>o[2]!==void 0||o[0]!==o[1]),t,l,u;n.progressFn?t=M(a,{progressFn:o=>{u=Math.floor(o/5),u!==l&&(l=u,n.progressFn(u))}}):t=M(a);let i=t.length-1;for(let o=i;o>0;o--)n.progressFn&&(u=Math.floor((1-o/i)*78)+21,u!==l&&u>l&&(l=u,n.progressFn(u))),(t[o][0]<=t[o-1][0]||!n.joinRangesThatTouchEdges&&t[o][0]<t[o-1][1]||n.joinRangesThatTouchEdges&&t[o][0]<=t[o-1][1])&&(t[o-1][0]=Math.min(t[o][0],t[o-1][0]),t[o-1][1]=Math.max(t[o][1],t[o-1][1]),t[o][2]!==void 0&&(t[o-1][0]>=t[o][0]||t[o-1][1]<=t[o][1])&&t[o-1][2]!==null&&(t[o][2]===null&&t[o-1][2]!==null?t[o-1][2]=null:t[o-1][2]!=null?+n.mergeType==2&&t[o-1][0]===t[o][0]?t[o-1][2]=t[o][2]:t[o-1][2]+=t[o][2]:t[o-1][2]=t[o][2]),t.splice(o,1),o=t.length);return t.length?t:null}var Xe=!0,B="Invariant failed";function oe(e,r){if(!e){if(Xe)throw new Error(B);var s=typeof r=="function"?r():r,n=s?B+": "+s:B;throw new Error(n)}}function ie(e,r,s){let n=0,a=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(r&&!Array.isArray(r))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(s&&typeof s!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof s}, equal to: ${JSON.stringify(s,null,4)}`);if(!r||!r.filter(f=>f).length)return e;let t;Array.isArray(r)&&Number.isInteger(r[0])&&Number.isInteger(r[1])?t=[Array.from(r)]:t=Array.from(r);let l=t.length,u=0;t.filter(f=>f).forEach((f,g)=>{if(s&&(n=Math.floor(u/l*10),n!==a&&(a=n,s(n))),!Array.isArray(f))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${g}th element not an array: ${JSON.stringify(f,null,4)}, which is ${typeof f}`);if(!Number.isInteger(f[0])){if(!Number.isInteger(+f[0])||+f[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${g}th element, array ${JSON.stringify(f,null,0)}. Its first element is not an integer, string index, but ${typeof f[0]}, equal to: ${JSON.stringify(f[0],null,4)}.`);t[g][0]=+t[g][0]}if(!Number.isInteger(f[1])){if(!Number.isInteger(+f[1])||+f[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${g}th element, array ${JSON.stringify(f,null,0)}. Its second element is not an integer, string index, but ${typeof f[1]}, equal to: ${JSON.stringify(f[1],null,4)}.`);t[g][1]=+t[g][1]}u+=1});let i=se(t,{progressFn:f=>{s&&(n=10+Math.floor(f/10),n!==a&&(a=n,s(n)))}});oe(i);let o=i.length;if(o>0){let f=e.slice(i[o-1][1]);e=i.reduce((g,y,m,d)=>{s&&(n=20+Math.floor(m/o*80),n!==a&&(a=n,s(n)));let O=m===0?0:d[m-1][1],F=d[m][0];return`${g}${e.slice(O,F)}${d[m][2]||""}`},""),e+=f}return e}function _(e,r=1){let s="\xA0";function n(t){return Array.from(t).reverse().join("")}function a(t,l,u){let i=u?`
|
|
12
12
|
`:"\r",o=u?"\r":`
|
|
13
|
-
`;if(!
|
|
14
|
-
`.includes(
|
|
15
|
-
${JSON.stringify(
|
|
16
|
-
${JSON.stringify(s,null,4)}`);if(E(this.ranges)&&Array.isArray(this.last())&&n===this.last()[1]){if(this.last()[1]=a,this.last()[2],this.last()[2]!==null&&E(s)){let
|
|
17
|
-
${JSON.stringify(e,null,4)}`);if(
|
|
18
|
-
${JSON.stringify(
|
|
19
|
-
${JSON.stringify(
|
|
20
|
-
`||e[o]==="\r"){if(!n){if(n=o,!l&&e[o-1]!=='"'){let g=e.slice(s,o);g.trim()!==""&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:i.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:i.padSingleDecimalPlaceNumbers,forceUKStyle:i.forceUKStyle}))}u?a.length=0:
|
|
21
|
-
${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:
|
|
13
|
+
`;if(!t)return t;let f=0,g=0,y="";for(let m=0,d=t.length;m<d;m++)(t[m]===i||t[m]===o&&t[m-1]!==i)&&g++,`\r
|
|
14
|
+
`.includes(t[m])||t[m]===s?(f=0,t[m]===s?y+=t[m]:t[m]===i?g<=l&&(y+=t[m],t[m+1]===o&&(y+=t[m+1],m++)):t[m]===o&&(!t[m-1]||t[m-1]!==i)&&g<=l&&(y+=t[m])):(f++,!t[m+1]&&!g&&(y+=" "));return y}if(typeof e=="string"&&e.length){let t=1;typeof+r=="number"&&Number.isInteger(+r)&&+r>=0&&(t=+r);let l="",u="";if(!e.trim())l=e;else if(!e[0].trim()){for(let i=0,o=e.length;i<o;i++)if(e[i].trim()){l=e.slice(0,i);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===s)){for(let i=e.length;i--;)if(e[i].trim()){u=e.slice(i+1);break}}return`${a(l,t,!1)}${e.trim()}${n(a(n(u),t,!0))}`}return e}var et={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function le(e,r){if(!Array.isArray(e)||!e.length)return e;let s=b(b({},et),r),n,a;if(s.strictlyTwoElementsInRangeArrays&&!e.every((u,i)=>!Array.isArray(u)||u.length!==2?(n=i,a=u.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${a} elements!`);if(!e.every((u,i)=>!Array.isArray(u)||!Number.isInteger(u[0])||u[0]<0||!Number.isInteger(u[1])||u[1]<0?(n=i,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let t=e.length**2,l=0;return Array.from(e).sort((u,i)=>(s.progressFn&&(l+=1,s.progressFn(Math.floor(l*100/t))),u[0]===i[0]?u[1]<i[1]?-1:u[1]>i[1]?1:0:u[0]<i[0]?-1:1))}var ae={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function tt(e,r){function s(o){return o&&typeof o=="object"&&!Array.isArray(o)}if(!Array.isArray(e)||!e.length)return null;let n;if(r)if(s(r)){if(n=b(b({},ae),r),n.progressFn&&s(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof n.progressFn}", equal to ${JSON.stringify(n.progressFn,null,4)}`);if(![1,2,"1","2"].includes(n.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof n.mergeType}", equal to ${JSON.stringify(n.mergeType,null,4)}`);if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof n.joinRangesThatTouchEdges}", equal to ${JSON.stringify(n.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
|
|
15
|
+
${JSON.stringify(r,null,4)} (type ${typeof r})`);else n=b({},ae);let a=e.filter(o=>Array.isArray(o)).map(o=>[...o]).filter(o=>o[2]!==void 0||o[0]!==o[1]),t,l,u;n.progressFn?t=le(a,{progressFn:o=>{u=Math.floor(o/5),u!==l&&(l=u,n.progressFn(u))}}):t=le(a);let i=t.length-1;for(let o=i;o>0;o--)n.progressFn&&(u=Math.floor((1-o/i)*78)+21,u!==l&&u>l&&(l=u,n.progressFn(u))),(t[o][0]<=t[o-1][0]||!n.joinRangesThatTouchEdges&&t[o][0]<t[o-1][1]||n.joinRangesThatTouchEdges&&t[o][0]<=t[o-1][1])&&(t[o-1][0]=Math.min(t[o][0],t[o-1][0]),t[o-1][1]=Math.max(t[o][1],t[o-1][1]),t[o][2]!==void 0&&(t[o-1][0]>=t[o][0]||t[o-1][1]<=t[o][1])&&t[o-1][2]!==null&&(t[o][2]===null&&t[o-1][2]!==null?t[o-1][2]=null:t[o-1][2]!=null?+n.mergeType==2&&t[o-1][0]===t[o][0]?t[o-1][2]=t[o][2]:t[o-1][2]+=t[o][2]:t[o-1][2]=t[o][2]),t.splice(o,1),o=t.length);return t.length?t:null}function E(e){return e!=null}function D(e){return Number.isInteger(e)&&e>=0}function V(e){return typeof e=="string"}var rt={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},ue=class{constructor(e){H(this,"ranges");H(this,"opts");let r=b(b({},rt),e);if(r.mergeType&&r.mergeType!==1&&r.mergeType!==2)if(V(r.mergeType)&&r.mergeType.trim()==="1")r.mergeType=1;else if(V(r.mergeType)&&r.mergeType.trim()==="2")r.mergeType=2;else throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof r.mergeType}", equal to ${JSON.stringify(r.mergeType,null,4)}`);this.opts=r,this.ranges=[]}add(e,r,s){if(e==null&&r==null)return;if(E(e)&&!E(r)){if(Array.isArray(e)){if(e.length){if(e.some(t=>Array.isArray(t))){e.forEach(t=>{Array.isArray(t)&&this.add(...t)});return}e.length&&D(+e[0])&&D(+e[1])&&this.add(...e)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(e,null,0)}) but second-one, "to" is not (${JSON.stringify(r,null,0)})`)}else if(!E(e)&&E(r))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(r,null,0)}) but first-one, "from" is not (${JSON.stringify(e,null,0)})`);let n=+e,a=+r;if(D(s)&&(s=String(s)),D(n)&&D(a)){if(E(s)&&!V(s)&&!D(s))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof s}, equal to:
|
|
16
|
+
${JSON.stringify(s,null,4)}`);if(E(this.ranges)&&Array.isArray(this.last())&&n===this.last()[1]){if(this.last()[1]=a,this.last()[2],this.last()[2]!==null&&E(s)){let t=this.last()[2]&&this.last()[2].length>0&&(!this.opts||!this.opts.mergeType||this.opts.mergeType===1)?`${this.last()[2]}${s}`:s;this.opts.limitToBeAddedWhitespace&&(t=_(t,this.opts.limitLinebreaksCount)),V(t)&&!t.length||(this.last()[2]=t)}}else{this.ranges||(this.ranges=[]);let t=s!==void 0&&!(V(s)&&!s.length)?[n,a,s&&this.opts.limitToBeAddedWhitespace?_(s,this.opts.limitLinebreaksCount):s]:[n,a];this.ranges.push(t)}}else throw D(n)&&n>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof a}" equal to: ${JSON.stringify(a,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof n}" equal to: ${JSON.stringify(n,null,4)}`)}push(e,r,s){this.add(e,r,s)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=tt(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>E(e[2])?[e[0],e[1],_(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&D(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var Ee=k(Oe(),1);function C(e,r){let s=!0,n=[".",",","'"," "],a;if(typeof e!="string")throw new TypeError(`string-remove-thousand-separators/remSep(): [THROW_ID_01] Input must be string! Currently it's: ${typeof e}, equal to:
|
|
17
|
+
${JSON.stringify(e,null,4)}`);if(r&&typeof r!="object")throw new TypeError(`string-remove-thousand-separators/remSep(): [THROW_ID_02] Options object must be a plain object! Currently it's: ${typeof r}, equal to:
|
|
18
|
+
${JSON.stringify(r,null,4)}`);let t=b({removeThousandSeparatorsFromNumbers:!0,padSingleDecimalPlaceNumbers:!0,forceUKStyle:!1},r),l=(0,Ee.default)(e.trim(),'"');if(l==="")return l;let u=new ue;for(let i=0,o=l.length;i<o;i++){if(t.removeThousandSeparatorsFromNumbers&&l[i].trim()===""&&u.add(i,i+1),t.removeThousandSeparatorsFromNumbers&&l[i]==="'"&&(u.add(i,i+1),l[i+1]==="'")){s=!1;break}if(n.includes(l[i])){if(l[i+1]!==void 0&&/^\d*$/.test(l[i+1]))if(l[i+2]!==void 0)if(/^\d*$/.test(l[i+2]))if(l[i+3]!==void 0)if(/^\d*$/.test(l[i+3])){if(l[i+4]!==void 0&&/^\d*$/.test(l[i+4])){s=!1;break}else if(t.removeThousandSeparatorsFromNumbers&&u.add(i,i+1),!a)a=l[i];else if(l[i]!==a){s=!1;break}}else{s=!1;break}else t.removeThousandSeparatorsFromNumbers&&t.forceUKStyle&&l[i]===","&&u.add(i,i+1,".");else{s=!1;break}else t.forceUKStyle&&l[i]===","&&u.add(i,i+1,"."),t.padSingleDecimalPlaceNumbers&&u.add(i+2,i+2,"0")}else if(!/^\d*$/.test(l[i])){s=!1;break}}return s&&u.current()?ie(l,u.current()):l}var xt={removeThousandSeparatorsFromNumbers:!0,padSingleDecimalPlaceNumbers:!0,forceUKStyle:!1};function De(e,r){let s=0,n=0,a=[],t=[],l=!1,u=!0;if(r&&typeof r!="object")throw new Error(`csv-split-easy/split(): [THROW_ID_02] Options object must be a plain object! Currently it's of a type ${typeof r} equal to:
|
|
19
|
+
${JSON.stringify(r,null,4)}`);let i=b(b({},xt),r);if(typeof e!="string")throw new TypeError(`csv-split-easy/split(): [THROW_ID_04] input must be string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(e==="")return[[""]];e=e.trim();for(let o=0,f=e.length;o<f;o++){if(u&&e[o]!=='"'&&e[o]!==","&&e[o].trim()!==""&&(u=!1),e[o]==='"')if(l&&e[o+1]==='"')o+=1;else if(l){l=!1;let g=e.slice(s,o);g.trim()!==""&&(u=!1);let y=/""/.test(g)?g.replace(/""/g,'"'):C(g,{removeThousandSeparatorsFromNumbers:i.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:i.padSingleDecimalPlaceNumbers,forceUKStyle:i.forceUKStyle});a.push(y)}else l=!0,s=o+1;else if(!l&&e[o]===","){if(e[o-1]!=='"'&&!l){let g=e.slice(s,o);g.trim()!==""&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:i.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:i.padSingleDecimalPlaceNumbers,forceUKStyle:i.forceUKStyle}))}s=o+1,n&&(n=0)}else if(e[o]===`
|
|
20
|
+
`||e[o]==="\r"){if(!n){if(n=o,!l&&e[o-1]!=='"'){let g=e.slice(s,o);g.trim()!==""&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:i.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:i.padSingleDecimalPlaceNumbers,forceUKStyle:i.forceUKStyle}))}u?a.length=0:t.push(a),u=!0,a=[]}s=o+1}else n&&(n=0,s=o);if(o+1===f){if(e[o]!=='"'){let g=e.slice(s,o+1);g.trim()&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:i.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:i.padSingleDecimalPlaceNumbers,forceUKStyle:i.forceUKStyle}))}u?a=[]:t.push(a),u=!0}}return t.length===0?[[""]]:t}var A=k(Ie(),1);function j(e){return typeof e=="number"&&!isNaN(e)?!0:(e=(e||"").toString().trim(),e?!isNaN(+e):!1)}var Vt=["\u062F.\u0625","\u060B","L","\u058F","\u0192","Kz","$","\u0192","\u20BC","KM","\u09F3","\u043B\u0432",".\u062F.\u0628","FBu","$b","R$","\u0E3F","Nu.","P","p.","BZ$","FC","CHF","\xA5","\u20A1","\u20B1","K\u010D","Fdj","kr","RD$","\u062F\u062C","kr","Nfk","Br","\u039E","\u20AC","\u20BE","\u20B5","GH\u20B5","D","FG","Q","L","kn","G","Ft","Rp","\u20AA","\u20B9","\u0639.\u062F","\uFDFC","kr","J$","JD","\xA5","KSh","\u043B\u0432","\u17DB","CF","\u20A9","\u20A9","KD","\u043B\u0432","\u20AD","\u20A8","M","\u0141","Lt","Ls","LD","MAD","lei","Ar","\u0434\u0435\u043D","K","\u20AE","MOP$","UM","\u20A8","Rf","MK","RM","MT","\u20A6","C$","kr","\u20A8","\uFDFC","B/.","S/.","K","\u20B1","\u20A8","z\u0142","Gs","\uFDFC","\uFFE5","lei","\u0414\u0438\u043D.","\u20BD","R\u20A3","\uFDFC","\u20A8","\u062C.\u0633.","kr","\xA3","Le","S","Db","E","\u0E3F","SM","T","\u062F.\u062A","T$","\u20A4","\u20BA","TT$","NT$","TSh","\u20B4","USh","$U","\u043B\u0432","Bs","\u20AB","VT","WS$","FCFA","\u0243","CFA","\u20A3","\uFDFC","R","Z$"];function w(e){return j(e)||Vt.some(r=>j(e.replace(r,"").replace(/[,.]/g,"")))?"numeric":e.trim()?"text":"empty"}var Ae="6.0.11";var Ft=Ae;function _t(e){let r=null,s=null;if(typeof e!="string")throw new TypeError(`csv-sort/csvSort(): [THROW_ID_01] The input is of a wrong type! We accept either string of array of arrays. We got instead: ${typeof e}, equal to:
|
|
21
|
+
${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:r,msgType:s};let n=De(e),a=[],t=!1,l=!0,u=[],i=null;for(let p=n.length-1;p>=0;p--)if(a.length){p===0&&(t=n[p].every(h=>w(h)==="text"||w(h)==="empty")),!t&&a.length!==n[p].length&&(l=!1);let c=null;for(let h=0,S=n[p].length;h<S;h++)if(c===null&&w(n[p][h].trim())==="empty"&&(c=h),c!==null&&w(n[p][h].trim())!=="empty"&&(c=null),w(n[p][h].trim())!==a[h]&&!t){let T=w(n[p][h].trim());if(Array.isArray(a[h]))a[h].includes(T)||a[h].push(w(n[p][h].trim()));else if(a[h]!==T){let $=a[h];a[h]=[],a[h].push($),a[h].push(T)}}i!==null&&c!==null&&c>i&&(!t||t&&p!==0)&&(i=c)}else if(n[p].length!==1||n[p][0]!=="")for(let c=0,h=n[p].length;c<h;c++)a.push(w(n[p][c].trim())),i===null&&w(n[p][c].trim())==="empty"&&(i=c),i!==null&&w(n[p][c].trim())!=="empty"&&(i=null);i||(i=a.length);let o=0;for(let p=0,c=a.length;p<c&&a[p]==="empty";p++)o=p;o!==0&&(n=n.map(p=>p.slice(o+1,i)),a=a.slice(o+1,i));let f=[],g;a.forEach((p,c)=>{p==="numeric"&&f.push(c)});let y=t?1:0;if(f.length===1)g=f[0];else{if(f.length===0)throw new Error('csv-sort/csvSort(): [THROW_ID_03] Your CSV file does not contain numeric-only columns and computer was not able to detect the "Balance" column!');{let p=Array.from(f),c=[];for(let h=0,S=p.length;h<S;h++){let T=p[h],$,R=!0,I,N=!0;for(let v=y,xe=n.length;v<xe&&(R&&($==null?$=n[v][T]:$===n[v][T]?(c.push(T),R=!1):$=n[v][T]),N&&(I==null?I=n[v][T]:n[v][T]!==I&&(N=!1)),!!R);v++);N&&u.push(T)}if(p=(0,G.default)(p,...c),p.length===1)g=p[0];else if(p.length===0)throw new Error(`csv-sort/csvSort(): [THROW_ID_04] The computer can't find the "Balance" column! It saw some numeric-only columns, but they all seem to have certain rows with the same values as rows right below/above them!`)}}if(!g)throw new Error("csv-sort/csvSort(): [THROW_ID_05] Sadly computer couldn't find its way in this CSV and had to stop working on it.");let m=(0,G.default)(Array.from(a.reduce((p,c,h)=>((typeof c=="string"&&c==="numeric"||Array.isArray(c)&&c.includes("numeric"))&&p.push(h),p),[])),g,...u),d=[];d.push(n[n.length-1].slice(0,i));let O=[],F=t?1:0;for(let p=n.length-2;p>=F;p--)for(let c=n.length-2;c>=F;c--)if(!O.includes(c)){let h=!1;for(let S=0,T=m.length;S<T;S++){let $=null;n[c][m[S]]!==""&&($=(0,A.default)(n[c][m[S]]));let R=null;n[c][g]!==""&&(R=(0,A.default)(n[c][g]));let I=null;d[0][g]!==""&&(I=(0,A.default)(d[0][g]).format());let N=null;d[d.length-1][m[S]]!==""&&(N=(0,A.default)(d[d.length-1][m[S]]).format());let v=null;if(d[d.length-1][g]!==""&&(v=(0,A.default)(d[d.length-1][g])),$&&R.add($).format()===I){d.unshift(n[c].slice(0,i)),O.push(c),h=!0;break}else if($&&R.subtract($).format()===I){d.unshift(n[c].slice(0,i)),O.push(c),h=!0;break}else if(N&&v.add(N).format()===R.format()){d.push(n[c].slice(0,i)),O.push(c),h=!0;break}else if(N&&v.subtract(N).format()===R.format()){d.push(n[c].slice(0,i)),O.push(c),h=!0;break}}if(h){h=!1;break}}return t&&(l&&n[0].length>a.length&&(n[0].length=a.length),d.unshift(n[0].slice(0,i))),n.length-(t?2:1)!==O.length&&(r="Not all rows were recognised!",s="alert"),{res:d,msgContent:r,msgType:s}}return Je(jt);})();
|
|
22
22
|
/**
|
|
23
23
|
* @name csv-split-easy
|
|
24
24
|
* @fileoverview Splits the CSV string into array of arrays, each representing a row of columns
|
|
25
|
-
* @version 6.0.
|
|
25
|
+
* @version 6.0.11
|
|
26
26
|
* @author Roy Revelt, Codsen Ltd
|
|
27
27
|
* @license MIT
|
|
28
28
|
* {@link https://codsen.com/os/csv-split-easy/}
|
|
@@ -30,7 +30,7 @@ ${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:t,msgTyp
|
|
|
30
30
|
/**
|
|
31
31
|
* @name ranges-apply
|
|
32
32
|
* @fileoverview Take an array of string index ranges, delete/replace the string according to them
|
|
33
|
-
* @version 6.0.
|
|
33
|
+
* @version 6.0.11
|
|
34
34
|
* @author Roy Revelt, Codsen Ltd
|
|
35
35
|
* @license MIT
|
|
36
36
|
* {@link https://codsen.com/os/ranges-apply/}
|
|
@@ -38,7 +38,7 @@ ${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:t,msgTyp
|
|
|
38
38
|
/**
|
|
39
39
|
* @name ranges-merge
|
|
40
40
|
* @fileoverview Merge and sort string index ranges
|
|
41
|
-
* @version 8.0.
|
|
41
|
+
* @version 8.0.11
|
|
42
42
|
* @author Roy Revelt, Codsen Ltd
|
|
43
43
|
* @license MIT
|
|
44
44
|
* {@link https://codsen.com/os/ranges-merge/}
|
|
@@ -46,7 +46,7 @@ ${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:t,msgTyp
|
|
|
46
46
|
/**
|
|
47
47
|
* @name ranges-push
|
|
48
48
|
* @fileoverview Gather string index ranges
|
|
49
|
-
* @version 6.0.
|
|
49
|
+
* @version 6.0.11
|
|
50
50
|
* @author Roy Revelt, Codsen Ltd
|
|
51
51
|
* @license MIT
|
|
52
52
|
* {@link https://codsen.com/os/ranges-push/}
|
|
@@ -54,7 +54,7 @@ ${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:t,msgTyp
|
|
|
54
54
|
/**
|
|
55
55
|
* @name ranges-sort
|
|
56
56
|
* @fileoverview Sort string index ranges
|
|
57
|
-
* @version 5.0.
|
|
57
|
+
* @version 5.0.11
|
|
58
58
|
* @author Roy Revelt, Codsen Ltd
|
|
59
59
|
* @license MIT
|
|
60
60
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
@@ -62,7 +62,7 @@ ${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:t,msgTyp
|
|
|
62
62
|
/**
|
|
63
63
|
* @name string-collapse-leading-whitespace
|
|
64
64
|
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
65
|
-
* @version 6.0.
|
|
65
|
+
* @version 6.0.11
|
|
66
66
|
* @author Roy Revelt, Codsen Ltd
|
|
67
67
|
* @license MIT
|
|
68
68
|
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
@@ -70,7 +70,7 @@ ${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:t,msgTyp
|
|
|
70
70
|
/**
|
|
71
71
|
* @name string-remove-thousand-separators
|
|
72
72
|
* @fileoverview Detects and removes thousand separators (dot/comma/quote/space) from string-type digits
|
|
73
|
-
* @version 6.0.
|
|
73
|
+
* @version 6.0.11
|
|
74
74
|
* @author Roy Revelt, Codsen Ltd
|
|
75
75
|
* @license MIT
|
|
76
76
|
* {@link https://codsen.com/os/string-remove-thousand-separators/}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv-sort",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.11",
|
|
4
4
|
"description": "Sorts double-entry bookkeeping CSV coming from internet banking",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accountancy",
|
|
@@ -40,13 +40,15 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
42
42
|
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
43
|
-
"dts": "rollup -c",
|
|
43
|
+
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
|
|
44
44
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
45
45
|
"lect": "node '../../ops/lect/lect.js'",
|
|
46
46
|
"letspublish": "yarn publish || :",
|
|
47
47
|
"lint": "eslint . --fix",
|
|
48
48
|
"perf": "node perf/check.js",
|
|
49
49
|
"prepare": "echo 'ready'",
|
|
50
|
+
"prettier": "prettier",
|
|
51
|
+
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
|
|
50
52
|
"pretest": "yarn run lect && yarn run build",
|
|
51
53
|
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
52
54
|
"unit": "uvu test"
|
|
@@ -70,7 +72,7 @@
|
|
|
70
72
|
}
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
|
-
"csv-split-easy": "^6.0.
|
|
75
|
+
"csv-split-easy": "^6.0.11",
|
|
74
76
|
"currency.js": "^2.0.4",
|
|
75
77
|
"lodash.pull": "^4.1.0"
|
|
76
78
|
},
|
package/types/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ declare function findType(something: string): string;
|
|
|
3
3
|
|
|
4
4
|
declare const version: string;
|
|
5
5
|
interface Res {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
res: string[][];
|
|
7
|
+
msgContent: null | string;
|
|
8
|
+
msgType: null | string;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Sorts double-entry bookkeeping CSV coming from internet banking
|