utilful 1.1.0 → 1.1.1
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.d.mts +3 -1
- package/dist/csv.d.ts +3 -1
- package/dist/csv.mjs +6 -5
- package/package.json +1 -1
package/dist/csv.d.mts
CHANGED
|
@@ -30,12 +30,14 @@ declare function createCSV<T extends Record<string, unknown>>(data: T[], columns
|
|
|
30
30
|
*
|
|
31
31
|
* @remarks
|
|
32
32
|
* Returns an empty string if the value is `null` or `undefined`.
|
|
33
|
+
* Values containing delimiters, quotes, or line breaks are quoted.
|
|
34
|
+
* Within quoted values, double quotes are escaped by doubling them.
|
|
33
35
|
*
|
|
34
36
|
* @example
|
|
35
37
|
* escapeCSVValue('hello, world'); // "hello, world"
|
|
36
38
|
* escapeCSVValue('contains "quotes"'); // "contains ""quotes"""
|
|
37
39
|
*/
|
|
38
|
-
declare function escapeCSVValue(value: unknown,
|
|
40
|
+
declare function escapeCSVValue(value: unknown, options?: {
|
|
39
41
|
/** @default ',' */
|
|
40
42
|
delimiter?: string;
|
|
41
43
|
/** @default false */
|
package/dist/csv.d.ts
CHANGED
|
@@ -30,12 +30,14 @@ declare function createCSV<T extends Record<string, unknown>>(data: T[], columns
|
|
|
30
30
|
*
|
|
31
31
|
* @remarks
|
|
32
32
|
* Returns an empty string if the value is `null` or `undefined`.
|
|
33
|
+
* Values containing delimiters, quotes, or line breaks are quoted.
|
|
34
|
+
* Within quoted values, double quotes are escaped by doubling them.
|
|
33
35
|
*
|
|
34
36
|
* @example
|
|
35
37
|
* escapeCSVValue('hello, world'); // "hello, world"
|
|
36
38
|
* escapeCSVValue('contains "quotes"'); // "contains ""quotes"""
|
|
37
39
|
*/
|
|
38
|
-
declare function escapeCSVValue(value: unknown,
|
|
40
|
+
declare function escapeCSVValue(value: unknown, options?: {
|
|
39
41
|
/** @default ',' */
|
|
40
42
|
delimiter?: string;
|
|
41
43
|
/** @default false */
|
package/dist/csv.mjs
CHANGED
|
@@ -13,14 +13,15 @@ function createCSV(data, columns, options = {}) {
|
|
|
13
13
|
}
|
|
14
14
|
return rows.join("\n");
|
|
15
15
|
}
|
|
16
|
-
function escapeCSVValue(value, {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
function escapeCSVValue(value, options = {}) {
|
|
17
|
+
const {
|
|
18
|
+
delimiter = ",",
|
|
19
|
+
quoteAll = false
|
|
20
|
+
} = options;
|
|
20
21
|
if (value == null) {
|
|
21
22
|
return "";
|
|
22
23
|
}
|
|
23
|
-
const stringValue = value
|
|
24
|
+
const stringValue = String(value);
|
|
24
25
|
const needsQuoting = quoteAll || stringValue.includes(delimiter) || stringValue.includes('"') || stringValue.includes("\n") || stringValue.includes("\r");
|
|
25
26
|
if (needsQuoting) {
|
|
26
27
|
return `"${stringValue.replaceAll('"', '""')}"`;
|
package/package.json
CHANGED