@thi.ng/csv 2.3.85 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:17Z
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
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
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.85",
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://github.com/thi-ng/umbrella/tree/develop/packages/csv#readme",
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.1",
40
- "@thi.ng/checks": "^3.6.3",
41
- "@thi.ng/strings": "^3.7.32",
42
- "@thi.ng/transducers": "^9.0.4"
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.43.0",
46
- "esbuild": "^0.20.2",
47
- "typedoc": "^0.25.12",
48
- "typescript": "^5.4.3"
45
+ "@microsoft/api-extractor": "^7.47.0",
46
+ "esbuild": "^0.21.5",
47
+ "typedoc": "^0.25.13",
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": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
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 = initIndex(header2, cols));
36
- all && (revIndex = initRevIndex(header2));
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,22 +54,21 @@ function parseCSV(opts, src) {
54
54
  if ((!line.length || line.startsWith(comment)) && !isQuoted)
55
55
  return acc;
56
56
  if (!first) {
57
- isQuoted = parseLine(
57
+ isQuoted = __parseLine(
58
58
  line,
59
59
  record,
60
60
  isQuoted,
61
61
  delim,
62
62
  quote
63
63
  );
64
- if (isQuoted)
65
- return acc;
64
+ if (isQuoted) return acc;
66
65
  const row = {};
67
66
  all && collectAll(row);
68
67
  index && collectIndexed(row);
69
68
  record = [];
70
69
  return reduce(acc, row);
71
70
  } else {
72
- isQuoted = parseLine(
71
+ isQuoted = __parseLine(
73
72
  line,
74
73
  record,
75
74
  isQuoted,
@@ -116,20 +115,19 @@ function parseCSVSimple(opts, src) {
116
115
  if ((!line.length || line.startsWith(comment)) && !isQuoted)
117
116
  return acc;
118
117
  if (!first) {
119
- isQuoted = parseLine(
118
+ isQuoted = __parseLine(
120
119
  line,
121
120
  record,
122
121
  isQuoted,
123
122
  delim,
124
123
  quote
125
124
  );
126
- if (isQuoted)
127
- return acc;
125
+ if (isQuoted) return acc;
128
126
  const row = cols ? collect() : record;
129
127
  record = [];
130
128
  return reduce(acc, row);
131
129
  } else {
132
- isQuoted = parseLine(
130
+ isQuoted = __parseLine(
133
131
  line,
134
132
  record,
135
133
  isQuoted,
@@ -145,7 +143,7 @@ function parseCSVSimple(opts, src) {
145
143
  }
146
144
  const parseCSVFromString = (opts, src) => parseCSV(opts, split(src));
147
145
  const parseCSVSimpleFromString = (opts, src) => parseCSVSimple(opts, split(src));
148
- const parseLine = (line, acc, isQuoted, delim, quote) => {
146
+ const __parseLine = (line, acc, isQuoted, delim, quote) => {
149
147
  let curr = "";
150
148
  let p = "";
151
149
  let openQuote = isQuoted;
@@ -162,10 +160,9 @@ const parseLine = (line, acc, isQuoted, delim, quote) => {
162
160
  curr += quote;
163
161
  p = "";
164
162
  continue;
165
- } else if (line[i + 1] !== quote)
166
- isQuoted = false;
163
+ } else if (line[i + 1] !== quote) isQuoted = false;
167
164
  } else if (!isQuoted && c === delim) {
168
- collectCell(acc, curr, openQuote);
165
+ __collectCell(acc, curr, openQuote);
169
166
  openQuote = false;
170
167
  curr = "";
171
168
  } else if (c !== "\\") {
@@ -173,11 +170,11 @@ const parseLine = (line, acc, isQuoted, delim, quote) => {
173
170
  }
174
171
  p = c;
175
172
  }
176
- curr !== "" && collectCell(acc, curr, openQuote);
173
+ curr !== "" && __collectCell(acc, curr, openQuote);
177
174
  return isQuoted;
178
175
  };
179
- const collectCell = (acc, curr, openQuote) => openQuote ? acc[acc.length - 1] += "\n" + curr : acc.push(curr);
180
- const initIndex = (line, cols) => isArray(cols) ? cols.reduce((acc, spec, i) => {
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) => {
181
178
  if (spec) {
182
179
  const alias = spec.alias || line[i] || String(i);
183
180
  acc[alias] = { i, spec: { alias, ...spec } };
@@ -187,7 +184,7 @@ const initIndex = (line, cols) => isArray(cols) ? cols.reduce((acc, spec, i) =>
187
184
  (acc, id, i) => cols[id] ? (acc[id] = { i, spec: cols[id] }, acc) : acc,
188
185
  {}
189
186
  );
190
- const initRevIndex = (line) => line.reduce((acc, x, i) => (acc[i] = x, acc), {});
187
+ const __initRevIndex = (line) => line.reduce((acc, x, i) => (acc[i] = x, acc), {});
191
188
  export {
192
189
  parseCSV,
193
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 | undefined) => string;
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 | undefined) => import("@thi.ng/strings").Stringer<number>;
73
+ export declare const formatPercent: (prec?: number) => import("@thi.ng/strings").Stringer<number>;
74
74
  //# sourceMappingURL=transforms.d.ts.map
package/transforms.js CHANGED
@@ -13,8 +13,7 @@ const epoch = (defaultVal = 0) => (x) => {
13
13
  };
14
14
  const date = (defaultVal) => (x) => {
15
15
  const epoch2 = Date.parse(x);
16
- if (isNaN(epoch2))
17
- return defaultVal;
16
+ if (isNaN(epoch2)) return defaultVal;
18
17
  const res = /* @__PURE__ */ new Date();
19
18
  res.setTime(epoch2);
20
19
  return res;