csv-sort 6.1.9 → 6.1.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/CHANGELOG.md +3 -3
- package/README.md +13 -16
- package/dist/csv-sort.esm.js +2 -2
- package/dist/csv-sort.umd.js +9 -9
- package/package.json +3 -3
- package/examples/_quickTake.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -17,7 +17,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
17
17
|
|
|
18
18
|
### BREAKING CHANGES
|
|
19
19
|
|
|
20
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
20
|
+
- programs now are in ES Modules and won't work with Common JS `require()`
|
|
21
21
|
|
|
22
22
|
## 5.1.0 (2021-05-24)
|
|
23
23
|
|
|
@@ -35,7 +35,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
35
35
|
|
|
36
36
|
### Fixed
|
|
37
37
|
|
|
38
|
-
- add testStats to npmignore ([f3c84e9](https://github.com/codsen/codsen/commit/f3c84e95afc5514214312f913692d85b2e12eb29))
|
|
38
|
+
- add `testStats` to npmignore ([f3c84e9](https://github.com/codsen/codsen/commit/f3c84e95afc5514214312f913692d85b2e12eb29))
|
|
39
39
|
|
|
40
40
|
## 5.0.0 (2021-01-23)
|
|
41
41
|
|
|
@@ -49,7 +49,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
49
49
|
|
|
50
50
|
## 4.0.0 (2020-11-28)
|
|
51
51
|
|
|
52
|
-
Accidental version bump during migration to
|
|
52
|
+
Accidental version bump during migration to SourceHut. Sorry about that.
|
|
53
53
|
|
|
54
54
|
## 3.1.0 (2020-09-27)
|
|
55
55
|
|
package/README.md
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">csv-sort</h1>
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
<p align="center">Sort double-entry bookkeeping CSV from internet banking</p>
|
|
4
4
|
|
|
5
|
-
<
|
|
6
|
-
<a href="https://www.npmjs.com/package/csv-sort" rel="nofollow noreferrer noopener">
|
|
7
|
-
<img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm">
|
|
8
|
-
</a>
|
|
5
|
+
<p align="center">
|
|
9
6
|
<a href="https://codsen.com/os/csv-sort" rel="nofollow noreferrer noopener">
|
|
10
7
|
<img src="https://img.shields.io/badge/-codsen-blue?style=flat-square" alt="page on codsen.com">
|
|
11
8
|
</a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/csv-sort" rel="nofollow noreferrer noopener">
|
|
10
|
+
<img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm">
|
|
11
|
+
</a>
|
|
12
12
|
<a href="https://github.com/codsen/codsen/tree/main/packages/csv-sort" rel="nofollow noreferrer noopener">
|
|
13
13
|
<img src="https://img.shields.io/badge/-github-blue?style=flat-square" alt="page on github">
|
|
14
14
|
</a>
|
|
15
15
|
<a href="https://npmcharts.com/compare/csv-sort?interval=30" rel="nofollow noreferrer noopener" target="_blank">
|
|
16
16
|
<img src="https://img.shields.io/npm/dm/csv-sort.svg?style=flat-square" alt="Downloads per month">
|
|
17
17
|
</a>
|
|
18
|
-
<a href="https://
|
|
19
|
-
<img src="https://img.shields.io/badge/
|
|
20
|
-
</a>
|
|
21
|
-
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT License">
|
|
22
|
-
<a href="https://liberamanifesto.com" rel="nofollow noreferrer noopener" target="_blank">
|
|
23
|
-
<img src="https://img.shields.io/badge/libera-manifesto-lightgrey.svg?style=flat-square" alt="libera manifesto">
|
|
18
|
+
<a href="https://codsen.com/os/csv-sort/changelog" rel="nofollow noreferrer noopener">
|
|
19
|
+
<img src="https://img.shields.io/badge/changelog-here-brightgreen?style=flat-square" alt="changelog">
|
|
24
20
|
</a>
|
|
25
|
-
|
|
21
|
+
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT Licence">
|
|
22
|
+
</p>
|
|
26
23
|
|
|
27
24
|
## Install
|
|
28
25
|
|
|
@@ -76,10 +73,10 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
76
73
|
|
|
77
74
|
## Licence
|
|
78
75
|
|
|
79
|
-
MIT License
|
|
76
|
+
MIT License.
|
|
80
77
|
|
|
81
|
-
Copyright
|
|
78
|
+
Copyright © 2010-2022 Roy Revelt and other contributors.
|
|
82
79
|
|
|
83
80
|
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)
|
|
84
81
|
|
|
85
|
-
<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">
|
|
82
|
+
<p align="center"><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"></p>
|
package/dist/csv-sort.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name csv-sort
|
|
3
3
|
* @fileoverview Sort double-entry bookkeeping CSV from internet banking
|
|
4
|
-
* @version 6.1.
|
|
4
|
+
* @version 6.1.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 T="6.1.
|
|
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 T="6.1.11";var K=T;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
11
|
${JSON.stringify(i,null,4)}`);if(!i.trim())return{res:[[""]],msgContent:b,msgType:C};let n=O(i),s=[],d=!1,S=!0,v=[],r=null;for(let t=n.length-1;t>=0;t--)if(s.length){t===0&&(d=n[t].every(l=>f(l)==="text"||f(l)==="empty")),!d&&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]&&!d){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)}}r!==null&&e!==null&&e>r&&(!d||d&&t!==0)&&(r=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())),r===null&&f(n[t][e].trim())==="empty"&&(r=e),r!==null&&f(n[t][e].trim())!=="empty"&&(r=null);r||(r=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,r)),s=s.slice(w+1,r));let V=[],m;s.forEach((t,e)=>{t==="numeric"&&V.push(e)});let k=d?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,g=!0,y,h=!0;for(let c=k,I=n.length;c<I&&(g&&(u==null?u=n[c][a]:u===n[c][a]?(e.push(a),g=!1):u=n[c][a]),h&&(y==null?y=n[c][a]:n[c][a]!==y&&(h=!1)),!!g);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),o=[];o.push(n[n.length-1].slice(0,r));let $=[],x=d?1:0;for(let t=n.length-2;t>=x;t--)for(let e=n.length-2;e>=x;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 g=null;n[e][m]!==""&&(g=R(n[e][m]));let y=null;o[0][m]!==""&&(y=R(o[0][m]).format());let h=null;o[o.length-1][D[p]]!==""&&(h=R(o[o.length-1][D[p]]).format());let c=null;if(o[o.length-1][m]!==""&&(c=R(o[o.length-1][m])),u&&g.add(u).format()===y){o.unshift(n[e].slice(0,r)),$.push(e),l=!0;break}else if(u&&g.subtract(u).format()===y){o.unshift(n[e].slice(0,r)),$.push(e),l=!0;break}else if(h&&c.add(h).format()===g.format()){o.push(n[e].slice(0,r)),$.push(e),l=!0;break}else if(h&&c.subtract(h).format()===g.format()){o.push(n[e].slice(0,r)),$.push(e),l=!0;break}}if(l){l=!1;break}}return d&&(S&&n[0].length>s.length&&(n[0].length=s.length),o.unshift(n[0].slice(0,r))),n.length-(d?2:1)!==$.length&&(b="Not all rows were recognised!",C="alert"),{res:o,msgContent:b,msgType:C}}export{f as findType,E as isNumeric,_ as sort,K as version};
|
package/dist/csv-sort.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name csv-sort
|
|
3
3
|
* @fileoverview Sort double-entry bookkeeping CSV from internet banking
|
|
4
|
-
* @version 6.1.
|
|
4
|
+
* @version 6.1.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/csv-sort/}
|
|
@@ -17,12 +17,12 @@ ${JSON.stringify(s,null,4)}`);if(N(this.ranges)&&Array.isArray(this.last())&&n==
|
|
|
17
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
18
|
${JSON.stringify(r,null,4)}`);let t=b(b({},At),r),i=(0,Ee.default)(e.trim(),'"');if(i==="")return i;if(+e>0&&+e<1)return e;let u=new ae;for(let l=0,o=i.length;l<o;l++){if(t.removeThousandSeparatorsFromNumbers&&i[l].trim()===""&&u.add(l,l+1),t.removeThousandSeparatorsFromNumbers&&i[l]==="'"&&(u.add(l,l+1),i[l+1]==="'")){s=!1;break}if(n.includes(i[l])){if(i[l+1]!==void 0&&/^\d$/.test(i[l+1]))if(i[l+2]!==void 0)if(/^\d$/.test(i[l+2]))if(i[l+3]!==void 0)if(/^\d$/.test(i[l+3])){if(i[l+4]!==void 0&&/^\d$/.test(i[l+4])){s=!1;break}else if(t.removeThousandSeparatorsFromNumbers&&u.add(l,l+1),!a)a=i[l];else if(i[l]!==a){s=!1;break}}else{s=!1;break}else t.removeThousandSeparatorsFromNumbers&&t.forceUKStyle&&i[l]===","&&u.add(l,l+1,".");else{s=!1;break}else t.forceUKStyle&&i[l]===","&&u.add(l,l+1,"."),t.padSingleDecimalPlaceNumbers&&u.add(l+2,l+2,"0")}else if(!/^\d$/.test(i[l])){s=!1;break}}return s&&u.current()?oe(i,u.current()):i}var xt={removeThousandSeparatorsFromNumbers:!0,padSingleDecimalPlaceNumbers:!0,forceUKStyle:!1};function Ne(e,r){let s=0,n=0,a=[],t=[],i=!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
19
|
${JSON.stringify(r,null,4)}`);let l=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(i&&e[o+1]==='"')o+=1;else if(i){i=!1;let g=e.slice(s,o);g.trim()!==""&&(u=!1);let y=/""/.test(g)?g.replace(/""/g,'"'):C(g,{removeThousandSeparatorsFromNumbers:l.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:l.padSingleDecimalPlaceNumbers,forceUKStyle:l.forceUKStyle});a.push(y)}else i=!0,s=o+1;else if(!i&&e[o]===","){if(e[o-1]!=='"'&&!i){let g=e.slice(s,o);g.trim()!==""&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:l.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:l.padSingleDecimalPlaceNumbers,forceUKStyle:l.forceUKStyle}))}s=o+1,n&&(n=0)}else if(e[o]===`
|
|
20
|
-
`||e[o]==="\r"){if(!n){if(n=o,!i&&e[o-1]!=='"'){let g=e.slice(s,o);g.trim()!==""&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:l.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:l.padSingleDecimalPlaceNumbers,forceUKStyle:l.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:l.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:l.padSingleDecimalPlaceNumbers,forceUKStyle:l.forceUKStyle}))}u?a=[]:t.push(a),u=!0}}return t.length===0?[[""]]:t}var A=k(De(),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 Ie="6.1.
|
|
20
|
+
`||e[o]==="\r"){if(!n){if(n=o,!i&&e[o-1]!=='"'){let g=e.slice(s,o);g.trim()!==""&&(u=!1),a.push(C(g,{removeThousandSeparatorsFromNumbers:l.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:l.padSingleDecimalPlaceNumbers,forceUKStyle:l.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:l.removeThousandSeparatorsFromNumbers,padSingleDecimalPlaceNumbers:l.padSingleDecimalPlaceNumbers,forceUKStyle:l.forceUKStyle}))}u?a=[]:t.push(a),u=!0}}return t.length===0?[[""]]:t}var A=k(De(),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 Ie="6.1.11";var Ft=Ie;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
21
|
${JSON.stringify(e,null,4)}`);if(!e.trim())return{res:[[""]],msgContent:r,msgType:s};let n=Ne(e),a=[],t=!1,i=!0,u=[],l=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&&(i=!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 $=w(n[p][h].trim());if(Array.isArray(a[h]))a[h].includes($)||a[h].push(w(n[p][h].trim()));else if(a[h]!==$){let T=a[h];a[h]=[],a[h].push(T),a[h].push($)}}l!==null&&c!==null&&c>l&&(!t||t&&p!==0)&&(l=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())),l===null&&w(n[p][c].trim())==="empty"&&(l=c),l!==null&&w(n[p][c].trim())!=="empty"&&(l=null);l||(l=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,l)),a=a.slice(o+1,l));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 $=p[h],T,R=!0,I,O=!0;for(let v=y,Ae=n.length;v<Ae&&(R&&(T==null?T=n[v][$]:T===n[v][$]?(c.push($),R=!1):T=n[v][$]),O&&(I==null?I=n[v][$]:n[v][$]!==I&&(O=!1)),!!R);v++);O&&u.push($)}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,l));let E=[],F=t?1:0;for(let p=n.length-2;p>=F;p--)for(let c=n.length-2;c>=F;c--)if(!E.includes(c)){let h=!1;for(let S=0,$=m.length;S<$;S++){let T=null;n[c][m[S]]!==""&&(T=(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 O=null;d[d.length-1][m[S]]!==""&&(O=(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])),T&&R.add(T).format()===I){d.unshift(n[c].slice(0,l)),E.push(c),h=!0;break}else if(T&&R.subtract(T).format()===I){d.unshift(n[c].slice(0,l)),E.push(c),h=!0;break}else if(O&&v.add(O).format()===R.format()){d.push(n[c].slice(0,l)),E.push(c),h=!0;break}else if(O&&v.subtract(O).format()===R.format()){d.push(n[c].slice(0,l)),E.push(c),h=!0;break}}if(h){h=!1;break}}return t&&(i&&n[0].length>a.length&&(n[0].length=a.length),d.unshift(n[0].slice(0,l))),n.length-(t?2:1)!==E.length&&(r="Not all rows were recognised!",s="alert"),{res:d,msgContent:r,msgType:s}}return We(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.1.
|
|
25
|
+
* @version 6.1.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:r,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.2.
|
|
33
|
+
* @version 6.2.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:r,msgTyp
|
|
|
38
38
|
/**
|
|
39
39
|
* @name ranges-merge
|
|
40
40
|
* @fileoverview Merge and sort string index ranges
|
|
41
|
-
* @version 8.2.
|
|
41
|
+
* @version 8.2.6
|
|
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:r,msgTyp
|
|
|
46
46
|
/**
|
|
47
47
|
* @name ranges-push
|
|
48
48
|
* @fileoverview Gather string index ranges
|
|
49
|
-
* @version 6.2.
|
|
49
|
+
* @version 6.2.6
|
|
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:r,msgTyp
|
|
|
54
54
|
/**
|
|
55
55
|
* @name ranges-sort
|
|
56
56
|
* @fileoverview Sort string index ranges
|
|
57
|
-
* @version 5.1.
|
|
57
|
+
* @version 5.1.5
|
|
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:r,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.1.
|
|
65
|
+
* @version 6.1.6
|
|
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:r,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.2.
|
|
73
|
+
* @version 6.2.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.1.
|
|
3
|
+
"version": "6.1.11",
|
|
4
4
|
"description": "Sort double-entry bookkeeping CSV from internet banking",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accountancy",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
47
47
|
"lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
|
|
48
48
|
"letspublish": "yarn publish || :",
|
|
49
|
-
"lint": "eslint . --fix",
|
|
49
|
+
"lint": "eslint . --ext .js --ext .ts --fix",
|
|
50
50
|
"perf": "node perf/check.js",
|
|
51
51
|
"prepare": "echo 'ready'",
|
|
52
52
|
"prettier": "prettier",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"csv-split-easy": "^6.1.
|
|
77
|
+
"csv-split-easy": "^6.1.11",
|
|
78
78
|
"currency.js": "^2.0.4",
|
|
79
79
|
"lodash.pull": "^4.1.0"
|
|
80
80
|
},
|
package/examples/_quickTake.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Quick Take
|
|
2
|
-
|
|
3
|
-
import { strict as assert } from "assert";
|
|
4
|
-
|
|
5
|
-
import { sort } from "../dist/csv-sort.esm.js";
|
|
6
|
-
|
|
7
|
-
// Sorts double-entry bookkeeping CSV's - bank statements for example
|
|
8
|
-
// see https://en.wikipedia.org/wiki/Double-entry_bookkeeping
|
|
9
|
-
|
|
10
|
-
assert.deepEqual(
|
|
11
|
-
sort(`Acc Number,Description,Debit Amount,Credit Amount,Balance,
|
|
12
|
-
123456,Client #1 payment,,1000,1940
|
|
13
|
-
123456,Bought carpet,30,,950
|
|
14
|
-
123456,Bought table,10,,940
|
|
15
|
-
123456,Bought pens,10,,1000
|
|
16
|
-
123456,Bought chairs,20,,980
|
|
17
|
-
`),
|
|
18
|
-
{
|
|
19
|
-
res: [
|
|
20
|
-
["Acc Number", "Description", "Debit Amount", "Credit Amount", "Balance"],
|
|
21
|
-
["123456", "Client #1 payment", "", "1000", "1940"],
|
|
22
|
-
["123456", "Bought table", "10", "", "940"],
|
|
23
|
-
["123456", "Bought carpet", "30", "", "950"],
|
|
24
|
-
["123456", "Bought chairs", "20", "", "980"],
|
|
25
|
-
["123456", "Bought pens", "10", "", "1000"],
|
|
26
|
-
],
|
|
27
|
-
msgContent: null,
|
|
28
|
-
msgType: null,
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
// you'll have to join elements and lines from the array yourself
|