utilful 2.2.0 → 2.2.2

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
@@ -16,6 +16,7 @@
16
16
  */
17
17
  function createCSV(data, columns, options = {}) {
18
18
  const { delimiter = ",", addHeader = true, quoteAll = false, lineEnding = "\n" } = options;
19
+ if (delimiter.length !== 1) throw new RangeError(`CSV delimiter must be a single character, got "${delimiter}"`);
19
20
  const formatCell = (value) => escapeCSVValue(value, {
20
21
  delimiter,
21
22
  quoteAll
@@ -63,7 +64,9 @@ function parseCSV(csv, options = {}) {
63
64
  let currentRow = [];
64
65
  let currentField = "";
65
66
  let inQuotes = false;
67
+ let currentRowNumber = 1;
66
68
  const { delimiter = ",", trim = true, strict = true } = options;
69
+ if (delimiter.length !== 1) throw new RangeError(`CSV delimiter must be a single character, got "${delimiter}"`);
67
70
  const appendField = () => {
68
71
  currentRow.push(currentField);
69
72
  currentField = "";
@@ -84,9 +87,11 @@ function parseCSV(csv, options = {}) {
84
87
  else if ((character === "\n" || character === "\r" && nextCharacter === "\n") && !inQuotes) {
85
88
  if (character === "\r") i++;
86
89
  appendRow();
90
+ currentRowNumber++;
87
91
  } else currentField += character;
88
92
  }
89
93
  if (currentField || currentRow.length > 0) appendRow();
94
+ if (inQuotes) throw new SyntaxError(`CSV contains unterminated quoted field at row ${currentRowNumber}`);
90
95
  if (rows.length <= 1) return [];
91
96
  const [headerRow] = rows;
92
97
  if (!headerRow) return [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilful",
3
3
  "type": "module",
4
- "version": "2.2.0",
4
+ "version": "2.2.2",
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 { };