@thi.ng/csv 1.0.6 → 2.0.3

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
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [1.0.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.5...@thi.ng/csv@1.0.6) (2021-08-19)
6
+ ## [2.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@2.0.2...@thi.ng/csv@2.0.3) (2021-10-15)
7
7
 
8
8
  **Note:** Version bump only for package @thi.ng/csv
9
9
 
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- ## [1.0.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.4...@thi.ng/csv@1.0.5) (2021-08-19)
14
+ ## [2.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@2.0.1...@thi.ng/csv@2.0.2) (2021-10-15)
15
15
 
16
16
  **Note:** Version bump only for package @thi.ng/csv
17
17
 
@@ -19,7 +19,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
19
19
 
20
20
 
21
21
 
22
- ## [1.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.3...@thi.ng/csv@1.0.4) (2021-08-17)
22
+ ## [2.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@2.0.0...@thi.ng/csv@2.0.1) (2021-10-13)
23
23
 
24
24
  **Note:** Version bump only for package @thi.ng/csv
25
25
 
@@ -27,80 +27,52 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
27
27
 
28
28
 
29
29
 
30
- ## [1.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.2...@thi.ng/csv@1.0.3) (2021-08-08)
31
-
32
- **Note:** Version bump only for package @thi.ng/csv
33
-
34
-
35
-
36
-
37
-
38
- ## [1.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.1...@thi.ng/csv@1.0.2) (2021-08-08)
39
-
40
- **Note:** Version bump only for package @thi.ng/csv
41
-
42
-
30
+ # [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.7...@thi.ng/csv@2.0.0) (2021-10-12)
43
31
 
44
32
 
33
+ ### Build System
45
34
 
46
- ## [1.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@0.1.30...@thi.ng/csv@1.0.1) (2021-08-08)
47
-
48
- **Note:** Version bump only for package @thi.ng/csv
49
-
50
-
51
-
52
-
53
-
54
- ## [0.1.30](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@0.1.29...@thi.ng/csv@0.1.30) (2021-08-04)
55
-
56
- **Note:** Version bump only for package @thi.ng/csv
57
-
58
-
59
-
60
-
61
-
62
- ## [0.1.29](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@0.1.28...@thi.ng/csv@0.1.29) (2021-08-04)
63
-
64
- **Note:** Version bump only for package @thi.ng/csv
65
-
66
-
67
-
68
-
69
-
70
- ## [0.1.28](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@0.1.27...@thi.ng/csv@0.1.28) (2021-07-27)
71
-
72
- **Note:** Version bump only for package @thi.ng/csv
73
-
74
-
35
+ * major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea9fab2a645d6c5f2bf2591459b939c09b6))
75
36
 
76
37
 
38
+ ### Features
77
39
 
