utilful 2.2.1 → 2.2.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/dist/csv.mjs CHANGED
@@ -22,7 +22,7 @@ function createCSV(data, columns, options = {}) {
22
22
  quoteAll
23
23
  });
24
24
  const rows = data.map((obj) => columns.map((key) => formatCell(obj[key])).join(delimiter));
25
- if (addHeader) rows.unshift(columns.map(formatCell).join(delimiter));
25
+ if (addHeader) return columns.map(formatCell).join(delimiter) + lineEnding + rows.join(lineEnding);
26
26
  return rows.join(lineEnding);
27
27
  }
28
28
  /**
@@ -100,8 +100,11 @@ function parseCSV(csv, options = {}) {
100
100
  const positions = headers.map((h, i) => h.length === 0 ? i + 1 : -1).filter((i) => i > 0).join(", ");
101
101
  throw new SyntaxError(`CSV header row contains empty column name(s) at position(s): ${positions}`);
102
102
  }
103
- const duplicateHeaderNames = headers.filter((h, i) => headers.indexOf(h) !== i);
104
- if (duplicateHeaderNames.length > 0) throw new SyntaxError(`CSV header row contains duplicate column name(s): ${[...new Set(duplicateHeaderNames)].join(", ")}`);
103
+ const headerSet = /* @__PURE__ */ new Set();
104
+ const duplicateHeaderNames = /* @__PURE__ */ new Set();
105
+ for (const header of headers) if (headerSet.has(header)) duplicateHeaderNames.add(header);
106
+ else headerSet.add(header);
107
+ if (duplicateHeaderNames.size > 0) throw new SyntaxError(`CSV header row contains duplicate column name(s): ${[...duplicateHeaderNames].join(", ")}`);
105
108
  const isFieldPopulated = trim ? (field) => field.trim().length > 0 : (field) => field.length > 0;
106
109
  return rows.slice(1).filter((row) => row.length > 1 || row.some(isFieldPopulated)).map((fieldValues, rowIndex) => {
107
110
  if (fieldValues.length > headers.length) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilful",
3
3
  "type": "module",
4
- "version": "2.2.1",
4
+ "version": "2.2.3",
5
5
  "packageManager": "pnpm@10.21.0",
6
6
  "description": "A collection of TypeScript utilities",
7
7
  "author": "Johann Schopplich <hello@johannschopplich.com>",
@@ -17,55 +17,55 @@
17
17
  "sideEffects": false,
18
18
  "exports": {
19
19
  ".": {
20
- "types": "./dist/index.d.ts",
21
- "default": "./dist/index.js"
20
+ "types": "./dist/index.d.mts",
21
+ "default": "./dist/index.mjs"
22
22
  },
23
23
  "./array": {
24
- "types": "./dist/array.d.ts",
25
- "default": "./dist/array.js"
24
+ "types": "./dist/array.d.mts",
25
+ "default": "./dist/array.mjs"
26
26
  },
27
27
  "./csv": {
28
- "types": "./dist/csv.d.ts",
29
- "default": "./dist/csv.js"
28
+ "types": "./dist/csv.d.mts",
29
+ "default": "./dist/csv.mjs"
30
30
  },
31
31
  "./defu": {
32
- "types": "./dist/defu.d.ts",
33
- "default": "./dist/defu.js"
32
+ "types": "./dist/defu.d.mts",
33
+ "default": "./dist/defu.mjs"
34
34
  },
35
35
  "./emitter": {
36
- "types": "./dist/emitter.d.ts",
37
- "default": "./dist/emitter.js"
36
+ "types": "./dist/emitter.d.mts",
37
+ "default": "./dist/emitter.mjs"
38
38
  },
39
39
  "./json": {
40
- "types": "./dist/json.d.ts",
41
- "default": "./dist/json.js"
40
+ "types": "./dist/json.d.mts",
41
+ "default": "./dist/json.mjs"
42
42
  },
43
43
  "./module": {
44
- "types": "./dist/module.d.ts",
45
- "default": "./dist/module.js"
44
+ "types": "./dist/module.d.mts",
45
+ "default": "./dist/module.mjs"
46
46
  },
47
47
  "./object": {
48
- "types": "./dist/object.d.ts",
49
- "default": "./dist/object.js"
48
+ "types": "./dist/object.d.mts",
49
+ "default": "./dist/object.mjs"
50
50
  },
51
51
  "./path": {
52
- "types": "./dist/path.d.ts",
53
- "default": "./dist/path.js"
52
+ "types": "./dist/path.d.mts",
53
+ "default": "./dist/path.mjs"
54
54
  },
55
55
  "./result": {
56
- "types": "./dist/result.d.ts",
57
- "default": "./dist/result.js"
56
+ "types": "./dist/result.d.mts",
57
+ "default": "./dist/result.mjs"
58
58
  },
59
59
  "./string": {
60
- "types": "./dist/string.d.ts",
61
- "default": "./dist/string.js"
60
+ "types": "./dist/string.d.mts",
61
+ "default": "./dist/string.mjs"
62
62
  },
63
63
  "./types": {
64
- "types": "./dist/types.d.ts",
65
- "default": "./dist/types.js"
64
+ "types": "./dist/types.d.mts",
65
+ "default": "./dist/types.mjs"
66
66
  }
67
67
  },
68
- "types": "./dist/index.d.ts",
68
+ "types": "./dist/index.d.mts",
69
69
  "files": [
70
70
  "dist"
71
71
  ],
package/dist/types.mjs DELETED
@@ -1 +0,0 @@
1
- export { };