@smartnet360/svelte-components 0.0.129 → 0.0.130
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.
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
* Parses CSV files for custom cell sets.
|
|
5
5
|
* Required column: cellName (or txId for backwards compatibility)
|
|
6
6
|
* Optional columns: customGroup, sizeFactor, + any extras for tooltips
|
|
7
|
+
* Supports both comma (,) and semicolon (;) delimiters
|
|
7
8
|
*/
|
|
8
9
|
import type { CustomCellImportResult } from '../types';
|
|
9
10
|
import type { Cell } from '../../../../../shared/demo';
|
|
11
|
+
/**
|
|
12
|
+
* Supported delimiters
|
|
13
|
+
*/
|
|
14
|
+
export type CsvDelimiter = ',' | ';' | 'auto';
|
|
10
15
|
/**
|
|
11
16
|
* Parse a CSV string into custom cells
|
|
12
17
|
* @param csvContent Raw CSV content
|
|
13
18
|
* @param cellLookup Map of cellName -> Cell for resolving cell data
|
|
19
|
+
* @param delimiter Delimiter to use: ',' (comma), ';' (semicolon), or 'auto' (detect)
|
|
14
20
|
* @returns Import result with cells, unmatched IDs, groups, and extra columns
|
|
15
21
|
*/
|
|
16
|
-
export declare function parseCustomCellsCsv(csvContent: string, cellLookup: Map<string, Cell
|
|
22
|
+
export declare function parseCustomCellsCsv(csvContent: string, cellLookup: Map<string, Cell>, delimiter?: CsvDelimiter): CustomCellImportResult;
|
|
17
23
|
/**
|
|
18
24
|
* Build a cell lookup map from an array of cells
|
|
19
25
|
* Creates lookups for both cellName and txId for flexible matching
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Parses CSV files for custom cell sets.
|
|
5
5
|
* Required column: cellName (or txId for backwards compatibility)
|
|
6
6
|
* Optional columns: customGroup, sizeFactor, + any extras for tooltips
|
|
7
|
+
* Supports both comma (,) and semicolon (;) delimiters
|
|
7
8
|
*/
|
|
8
9
|
/**
|
|
9
10
|
* Known/reserved column names
|
|
@@ -15,13 +16,23 @@ const RESERVED_COLUMNS = ['cellname', 'txid', 'customgroup', 'sizefactor'];
|
|
|
15
16
|
function normalizeColumnName(name) {
|
|
16
17
|
return name.trim().toLowerCase();
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect the delimiter used in CSV content
|
|
21
|
+
* Counts occurrences in the header line and picks the most common
|
|
22
|
+
*/
|
|
23
|
+
function detectDelimiter(headerLine) {
|
|
24
|
+
const commaCount = (headerLine.match(/,/g) || []).length;
|
|
25
|
+
const semicolonCount = (headerLine.match(/;/g) || []).length;
|
|
26
|
+
return semicolonCount > commaCount ? ';' : ',';
|
|
27
|
+
}
|
|
18
28
|
/**
|
|
19
29
|
* Parse a CSV string into custom cells
|
|
20
30
|
* @param csvContent Raw CSV content
|
|
21
31
|
* @param cellLookup Map of cellName -> Cell for resolving cell data
|
|
32
|
+
* @param delimiter Delimiter to use: ',' (comma), ';' (semicolon), or 'auto' (detect)
|
|
22
33
|
* @returns Import result with cells, unmatched IDs, groups, and extra columns
|
|
23
34
|
*/
|
|
24
|
-
export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
35
|
+
export function parseCustomCellsCsv(csvContent, cellLookup, delimiter = 'auto') {
|
|
25
36
|
const lines = csvContent.trim().split('\n');
|
|
26
37
|
if (lines.length < 2) {
|
|
27
38
|
return {
|
|
@@ -32,9 +43,11 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
32
43
|
totalRows: 0
|
|
33
44
|
};
|
|
34
45
|
}
|
|
35
|
-
//
|
|
46
|
+
// Detect or use specified delimiter
|
|
36
47
|
const headerLine = lines[0];
|
|
37
|
-
const
|
|
48
|
+
const actualDelimiter = delimiter === 'auto' ? detectDelimiter(headerLine) : delimiter;
|
|
49
|
+
// Parse header
|
|
50
|
+
const headers = parseCSVLine(headerLine, actualDelimiter);
|
|
38
51
|
const normalizedHeaders = headers.map(normalizeColumnName);
|
|
39
52
|
// Find cell identifier column - prefer cellName, fallback to txId
|
|
40
53
|
let idIndex = normalizedHeaders.findIndex(h => h === 'cellname');
|
|
@@ -67,7 +80,7 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
67
80
|
const line = lines[i].trim();
|
|
68
81
|
if (!line)
|
|
69
82
|
continue;
|
|
70
|
-
const values = parseCSVLine(line);
|
|
83
|
+
const values = parseCSVLine(line, actualDelimiter);
|
|
71
84
|
const cellIdentifier = values[idIndex]?.trim();
|
|
72
85
|
if (!cellIdentifier)
|
|
73
86
|
continue;
|
|
@@ -117,8 +130,10 @@ export function parseCustomCellsCsv(csvContent, cellLookup) {
|
|
|
117
130
|
}
|
|
118
131
|
/**
|
|
119
132
|
* Parse a single CSV line, handling quoted fields
|
|
133
|
+
* @param line The CSV line to parse
|
|
134
|
+
* @param delimiter The field delimiter (',' or ';')
|
|
120
135
|
*/
|
|
121
|
-
function parseCSVLine(line) {
|
|
136
|
+
function parseCSVLine(line, delimiter = ',') {
|
|
122
137
|
const result = [];
|
|
123
138
|
let current = '';
|
|
124
139
|
let inQuotes = false;
|
|
@@ -143,7 +158,7 @@ function parseCSVLine(line) {
|
|
|
143
158
|
if (char === '"') {
|
|
144
159
|
inQuotes = true;
|
|
145
160
|
}
|
|
146
|
-
else if (char ===
|
|
161
|
+
else if (char === delimiter) {
|
|
147
162
|
result.push(current);
|
|
148
163
|
current = '';
|
|
149
164
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Custom Cells Logic - Barrel Export
|
|
3
3
|
*/
|
|
4
|
-
export { parseCustomCellsCsv, buildCellLookup } from './csv-parser';
|
|
4
|
+
export { parseCustomCellsCsv, buildCellLookup, type CsvDelimiter } from './csv-parser';
|
|
5
5
|
export { buildCustomCellTree, getGroupCounts } from './tree-adapter';
|