@thi.ng/csv 2.3.86 → 2.3.87
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 +7 -1
- package/README.md +12 -1
- package/package.json +10 -10
- package/parse.js +12 -12
- package/transforms.d.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [2.3.87](https://github.com/thi-ng/umbrella/tree/@thi.ng/csv@2.3.87) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
### [2.3.81](https://github.com/thi-ng/umbrella/tree/@thi.ng/csv@2.3.81) (2024-04-08)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
- [Planned features](#planned-features)
|
|
21
21
|
- [Installation](#installation)
|
|
22
22
|
- [Dependencies](#dependencies)
|
|
23
|
+
- [Usage examples](#usage-examples)
|
|
23
24
|
- [API](#api)
|
|
24
25
|
- [Authors](#authors)
|
|
25
26
|
- [License](#license)
|
|
@@ -95,6 +96,16 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.53 KB
|
|
|
95
96
|
- [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
|
|
96
97
|
- [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
|
|
97
98
|
|
|
99
|
+
## Usage examples
|
|
100
|
+
|
|
101
|
+
One project in this repo's
|
|
102
|
+
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
|
|
103
|
+
directory is using this package:
|
|
104
|
+
|
|
105
|
+
| Screenshot | Description | Live demo | Source |
|
|
106
|
+
|:-------------------------------------------------------------------------------------------------------------------------|:-----------------------------------|:--------------------------------------------------------|:-------------------------------------------------------------------------------------|
|
|
107
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-csv-piechart.png" width="240"/> | Piechart visualization of CSV data | [Demo](https://demo.thi.ng/umbrella/geom-csv-piechart/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-csv-piechart) |
|
|
108
|
+
|
|
98
109
|
## API
|
|
99
110
|
|
|
100
111
|
[Generated API docs](https://docs.thi.ng/umbrella/csv/)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/csv",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.87",
|
|
4
4
|
"description": "Customizable, transducer-based CSV parser/object mapper and transformer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/csv",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
41
|
-
"@thi.ng/strings": "^3.7.
|
|
42
|
-
"@thi.ng/transducers": "^9.0.
|
|
39
|
+
"@thi.ng/api": "^8.11.3",
|
|
40
|
+
"@thi.ng/checks": "^3.6.5",
|
|
41
|
+
"@thi.ng/strings": "^3.7.34",
|
|
42
|
+
"@thi.ng/transducers": "^9.0.6"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.
|
|
46
|
-
"esbuild": "^0.21.
|
|
45
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
46
|
+
"esbuild": "^0.21.5",
|
|
47
47
|
"typedoc": "^0.25.13",
|
|
48
|
-
"typescript": "^5.
|
|
48
|
+
"typescript": "^5.5.2"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"csv",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"thi.ng": {
|
|
86
86
|
"year": 2014
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
89
89
|
}
|
package/parse.js
CHANGED
|
@@ -32,8 +32,8 @@ function parseCSV(opts, src) {
|
|
|
32
32
|
let isQuoted = false;
|
|
33
33
|
let record = [];
|
|
34
34
|
const init = (header2) => {
|
|
35
|
-
cols && (index =
|
|
36
|
-
all && (revIndex =
|
|
35
|
+
cols && (index = __initIndex(header2, cols));
|
|
36
|
+
all && (revIndex = __initRevIndex(header2));
|
|
37
37
|
first = false;
|
|
38
38
|
};
|
|
39
39
|
const collectAll = (row) => record.reduce(
|
|
@@ -54,7 +54,7 @@ function parseCSV(opts, src) {
|
|
|
54
54
|
if ((!line.length || line.startsWith(comment)) && !isQuoted)
|
|
55
55
|
return acc;
|
|
56
56
|
if (!first) {
|
|
57
|
-
isQuoted =
|
|
57
|
+
isQuoted = __parseLine(
|
|
58
58
|
line,
|
|
59
59
|
record,
|
|
60
60
|
isQuoted,
|
|
@@ -68,7 +68,7 @@ function parseCSV(opts, src) {
|
|
|
68
68
|
record = [];
|
|
69
69
|
return reduce(acc, row);
|
|
70
70
|
} else {
|
|
71
|
-
isQuoted =
|
|
71
|
+
isQuoted = __parseLine(
|
|
72
72
|
line,
|
|
73
73
|
record,
|
|
74
74
|
isQuoted,
|
|
@@ -115,7 +115,7 @@ function parseCSVSimple(opts, src) {
|
|
|
115
115
|
if ((!line.length || line.startsWith(comment)) && !isQuoted)
|
|
116
116
|
return acc;
|
|
117
117
|
if (!first) {
|
|
118
|
-
isQuoted =
|
|
118
|
+
isQuoted = __parseLine(
|
|
119
119
|
line,
|
|
120
120
|
record,
|
|
121
121
|
isQuoted,
|
|
@@ -127,7 +127,7 @@ function parseCSVSimple(opts, src) {
|
|
|
127
127
|
record = [];
|
|
128
128
|
return reduce(acc, row);
|
|
129
129
|
} else {
|
|
130
|
-
isQuoted =
|
|
130
|
+
isQuoted = __parseLine(
|
|
131
131
|
line,
|
|
132
132
|
record,
|
|
133
133
|
isQuoted,
|
|
@@ -143,7 +143,7 @@ function parseCSVSimple(opts, src) {
|
|
|
143
143
|
}
|
|
144
144
|
const parseCSVFromString = (opts, src) => parseCSV(opts, split(src));
|
|
145
145
|
const parseCSVSimpleFromString = (opts, src) => parseCSVSimple(opts, split(src));
|
|
146
|
-
const
|
|
146
|
+
const __parseLine = (line, acc, isQuoted, delim, quote) => {
|
|
147
147
|
let curr = "";
|
|
148
148
|
let p = "";
|
|
149
149
|
let openQuote = isQuoted;
|
|
@@ -162,7 +162,7 @@ const parseLine = (line, acc, isQuoted, delim, quote) => {
|
|
|
162
162
|
continue;
|
|
163
163
|
} else if (line[i + 1] !== quote) isQuoted = false;
|
|
164
164
|
} else if (!isQuoted && c === delim) {
|
|
165
|
-
|
|
165
|
+
__collectCell(acc, curr, openQuote);
|
|
166
166
|
openQuote = false;
|
|
167
167
|
curr = "";
|
|
168
168
|
} else if (c !== "\\") {
|
|
@@ -170,11 +170,11 @@ const parseLine = (line, acc, isQuoted, delim, quote) => {
|
|
|
170
170
|
}
|
|
171
171
|
p = c;
|
|
172
172
|
}
|
|
173
|
-
curr !== "" &&
|
|
173
|
+
curr !== "" && __collectCell(acc, curr, openQuote);
|
|
174
174
|
return isQuoted;
|
|
175
175
|
};
|
|
176
|
-
const
|
|
177
|
-
const
|
|
176
|
+
const __collectCell = (acc, curr, openQuote) => openQuote ? acc[acc.length - 1] += "\n" + curr : acc.push(curr);
|
|
177
|
+
const __initIndex = (line, cols) => isArray(cols) ? cols.reduce((acc, spec, i) => {
|
|
178
178
|
if (spec) {
|
|
179
179
|
const alias = spec.alias || line[i] || String(i);
|
|
180
180
|
acc[alias] = { i, spec: { alias, ...spec } };
|
|
@@ -184,7 +184,7 @@ const initIndex = (line, cols) => isArray(cols) ? cols.reduce((acc, spec, i) =>
|
|
|
184
184
|
(acc, id, i) => cols[id] ? (acc[id] = { i, spec: cols[id] }, acc) : acc,
|
|
185
185
|
{}
|
|
186
186
|
);
|
|
187
|
-
const
|
|
187
|
+
const __initRevIndex = (line) => line.reduce((acc, x, i) => (acc[i] = x, acc), {});
|
|
188
188
|
export {
|
|
189
189
|
parseCSV,
|
|
190
190
|
parseCSVFromString,
|
package/transforms.d.ts
CHANGED
|
@@ -64,11 +64,11 @@ export declare const url: CellTransform;
|
|
|
64
64
|
* @param defaultVal
|
|
65
65
|
*/
|
|
66
66
|
export declare const oneOf: <T>(mappings: IObjectOf<T>, defaultVal: T) => CellTransform;
|
|
67
|
-
export declare const zeroPad: (digits: number) => (x: any, length?: number
|
|
67
|
+
export declare const zeroPad: (digits: number) => (x: any, length?: number) => string;
|
|
68
68
|
export declare const formatFloat: (prec?: number) => (x: number) => string;
|
|
69
69
|
/**
|
|
70
70
|
* Higher order cell value formatter. Takes normalized values and formats them
|
|
71
71
|
* as percentage with given `precision` (number of fractional digits).
|
|
72
72
|
*/
|
|
73
|
-
export declare const formatPercent: (prec?: number
|
|
73
|
+
export declare const formatPercent: (prec?: number) => import("@thi.ng/strings").Stringer<number>;
|
|
74
74
|
//# sourceMappingURL=transforms.d.ts.map
|