78
- ## [0.1.27](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@0.1.26...@thi.ng/csv@0.1.27) (2021-07-01)
40
+ * **csv:** add formatCSV(), types, tests ([a2ca1b6](https://github.com/thi-ng/umbrella/commit/a2ca1b6d5cd491692a7867ad9a550767e8340588))
79
41
 
80
- **Note:** Version bump only for package @thi.ng/csv
81
42
 
43
+ ### BREAKING CHANGES
82
44
 
45
+ * discontinue CommonJS & UMD versions
83
46
 
47
+ - only ESM modules will be published from now on
48
+ - CJS obsolete due to ESM support in recent versions of node:
49
+ - i.e. launch NodeJS via:
50
+ - `node --experimental-specifier-resolution=node --experimental-repl-await`
51
+ - in the node REPL use `await import(...)` instead of `require()`
52
+ - UMD obsolete due to widespread browser support for ESM
84
53
 
54
+ Also:
55
+ - normalize/restructure/reorg all package.json files
56
+ - cleanup all build scripts, remove obsolete
57
+ - switch from mocha to @thi.ng/testament for all tests
85
58
 
86
- ## [0.1.26](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@0.1.25...@thi.ng/csv@0.1.26) (2021-06-08)
87
59
 
88
- **Note:** Version bump only for package @thi.ng/csv
89
60
 
90
61
 
91
62
 
92
63
 
64
+ ## [1.0.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/csv@1.0.6...@thi.ng/csv@1.0.7) (2021-09-03)
93
65
 
94
- # 0.1.0 (2020-11-24)
66
+ **Note:** Version bump only for package @thi.ng/csv
95
67
 
68
+ # 0.1.0 (2020-11-24)
96
69
 
97
- ### Bug Fixes
70
+ ### Bug Fixes
98
71
 
99
- * **csv:** add quoting/newline support in header fields ([28cac18](https://github.com/thi-ng/umbrella/commit/28cac1884b074d125fee747c76d3abc423cfe7ea))
72
+ - **csv:** add quoting/newline support in header fields ([28cac18](https://github.com/thi-ng/umbrella/commit/28cac1884b074d125fee747c76d3abc423cfe7ea))
100
73
 
74
+ ### Features
101
75
 
102
- ### Features
103
-
104
- * **csv:** add coercions, restructure ([93d79ec](https://github.com/thi-ng/umbrella/commit/93d79ec0b9b81ab209046bd460b5f7993359e547))
105
- * **csv:** add/update CSVOpts, cell transforms, docs ([282e85c](https://github.com/thi-ng/umbrella/commit/282e85cf9c1a9aae704d918218f8c143b51a88df))
106
- * **csv:** import as new package ([2b07100](https://github.com/thi-ng/umbrella/commit/2b07100f27bb9fb1f934901aec7c9fc1fab67fbf))
76
+ - **csv:** add coercions, restructure ([93d79ec](https://github.com/thi-ng/umbrella/commit/93d79ec0b9b81ab209046bd460b5f7993359e547))
77
+ - **csv:** add/update CSVOpts, cell transforms, docs ([282e85c](https://github.com/thi-ng/umbrella/commit/282e85cf9c1a9aae704d918218f8c143b51a88df))
78
+ - **csv:** import as new package ([2b07100](https://github.com/thi-ng/umbrella/commit/2b07100f27bb9fb1f934901aec7c9fc1fab67fbf))
package/README.md CHANGED
@@ -61,15 +61,24 @@ for more details/ideas.
61
61
  yarn add @thi.ng/csv
62
62
  ```
63
63
 
64
+ ES module import:
65
+
64
66
  ```html
65
- // ES module
66
- <script type="module" src="https://unpkg.com/@thi.ng/csv?module" crossorigin></script>
67
+ <script type="module" src="https://cdn.skypack.dev/@thi.ng/csv"></script>
68
+ ```
69
+
70
+ [Skypack documentation](https://docs.skypack.dev/)
71
+
72
+ For Node.js REPL:
73
+
74
+ ```text
75
+ # with flag only for < v16
76
+ node --experimental-repl-await
67
77
 
68
- // UMD
69
- <script src="https://unpkg.com/@thi.ng/csv/lib/index.umd.js" crossorigin></script>
78
+ > const csv = await import("@thi.ng/csv");
70
79
  ```
71
80
 
72
- Package sizes (gzipped, pre-treeshake): ESM: 1.07 KB / CJS: 1.15 KB / UMD: 1.16 KB
81
+ Package sizes (gzipped, pre-treeshake): ESM: 1.44 KB
73
82
 
74
83
  ## Dependencies
75
84
 
package/api.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Fn2, Nullable } from "@thi.ng/api";
2
+ import type { Stringer } from "@thi.ng/strings";
2
3
  /**
3
4
  * Tuple representing a single CSV row/record.
4
5
  */
@@ -97,4 +98,31 @@ export interface CSVOpts extends CommonCSVOpts {
97
98
  */
98
99
  cols: Nullable<ColumnSpec>[] | Record<string, ColumnSpec>;
99
100
  }
101
+ export interface CSVFormatOpts {
102
+ /**
103
+ * Column names, in order of appearance. If omitted and rows are supplied as
104
+ * {@link CSVRecord}, the keys of the first item will be used as column
105
+ * names. If `header` is omitted and rows are given as array, NO header row
106
+ * will be created.
107
+ */
108
+ header: string[];
109
+ /**
110
+ * Column value formatters. If given as object, and the `header` option MUST be
111
+ * given and the column names given in `header` need to correspond with keys
112
+ * in the object.
113
+ */
114
+ cols: Nullable<Stringer<any>>[] | Record<string, Stringer<any>>;
115
+ /**
116
+ * Column delimiter
117
+ *
118
+ * @defaultValue `,`
119
+ */
120
+ delim: string;
121
+ /**
122
+ * Quote char
123
+ *
124
+ * @defaultValue `"`
125
+ */
126
+ quote: string;
127
+ }
100
128
  //# sourceMappingURL=api.d.ts.map
package/format.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { Transducer } from "@thi.ng/transducers";
2
+ import type { CSVFormatOpts, CSVRecord, CSVRow } from "./api.js";
3
+ export declare function formatCSV(opts?: Partial<CSVFormatOpts>): Transducer<CSVRow | CSVRecord, string>;
4
+ export declare function formatCSV(opts: Partial<CSVFormatOpts>, src: Iterable<CSVRow | CSVRecord>): IterableIterator<string>;
5
+ export declare const formatCSVString: (opts: Partial<CSVFormatOpts & {
6
+ rowDelim: string;
7
+ }> | undefined, src: Iterable<CSVRow>) => string;
8
+ //# sourceMappingURL=format.d.ts.map
package/format.js ADDED
@@ -0,0 +1,67 @@
1
+ import { isArray } from "@thi.ng/checks/is-array";
2
+ import { isIterable } from "@thi.ng/checks/is-iterable";
3
+ import { wrap } from "@thi.ng/strings/wrap";
4
+ import { compR } from "@thi.ng/transducers/compr";
5
+ import { iterator } from "@thi.ng/transducers/iterator";
6
+ import { isReduced } from "@thi.ng/transducers/reduced";
7
+ import { str } from "@thi.ng/transducers/str";
8
+ import { transduce } from "@thi.ng/transducers/transduce";
9
+ export function formatCSV(opts, src) {
10
+ return isIterable(src)
11
+ ? iterator(formatCSV(opts), src)
12
+ : (rfn) => {
13
+ let { header, cols, delim, quote } = {
14
+ delim: ",",
15
+ quote: `"`,
16
+ cols: [],
17
+ ...opts,
18
+ };
19
+ let colTx;
20
+ const reQuote = new RegExp(quote, "g");
21
+ const reduce = rfn[2];
22
+ let headerDone = false;
23
+ return compR(rfn, (acc, row) => {
24
+ if (!headerDone) {
25
+ if (!header && !isArray(row)) {
26
+ header = Object.keys(row);
27
+ }
28
+ colTx = isArray(cols)
29
+ ? cols
30
+ : header
31
+ ? header.map((id) => cols[id])
32
+ : [];
33
+ }
34
+ const $row = isArray(row)
35
+ ? row
36
+ : header.map((k) => row[k]);
37
+ const line = (header || $row)
38
+ .map((_, i) => {
39
+ const val = $row[i];
40
+ const cell = val != null
41
+ ? colTx[i]
42
+ ? colTx[i](val)
43
+ : String(val)
44
+ : "";
45
+ return cell.indexOf(quote) !== -1
46
+ ? wrap(quote)(cell.replace(reQuote, `${quote}${quote}`))
47
+ : cell;
48
+ })
49
+ .join(delim);
50
+ if (!headerDone) {
51
+ if (header) {
52
+ acc = reduce(acc, header.join(delim));
53
+ }
54
+ else {
55
+ header = $row;
56
+ }
57
+ headerDone = true;
58
+ !isReduced(acc) && (acc = reduce(acc, line));
59
+ return acc;
60
+ }
61
+ else {
62
+ return reduce(acc, line);
63
+ }
64
+ });
65
+ };
66
+ }
67
+ export const formatCSVString = (opts = {}, src) => transduce(formatCSV(opts), str(opts.rowDelim || "\n"), src);
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export * from "./api";
2
- export * from "./parse";
3
- export * from "./transforms";
1
+ export * from "./api.js";
2
+ export * from "./format.js";
3
+ export * from "./parse.js";
4
+ export * from "./transforms.js";
4
5
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./api";
2
- export * from "./parse";
3
- export * from "./transforms";
1
+ export * from "./api.js";
2
+ export * from "./format.js";
3
+ export * from "./parse.js";
4
+ export * from "./transforms.js";
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@thi.ng/csv",
3
- "version": "1.0.6",
3
+ "version": "2.0.3",
4
4
  "description": "Customizable, transducer-based CSV parser/object mapper and transformer",
5
+ "type": "module",
5
6
  "module": "./index.js",
6
- "main": "./lib/index.js",
7
- "umd:main": "./lib/index.umd.js",
8
7
  "typings": "./index.d.ts",
8
+ "sideEffects": false,
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
@@ -24,30 +24,24 @@
24
24
  "author": "Karsten Schmidt <k+npm@thi.ng>",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module",
28
- "build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all",
29
- "build:es6": "tsc --declaration",
30
- "build:test": "rimraf build && tsc -p test/tsconfig.json",
31
- "build:check": "tsc --isolatedModules --noEmit",
32
- "test": "mocha test",
33
- "cover": "nyc mocha test && nyc report --reporter=lcov",
34
- "clean": "rimraf *.js *.d.ts *.map .nyc_output build coverage doc lib",
35
- "doc:readme": "ts-node -P ../../tools/tsconfig.json ../../tools/src/readme.ts",
36
- "doc": "typedoc --excludePrivate --out doc --theme ../../tools/doc/typedoc-theme src/index.ts",
27
+ "build": "yarn clean && tsc --declaration",
28
+ "clean": "rimraf *.js *.d.ts *.map doc",
29
+ "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
37
30
  "doc:ae": "mkdir -p .ae/doc .ae/temp && node_modules/.bin/api-extractor run --local --verbose",
38
- "pub": "yarn build:release && yarn publish --access public"
31
+ "doc:readme": "yarn doc:stats && ../../scripts/node-esm ../../tools/src/readme.ts",
32
+ "doc:stats": "../../scripts/node-esm ../../tools/src/module-stats.ts",
33
+ "pub": "yarn build && yarn publish --access public",
34
+ "test": "testament test"
39
35
  },
40
36
  "dependencies": {
41
- "@thi.ng/api": "^7.1.9",
42
- "@thi.ng/checks": "^2.9.10",
43
- "@thi.ng/strings": "^2.1.6",
44
- "@thi.ng/transducers": "^7.9.1"
37
+ "@thi.ng/api": "^8.0.3",
38
+ "@thi.ng/checks": "^3.0.3",
39
+ "@thi.ng/strings": "^3.0.3",
40
+ "@thi.ng/transducers": "^8.0.3"
41
+ },
42
+ "devDependencies": {
43
+ "@thi.ng/testament": "^0.1.3"
45
44
  },
46
- "files": [
47
- "*.js",
48
- "*.d.ts",
49
- "lib"
50
- ],
51
45
  "keywords": [
52
46
  "csv",
53
47
  "fileformat",
@@ -59,9 +53,32 @@
59
53
  "publishConfig": {
60
54
  "access": "public"
61
55
  },
62
- "sideEffects": false,
56
+ "engines": {
57
+ "node": ">=12.7"
58
+ },
59
+ "files": [
60
+ "*.js",
61
+ "*.d.ts"
62
+ ],
63
+ "exports": {
64
+ ".": {
65
+ "import": "./index.js"
66
+ },
67
+ "./api": {
68
+ "import": "./api.js"
69
+ },
70
+ "./format": {
71
+ "import": "./format.js"
72
+ },
73
+ "./parse": {
74
+ "import": "./parse.js"
75
+ },
76
+ "./transforms": {
77
+ "import": "./transforms.js"
78
+ }
79
+ },
63
80
  "thi.ng": {
64
81
  "year": 2014
65
82
  },
66
- "gitHead": "84a067278ef79ccd538eeb652046eb8e03f3e34e"
83
+ "gitHead": "1fb38cac74d6c009d96855c28784a267a81badf1"
67
84
  }
package/parse.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Transducer } from "@thi.ng/transducers";
2
- import type { CSVOpts, CSVRecord, CSVRow, SimpleCSVOpts } from "./api";
1
+ import type { Transducer } from "@thi.ng/transducers";
2
+ import type { CSVOpts, CSVRecord, CSVRow, SimpleCSVOpts } from "./api.js";
3
3
  /**
4
4
  * Configurable CSV parsing transducer, operating on line-based string iterables
5
5
  * and yielding tuple objects of CSV row records. If called with input, returns
package/parse.js CHANGED
@@ -1,6 +1,10 @@
1
- import { compR, iterator1 } from "@thi.ng/transducers";
2
- import { ESCAPES, split } from "@thi.ng/strings";
3
- import { isArray, isFunction, isIterable } from "@thi.ng/checks";
1
+ import { isArray } from "@thi.ng/checks/is-array";
2
+ import { isFunction } from "@thi.ng/checks/is-function";
3
+ import { isIterable } from "@thi.ng/checks/is-iterable";
4
+ import { ESCAPES } from "@thi.ng/strings/escape";
5
+ import { split } from "@thi.ng/strings/split";
6
+ import { compR } from "@thi.ng/transducers/compr";
7
+ import { iterator1 } from "@thi.ng/transducers/iterator";
4
8
  /**
5
9
  * Default parser options.
6
10
  *
@@ -16,7 +20,11 @@ export function parseCSV(opts, src) {
16
20
  return isIterable(src)
17
21
  ? iterator1(parseCSV(opts), src)
18
22
  : (rfn) => {
19
- const { all, cols, delim, quote, comment, trim, header } = Object.assign(Object.assign({ all: true }, DEFAULT_OPTS), opts);
23
+ const { all, cols, delim, quote, comment, trim, header } = {
24
+ all: true,
25
+ ...DEFAULT_OPTS,
26
+ ...opts,
27
+ };
20
28
  const reduce = rfn[2];
21
29
  let index;
22
30
  let revIndex;
@@ -69,7 +77,11 @@ export function parseCSVSimple(opts, src) {
69
77
  return isIterable(src)
70
78
  ? iterator1(parseCSVSimple(opts), src)
71
79
  : (rfn) => {
72
- const { cols, delim, quote, comment, trim, header } = Object.assign(Object.assign({ header: true }, DEFAULT_OPTS), opts);
80
+ const { cols, delim, quote, comment, trim, header } = {
81
+ header: true,
82
+ ...DEFAULT_OPTS,
83
+ ...opts,
84
+ };
73
85
  const reduce = rfn[2];
74
86
  let first = header;
75
87
  let isQuoted = false;
@@ -186,7 +198,7 @@ const initIndex = (line, cols) => isArray(cols)
186
198
  ? cols.reduce((acc, spec, i) => {
187
199
  if (spec) {
188
200
  const alias = spec.alias || line[i] || String(i);
189
- acc[alias] = { i, spec: Object.assign({ alias }, spec) };
201
+ acc[alias] = { i, spec: { alias, ...spec } };
190
202
  }
191
203
  return acc;
192
204
  }, {})
package/transforms.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import type { CellTransform } from "./api";
1
+ import type { CellTransform } from "./api.js";
2
2
  export declare const upper: CellTransform;
3
3
  export declare const lower: CellTransform;
4
4
  export declare const float: (defaultVal?: number) => CellTransform;
5
5
  export declare const int: (defaultVal?: number) => CellTransform;
6
6
  export declare const hex: (defaultVal?: number) => CellTransform;
7
+ export declare const zeroPad: (digits: number) => (x: any, length?: number | undefined) => string;
8
+ export declare const formatFloat: (prec?: number) => (x: number) => string;
7
9
  //# sourceMappingURL=transforms.d.ts.map
package/transforms.js CHANGED
@@ -1,6 +1,10 @@
1
- import { maybeParseFloat, maybeParseInt } from "@thi.ng/strings";
1
+ import { padLeft } from "@thi.ng/strings/pad-left";
2
+ import { maybeParseFloat, maybeParseInt } from "@thi.ng/strings/parse";
2
3
  export const upper = (x) => x.toUpperCase();
3
4
  export const lower = (x) => x.toLowerCase();
4
5
  export const float = (defaultVal = 0) => (x) => maybeParseFloat(x, defaultVal);
5
6
  export const int = (defaultVal = 0) => (x) => maybeParseInt(x, defaultVal, 10);
6
7
  export const hex = (defaultVal = 0) => (x) => maybeParseInt(x, defaultVal, 16);
8
+ // formatters
9
+ export const zeroPad = (digits) => padLeft(digits, "0");
10
+ export const formatFloat = (prec = 2) => (x) => x.toFixed(prec);
package/lib/index.js DELETED
@@ -1,171 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var transducers = require('@thi.ng/transducers');
6
- var strings = require('@thi.ng/strings');
7
- var checks = require('@thi.ng/checks');
8
-
9
- const DEFAULT_OPTS = {
10
- delim: ",",
11
- quote: '"',
12
- comment: "#",
13
- trim: false,
14
- };
15
- function parseCSV(opts, src) {
16
- return checks.isIterable(src)
17
- ? transducers.iterator1(parseCSV(opts), src)
18
- : (rfn) => {
19
- const { all, cols, delim, quote, comment, trim, header } = Object.assign(Object.assign({ all: true }, DEFAULT_OPTS), opts);
20
- const reduce = rfn[2];
21
- let index;
22
- let revIndex;
23
- let first = true;
24
- let isQuoted = false;
25
- let record = [];
26
- const init = (header) => {
27
- cols && (index = initIndex(header, cols));
28
- all && (revIndex = initRevIndex(header));
29
- first = false;
30
- };
31
- const collectAll = (row) => record.reduce((acc, x, i) => ((acc[revIndex[i]] = trim ? x.trim() : x), acc), row);
32
- const collectIndexed = (row) => Object.entries(index).reduce((acc, [id, { i, spec }]) => {
33
- let val = record[i];
34
- if (val !== undefined) {
35
- trim && (val = val.trim());
36
- all && spec.alias && delete acc[id];
37
- acc[spec.alias || id] = spec.tx
38
- ? spec.tx(val, acc)
39
- : val;
40
- }
41
- return acc;
42
- }, row);
43
- header && init(header);
44
- return transducers.compR(rfn, (acc, line) => {
45
- if ((!line.length || line.startsWith(comment)) && !isQuoted)
46
- return acc;
47
- if (!first) {
48
- isQuoted = parseLine(line, record, isQuoted, delim, quote);
49
- if (isQuoted)
50
- return acc;
51
- const row = {};
52
- all && collectAll(row);
53
- index && collectIndexed(row);
54
- record = [];
55
- return reduce(acc, row);
56
- }
57
- else {
58
- isQuoted = parseLine(line, record, isQuoted, delim, quote);
59
- if (!isQuoted) {
60
- init(record);
61
- record = [];
62
- }
63
- return acc;
64
- }
65
- });
66
- };
67
- }
68
- function parseCSVSimple(opts, src) {
69
- return checks.isIterable(src)
70
- ? transducers.iterator1(parseCSVSimple(opts), src)
71
- : (rfn) => {
72
- const { cols, delim, quote, comment, trim, header } = Object.assign(Object.assign({ header: true }, DEFAULT_OPTS), opts);
73
- const reduce = rfn[2];
74
- let first = header;
75
- let isQuoted = false;
76
- let record = [];
77
- const collect = () => cols.reduce((acc, col, i) => {
78
- if (col) {
79
- let val = record[i];
80
- if (val !== undefined) {
81
- trim && (val = val.trim());
82
- acc.push(checks.isFunction(col) ? col(val, acc) : val);
83
- }
84
- }
85
- return acc;
86
- }, []);
87
- return transducers.compR(rfn, (acc, line) => {
88
- if ((!line.length || line.startsWith(comment)) && !isQuoted)
89
- return acc;
90
- if (!first) {
91
- isQuoted = parseLine(line, record, isQuoted, delim, quote);
92
- if (isQuoted)
93
- return acc;
94
- const row = cols ? collect() : record;
95
- record = [];
96
- return reduce(acc, row);
97
- }
98
- else {
99
- isQuoted = parseLine(line, record, isQuoted, delim, quote);
100
- first = false;
101
- record = [];
102
- return acc;
103
- }
104
- });
105
- };
106
- }
107
- const parseCSVFromString = (opts, src) => parseCSV(opts, strings.split(src));
108
- const parseCSVSimpleFromString = (opts, src) => parseCSVSimple(opts, strings.split(src));
109
- const parseLine = (line, acc, isQuoted, delim, quote) => {
110
- let curr = "";
111
- let p = "";
112
- let openQuote = isQuoted;
113
- for (let i = 0, n = line.length; i < n; i++) {
114
- const c = line[i];
115
- if (p === "\\") {
116
- curr += strings.ESCAPES[c] || c;
117
- }
118
- else if (c === quote) {
119
- if (!isQuoted) {
120
- p = "";
121
- isQuoted = true;
122
- continue;
123
- }
124
- else if (p === quote) {
125
- curr += quote;
126
- p = "";
127
- continue;
128
- }
129
- else if (line[i + 1] !== quote)
130
- isQuoted = false;
131
- }
132
- else if (!isQuoted && c === delim) {
133
- collectCell(acc, curr, openQuote);
134
- openQuote = false;
135
- curr = "";
136
- }
137
- else if (c !== "\\") {
138
- curr += c;
139
- }
140
- p = c;
141
- }
142
- curr !== "" && collectCell(acc, curr, openQuote);
143
- return isQuoted;
144
- };
145
- const collectCell = (acc, curr, openQuote) => openQuote ? (acc[acc.length - 1] += "\n" + curr) : acc.push(curr);
146
- const initIndex = (line, cols) => checks.isArray(cols)
147
- ? cols.reduce((acc, spec, i) => {
148
- if (spec) {
149
- const alias = spec.alias || line[i] || String(i);
150
- acc[alias] = { i, spec: Object.assign({ alias }, spec) };
151
- }
152
- return acc;
153
- }, {})
154
- : line.reduce((acc, id, i) => cols[id] ? ((acc[id] = { i, spec: cols[id] }), acc) : acc, {});
155
- const initRevIndex = (line) => line.reduce((acc, x, i) => ((acc[i] = x), acc), {});
156
-
157
- const upper = (x) => x.toUpperCase();
158
- const lower = (x) => x.toLowerCase();
159
- const float = (defaultVal = 0) => (x) => strings.maybeParseFloat(x, defaultVal);
160
- const int = (defaultVal = 0) => (x) => strings.maybeParseInt(x, defaultVal, 10);
161
- const hex = (defaultVal = 0) => (x) => strings.maybeParseInt(x, defaultVal, 16);
162
-
163
- exports.float = float;
164
- exports.hex = hex;
165
- exports.int = int;
166
- exports.lower = lower;
167
- exports.parseCSV = parseCSV;
168
- exports.parseCSVFromString = parseCSVFromString;
169
- exports.parseCSVSimple = parseCSVSimple;
170
- exports.parseCSVSimpleFromString = parseCSVSimpleFromString;
171
- exports.upper = upper;
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../parse.js","../transforms.js"],"sourcesContent":null,"names":["isIterable","iterator1","compR","isFunction","split","ESCAPES","isArray","maybeParseFloat","maybeParseInt"],"mappings":";;;;;;;;AAQA,MAAM,YAAY,GAAG;AACrB,IAAI,KAAK,EAAE,GAAG;AACd,IAAI,KAAK,EAAE,GAAG;AACd,IAAI,OAAO,EAAE,GAAG;AAChB,IAAI,IAAI,EAAE,KAAK;AACf,CAAC,CAAC;AACK,SAAS,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE;AACpC,IAAI,OAAOA,iBAAU,CAAC,GAAG,CAAC;AAC1B,UAAUC,qBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;AACxC,UAAU,CAAC,GAAG,KAAK;AACnB,YAAY,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;AACvI,YAAY,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAClC,YAAY,IAAI,KAAK,CAAC;AACtB,YAAY,IAAI,QAAQ,CAAC;AACzB,YAAY,IAAI,KAAK,GAAG,IAAI,CAAC;AAC7B,YAAY,IAAI,QAAQ,GAAG,KAAK,CAAC;AACjC,YAAY,IAAI,MAAM,GAAG,EAAE,CAAC;AAC5B,YAAY,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK;AACrC,gBAAgB,IAAI,KAAK,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,IA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AC,KAAKC,uBAAe,CAAC,CAAC,EAAE,UAAU,EAAE;AACnE,MAAC,GAAG,GAAG,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,CAAC,KAAKC,qBAAa,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;AACnE,MAAC,GAAG,GAAG,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,CAAC,KAAKA,qBAAa,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE;;;;;;;;;;;;"}
package/lib/index.umd.js DELETED
@@ -1 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/transducers"),require("@thi.ng/strings"),require("@thi.ng/checks")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/transducers","@thi.ng/strings","@thi.ng/checks"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.csv={}),e.thi.ng.transducers,e.thi.ng.strings,e.thi.ng.checks)}(this,(function(e,t,r,i){"use strict";const n={delim:",",quote:'"',comment:"#",trim:!1};function s(e,r){return i.isIterable(r)?t.iterator1(s(e),r):r=>{const{all:i,cols:s,delim:o,quote:u,comment:h,trim:f,header:d}=Object.assign(Object.assign({all:!0},n),e),g=r[2];let p,m,b=!0,S=!1,y=[];const j=e=>{s&&(p=a(e,s)),i&&(m=l(e)),b=!1};return d&&j(d),t.compR(r,((e,t)=>{if((!t.length||t.startsWith(h))&&!S)return e;if(b)return S=c(t,y,S,o,u),S||(j(y),y=[]),e;{if(S=c(t,y,S,o,u),S)return e;const r={};return i&&(e=>{y.reduce(((e,t,r)=>(e[m[r]]=f?t.trim():t,e)),e)})(r),p&&(e=>{Object.entries(p).reduce(((e,[t,{i:r,spec:n}])=>{let s=y[r];return void 0!==s&&(f&&(s=s.trim()),i&&n.alias&&delete e[t],e[n.alias||t]=n.tx?n.tx(s,e):s),e}),e)})(r),y=[],g(e,r)}}))}}function o(e,r){return i.isIterable(r)?t.iterator1(o(e),r):r=>{const{cols:s,delim:o,quote:u,comment:a,trim:l,header:h}=Object.assign(Object.assign({header:!0},n),e),f=r[2];let d=h,g=!1,p=[];return t.compR(r,((e,t)=>{if((!t.length||t.startsWith(a))&&!g)return e;if(d)return g=c(t,p,g,o,u),d=!1,p=[],e;{if(g=c(t,p,g,o,u),g)return e;const r=s?s.reduce(((e,t,r)=>{if(t){let n=p[r];void 0!==n&&(l&&(n=n.trim()),e.push(i.isFunction(t)?t(n,e):n))}return e}),[]):p;return p=[],f(e,r)}}))}}const c=(e,t,i,n,s)=>{let o="",c="",a=i;for(let l=0,h=e.length;l<h;l++){const h=e[l];if("\\"===c)o+=r.ESCAPES[h]||h;else if(h===s){if(!i){c="",i=!0;continue}if(c===s){o+=s,c="";continue}e[l+1]!==s&&(i=!1)}else i||h!==n?"\\"!==h&&(o+=h):(u(t,o,a),a=!1,o="");c=h}return""!==o&&u(t,o,a),i},u=(e,t,r)=>r?e[e.length-1]+="\n"+t:e.push(t),a=(e,t)=>i.isArray(t)?t.reduce(((t,r,i)=>{if(r){const n=r.alias||e[i]||String(i);t[n]={i,spec:Object.assign({alias:n},r)}}return t}),{}):e.reduce(((e,r,i)=>t[r]?(e[r]={i,spec:t[r]},e):e),{}),l=e=>e.reduce(((e,t,r)=>(e[r]=t,e)),{});e.float=(e=0)=>t=>r.maybeParseFloat(t,e),e.hex=(e=0)=>t=>r.maybeParseInt(t,e,16),e.int=(e=0)=>t=>r.maybeParseInt(t,e,10),e.lower=e=>e.toLowerCase(),e.parseCSV=s,e.parseCSVFromString=(e,t)=>s(e,r.split(t)),e.parseCSVSimple=o,e.parseCSVSimpleFromString=(e,t)=>o(e,r.split(t)),e.upper=e=>e.toUpperCase(),Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../parse.js","../transforms.js"],"sourcesContent":null,"names":["isIterable","iterator1","compR","isFunction","split","ESCAPES","isArray","maybeParseFlo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