convert-csv-to-json 4.45.0 → 4.47.0

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/README.md CHANGED
@@ -206,6 +206,15 @@ csvToJson.parseSubArray('*', ',').getJsonFromCsv('data.csv');
206
206
  // Output: { name: 'John', tags: ['javascript', 'nodejs', 'typescript'] }
207
207
  ```
208
208
 
209
+ #### `ignoreColumnIndexes(indexes)` - Exclude specific columns by index
210
+ ```js
211
+ // Input: firstName,lastName,age
212
+ // John,Doe,30
213
+ // Jane,Smith,25
214
+ csvToJson.ignoreColumnIndexes([1]).getJsonFromCsv('data.csv');
215
+ // Output: [{ firstName: 'John', age: '30' }, { firstName: 'Jane', age: '25' }]
216
+ ```
217
+
209
218
  #### `mapRows(fn)` - Transform, filter, or enrich each row
210
219
 
211
220
  ```js
@@ -0,0 +1,309 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html class="light" lang="en"><head>
4
+ <meta charset="utf-8"/>
5
+ <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
6
+ <title>Alchemist | Premium CSV to JSON Converter</title>
7
+ <script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
8
+ <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&amp;family=Inter:wght@300;400;500;600&amp;display=swap" rel="stylesheet"/>
9
+ <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
10
+ <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
11
+ <script id="tailwind-config">
12
+ tailwind.config = {
13
+ darkMode: "class",
14
+ theme: {
15
+ extend: {
16
+ colors: {
17
+ "primary-fixed": "#e3dfff",
18
+ "surface-dim": "#d2d9f4",
19
+ "tertiary-fixed": "#c9e6ff",
20
+ "on-surface-variant": "#464554",
21
+ "surface": "#faf8ff",
22
+ "surface-container": "#eaedff",
23
+ "outline": "#777586",
24
+ "surface-tint": "#5148d7",
25
+ "secondary-fixed": "#d3e4fe",
26
+ "on-secondary-container": "#54647a",
27
+ "on-primary-container": "#c1beff",
28
+ "on-tertiary-fixed-variant": "#004c6e",
29
+ "on-error-container": "#93000a",
30
+ "background": "#faf8ff",
31
+ "on-secondary-fixed-variant": "#38485d",
32
+ "tertiary-container": "#00577e",
33
+ "primary": "#2a14b4",
34
+ "surface-container-highest": "#dae2fd",
35
+ "on-tertiary-fixed": "#001e2f",
36
+ "on-background": "#131b2e",
37
+ "on-secondary-fixed": "#0b1c30",
38
+ "on-surface": "#131b2e",
39
+ "surface-container-high": "#e2e7ff",
40
+ "primary-container": "#4338ca",
41
+ "primary-fixed-dim": "#c3c0ff",
42
+ "secondary-container": "#d0e1fb",
43
+ "inverse-primary": "#c3c0ff",
44
+ "on-tertiary": "#ffffff",
45
+ "tertiary-fixed-dim": "#89ceff",
46
+ "secondary": "#505f76",
47
+ "surface-container-lowest": "#ffffff",
48
+ "on-tertiary-container": "#84cdff",
49
+ "secondary-fixed-dim": "#b7c8e1",
50
+ "tertiary": "#003f5c",
51
+ "error": "#ba1a1a",
52
+ "on-primary-fixed-variant": "#372abf",
53
+ "on-error": "#ffffff",
54
+ "on-primary": "#ffffff",
55
+ "outline-variant": "#c7c4d7",
56
+ "on-primary-fixed": "#100069",
57
+ "surface-container-low": "#f2f3ff",
58
+ "surface-variant": "#dae2fd",
59
+ "on-secondary": "#ffffff",
60
+ "inverse-surface": "#283044",
61
+ "error-container": "#ffdad6",
62
+ "surface-bright": "#faf8ff",
63
+ "inverse-on-surface": "#eef0ff"
64
+ },
65
+ fontFamily: {
66
+ "headline": ["Space Grotesk"],
67
+ "body": ["Inter"],
68
+ "label": ["Inter"]
69
+ },
70
+ borderRadius: {"DEFAULT": "0.25rem", "lg": "1rem", "xl": "1.5rem", "full": "9999px"},
71
+ },
72
+ },
73
+ }
74
+ </script>
75
+ <style>
76
+ .material-symbols-outlined {
77
+ font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
78
+ vertical-align: middle;
79
+ }
80
+ .code-editor-bg {
81
+ background-image: radial-gradient(circle at 2px 2px, rgba(199, 196, 215, 0.2) 1px, transparent 0);
82
+ background-size: 24px 24px;
83
+ }
84
+ .custom-scrollbar::-webkit-scrollbar {
85
+ width: 6px;
86
+ }
87
+ .custom-scrollbar::-webkit-scrollbar-track {
88
+ background: transparent;
89
+ }
90
+ .custom-scrollbar::-webkit-scrollbar-thumb {
91
+ background: #c7c4d7;
92
+ border-radius: 10px;
93
+ }
94
+ </style>
95
+ </head>
96
+ <body class="bg-background text-on-background font-body selection:bg-primary-fixed selection:text-on-primary-fixed">
97
+ <!-- TopNavBar -->
98
+ <nav class="fixed top-0 w-full z-50 h-20 bg-white/80 backdrop-blur-2xl dark:bg-slate-900/80 shadow-[0_24px_48px_-12px_rgba(19,27,46,0.08)]">
99
+ <div class="flex justify-between items-center max-w-7xl mx-auto px-8 w-full h-full">
100
+ <div class="flex items-center gap-12">
101
+ <span class="text-2xl font-bold tracking-tighter text-indigo-900 dark:text-white font-['Space_Grotesk']">Alchemist</span>
102
+ <div class="hidden md:flex items-center gap-8">
103
+ <a class="text-indigo-700 dark:text-indigo-300 font-semibold border-b-2 border-indigo-600 font-['Space_Grotesk'] text-base tracking-tight" href="#">Converter</a>
104
+ <a class="text-slate-500 dark:text-slate-400 hover:text-indigo-600 transition-colors font-['Space_Grotesk'] text-base tracking-tight" href="#">History</a>
105
+ <a class="text-slate-500 dark:text-slate-400 hover:text-indigo-600 transition-colors font-['Space_Grotesk'] text-base tracking-tight" href="#">Documentation</a>
106
+ </div>
107
+ </div>
108
+ <div class="flex items-center gap-4">
109
+ <button class="px-6 py-2 rounded-lg text-indigo-700 dark:text-indigo-400 font-medium hover:bg-slate-100/50 transition-all active:scale-95 duration-200">Sign In</button>
110
+ <button class="bg-gradient-to-br from-primary to-primary-container text-white px-6 py-2 rounded-lg font-medium shadow-lg hover:shadow-indigo-200 transition-all active:scale-95 duration-200">Start Transmuting</button>
111
+ </div>
112
+ </div>
113
+ </nav>
114
+ <main class="pt-32 pb-20 px-8 max-w-[1600px] mx-auto min-h-screen">
115
+ <!-- Hero Section -->
116
+ <header class="mb-16 max-w-3xl">
117
+ <h1 class="font-headline text-5xl md:text-6xl font-bold text-on-background tracking-tight leading-[1.1] mb-6">
118
+ Refine Raw Data into <span class="text-transparent bg-clip-text bg-gradient-to-r from-primary to-primary-container">Intelligence</span>
119
+ </h1>
120
+ <p class="text-lg text-secondary leading-relaxed font-light">
121
+ A high-precision CSV-to-JSON utility for developers who value technical elegance. No telemetry, no clutter, just pure data transmutation.
122
+ </p>
123
+ </header>
124
+ <!-- Main Workspace -->
125
+ <div class="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
126
+ <!-- Sidebar: Parsing Options -->
127
+ <aside class="lg:col-span-3 space-y-6">
128
+ <div class="bg-surface-container-low rounded-xl p-6 space-y-8">
129
+ <div>
130
+ <h3 class="font-headline text-sm font-bold uppercase tracking-widest text-secondary mb-6">Transmutation Rules</h3>
131
+ <div class="space-y-6">
132
+ <div class="flex items-center justify-between group">
133
+ <label class="text-sm font-medium text-on-surface-variant group-hover:text-primary transition-colors cursor-pointer">Header Row</label>
134
+ <button class="w-12 h-6 bg-primary rounded-full relative p-1 transition-colors">
135
+ <div class="w-4 h-4 bg-white rounded-full translate-x-6 transition-transform"></div>
136
+ </button>
137
+ </div>
138
+ <div class="flex items-center justify-between group">
139
+ <label class="text-sm font-medium text-on-surface-variant group-hover:text-primary transition-colors cursor-pointer">Type Inference</label>
140
+ <button class="w-12 h-6 bg-primary rounded-full relative p-1 transition-colors">
141
+ <div class="w-4 h-4 bg-white rounded-full translate-x-6 transition-transform"></div>
142
+ </button>
143
+ </div>
144
+ <div class="space-y-2">
145
+ <label class="text-xs font-bold text-outline uppercase tracking-tighter">Delimiter</label>
146
+ <div class="relative">
147
+ <select class="w-full bg-surface-container-lowest border-none rounded-lg py-3 px-4 text-sm text-on-surface focus:ring-2 focus:ring-primary/20 appearance-none">
148
+ <option>Comma (,)</option>
149
+ <option>Semicolon (;)</option>
150
+ <option>Tab (\t)</option>
151
+ <option>Pipe (|)</option>
152
+ </select>
153
+ <span class="material-symbols-outlined absolute right-3 top-3 text-outline pointer-events-none">expand_more</span>
154
+ </div>
155
+ </div>
156
+ <div class="space-y-2">
157
+ <label class="text-xs font-bold text-outline uppercase tracking-tighter">JSON Indentation</label>
158
+ <div class="grid grid-cols-3 gap-2">
159
+ <button class="py-2 text-xs font-medium bg-primary-fixed text-on-primary-fixed-variant rounded-lg">2 Space</button>
160
+ <button class="py-2 text-xs font-medium bg-surface-container-lowest text-secondary hover:bg-white rounded-lg transition-colors">4 Space</button>
161
+ <button class="py-2 text-xs font-medium bg-surface-container-lowest text-secondary hover:bg-white rounded-lg transition-colors">Minify</button>
162
+ </div>
163
+ </div>
164
+ </div>
165
+ </div>
166
+ <div class="pt-6 border-t border-outline-variant/20">
167
+ <button class="w-full bg-gradient-to-br from-primary to-primary-container text-white py-4 rounded-xl font-headline font-bold text-lg shadow-xl shadow-indigo-100 flex items-center justify-center gap-3 active:scale-95 transition-transform">
168
+ <span class="material-symbols-outlined" style="font-variation-settings: 'FILL' 1;">auto_fix_high</span>
169
+ Convert
170
+ </button>
171
+ </div>
172
+ </div>
173
+ <!-- Stats/Info Bento -->
174
+ <div class="grid grid-cols-1 gap-4">
175
+ <div class="bg-surface-container rounded-xl p-5 flex items-center gap-4">
176
+ <div class="w-10 h-10 bg-tertiary-fixed rounded-lg flex items-center justify-center text-on-tertiary-fixed">
177
+ <span class="material-symbols-outlined">bolt</span>
178
+ </div>
179
+ <div>
180
+ <p class="text-xs text-secondary">Processing Speed</p>
181
+ <p class="text-sm font-bold">1.2ms / MB</p>
182
+ </div>
183
+ </div>
184
+ </div>
185
+ </aside>
186
+ <!-- Editor Section -->
187
+ <div class="lg:col-span-9 grid grid-cols-1 md:grid-cols-2 gap-8 h-full">
188
+ <!-- Input Area -->
189
+ <div class="flex flex-col h-[700px]">
190
+ <div class="flex items-center justify-between mb-4">
191
+ <div class="flex items-center gap-3">
192
+ <span class="material-symbols-outlined text-primary">description</span>
193
+ <span class="font-headline font-bold tracking-tight">Source CSV</span>
194
+ </div>
195
+ <button class="text-xs font-bold text-primary flex items-center gap-1 hover:underline">
196
+ <span class="material-symbols-outlined text-sm">upload_file</span>
197
+ Upload File
198
+ </button>
199
+ </div>
200
+ <div class="flex-grow bg-surface-container-lowest rounded-xl shadow-[0_24px_48px_-12px_rgba(19,27,46,0.04)] border border-outline-variant/10 relative overflow-hidden flex flex-col">
201
+ <div class="absolute inset-0 code-editor-bg opacity-40 pointer-events-none"></div>
202
+ <div class="flex items-center gap-4 px-6 py-3 border-b border-outline-variant/5 bg-white/50 backdrop-blur-sm z-10">
203
+ <div class="flex gap-1.5">
204
+ <div class="w-2.5 h-2.5 rounded-full bg-red-400/30"></div>
205
+ <div class="w-2.5 h-2.5 rounded-full bg-amber-400/30"></div>
206
+ <div class="w-2.5 h-2.5 rounded-full bg-emerald-400/30"></div>
207
+ </div>
208
+ <span class="text-[10px] font-bold text-outline uppercase tracking-widest">Read Only Mode Off</span>
209
+ </div>
210
+ <textarea class="flex-grow p-8 font-mono text-sm bg-transparent border-none focus:ring-0 resize-none z-10 custom-scrollbar text-on-surface" placeholder="Paste your CSV content here...
211
+ id,name,email,role,status
212
+ 1,Julianne Moore,jmoore@alchemy.io,Lead Architect,active
213
+ 2,Cillian Murphy,cillian@alchemy.io,Senior Researcher,active
214
+ 3,Anya Taylor-Joy,anya@alchemy.io,Data Scientist,pending"></textarea>
215
+ </div>
216
+ </div>
217
+ <!-- Output Area -->
218
+ <div class="flex flex-col h-[700px]">
219
+ <div class="flex items-center justify-between mb-4">
220
+ <div class="flex items-center gap-3">
221
+ <span class="material-symbols-outlined text-primary-container">terminal</span>
222
+ <span class="font-headline font-bold tracking-tight">Intelligence JSON</span>
223
+ </div>
224
+ <div class="flex gap-4">
225
+ <button class="text-xs font-bold text-secondary flex items-center gap-1 hover:text-primary transition-colors">
226
+ <span class="material-symbols-outlined text-sm">content_copy</span>
227
+ Copy
228
+ </button>
229
+ <button class="text-xs font-bold text-secondary flex items-center gap-1 hover:text-primary transition-colors">
230
+ <span class="material-symbols-outlined text-sm">download</span>
231
+ Download
232
+ </button>
233
+ </div>
234
+ </div>
235
+ <div class="flex-grow bg-surface-container-low rounded-xl border border-outline-variant/10 relative overflow-hidden flex flex-col">
236
+ <div class="absolute inset-0 code-editor-bg opacity-40 pointer-events-none"></div>
237
+ <div class="flex items-center justify-between px-6 py-3 border-b border-outline-variant/5 bg-white/30 backdrop-blur-sm z-10">
238
+ <span class="text-[10px] font-bold text-outline uppercase tracking-widest">JSON Output</span>
239
+ <div class="flex items-center gap-2">
240
+ <div class="w-2 h-2 rounded-full bg-primary animate-pulse"></div>
241
+ <span class="text-[10px] text-primary font-bold uppercase tracking-widest">Valid Syntax</span>
242
+ </div>
243
+ </div>
244
+ <pre class="flex-grow p-8 font-mono text-sm text-indigo-900/80 z-10 custom-scrollbar overflow-auto"><code>[
245
+ {
246
+ "id": 1,
247
+ "name": "Julianne Moore",
248
+ "email": "jmoore@alchemy.io",
249
+ "role": "Lead Architect",
250
+ "status": "active"
251
+ },
252
+ {
253
+ "id": 2,
254
+ "name": "Cillian Murphy",
255
+ "email": "cillian@alchemy.io",
256
+ "role": "Senior Researcher",
257
+ "status": "active"
258
+ },
259
+ {
260
+ "id": 3,
261
+ "name": "Anya Taylor-Joy",
262
+ "email": "anya@alchemy.io",
263
+ "role": "Data Scientist",
264
+ "status": "pending"
265
+ }
266
+ ]</code></pre>
267
+ </div>
268
+ </div>
269
+ </div>
270
+ </div>
271
+ <!-- Ad/Promo Asymmetric Section -->
272
+ <section class="mt-24 grid grid-cols-1 md:grid-cols-12 gap-8 items-center bg-primary-fixed/30 rounded-3xl p-12 overflow-hidden relative">
273
+ <div class="md:col-span-7 z-10">
274
+ <h2 class="font-headline text-3xl font-bold mb-4">Enterprise Grade Security</h2>
275
+ <p class="text-secondary max-w-lg mb-8 leading-relaxed">
276
+ All processing happens client-side. Your raw data never touches our servers, ensuring your sensitive CSV files remain strictly within your laboratory.
277
+ </p>
278
+ <div class="flex gap-6">
279
+ <div class="flex items-center gap-2">
280
+ <span class="material-symbols-outlined text-primary">verified_user</span>
281
+ <span class="text-sm font-bold">100% Local</span>
282
+ </div>
283
+ <div class="flex items-center gap-2">
284
+ <span class="material-symbols-outlined text-primary">encrypted</span>
285
+ <span class="text-sm font-bold">No Telemetry</span>
286
+ </div>
287
+ </div>
288
+ </div>
289
+ <div class="md:col-span-5 relative h-64 md:h-full">
290
+ <img alt="abstract geometric representation of security and privacy using interlocking crystalline shapes in shades of indigo and crystal" class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full h-full object-contain mix-blend-multiply opacity-80" data-alt="minimalist 3d abstract visualization of digital security with translucent indigo glass shields and white glowing particles in a studio setting" src="https://lh3.googleusercontent.com/aida-public/AB6AXuBJzzRBomvg1hXct3tUM1jS_0kfAqEghXcwbz0vX7Xw3hJSUWlcvSLW4g-uTSNKSX8ChaNeH1R9cZ2dqPNsNJiHHwR_4N9LkRC621H9kmOFF1JO1ic1ZhfB67nzTXFd5YBR50Nuge0SxLtBnd7hLDiVJE5sPCPE05_HYb62V0bda_YZHo4wmbUGA4Vlk1YV1yEyoG5LO97jDuLNohSfdvXJATQzckjg__u198oWYUiV74G6Ah5HrOOQbfAyHxc-rBXultfOM0NtFAg"/>
291
+ </div>
292
+ </section>
293
+ </main>
294
+ <!-- Footer -->
295
+ <footer class="bg-slate-50 dark:bg-slate-950 w-full py-16">
296
+ <div class="flex flex-col md:flex-row justify-between items-center max-w-7xl mx-auto px-8 gap-6">
297
+ <div class="flex flex-col items-center md:items-start gap-2">
298
+ <span class="font-['Space_Grotesk'] font-bold text-slate-900 dark:text-slate-100 text-xl">Alchemist</span>
299
+ <p class="font-['Inter'] text-sm tracking-normal text-slate-500 dark:text-slate-500">© 2024 Alchemist. Precision Data Transmutation.</p>
300
+ </div>
301
+ <div class="flex gap-10">
302
+ <a class="text-slate-500 dark:text-slate-500 hover:text-indigo-700 dark:hover:text-indigo-300 transition-all font-['Inter'] text-sm tracking-normal" href="#">Terms</a>
303
+ <a class="text-slate-500 dark:text-slate-500 hover:text-indigo-700 dark:hover:text-indigo-300 transition-all font-['Inter'] text-sm tracking-normal" href="#">Privacy</a>
304
+ <a class="text-slate-500 dark:text-slate-500 hover:text-indigo-700 dark:hover:text-indigo-300 transition-all font-['Inter'] text-sm tracking-normal" href="#">API</a>
305
+ <a class="text-slate-500 dark:text-slate-500 hover:text-indigo-700 dark:hover:text-indigo-300 transition-all font-['Inter'] text-sm tracking-normal" href="#">Support</a>
306
+ </div>
307
+ </div>
308
+ </footer>
309
+ </body></html>
package/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
+ /// <reference types="node" />
2
+
1
3
  declare module 'convert-csv-to-json' {
4
+ /**
5
+ * Singleton parser instance with chainable CSV-to-JSON configuration methods.
6
+ */
2
7
  export class ConvertCsvToJson {
3
8
  /**
4
9
  * Prints a digit as Number type (for example 32 instead of '32')
@@ -121,22 +126,45 @@ declare module 'convert-csv-to-json' {
121
126
  */
122
127
  getJsonFromFileStreamingAsync(filePath: string): Promise<any[]>;
123
128
 
129
+ /**
130
+ * Parse a raw CSV string asynchronously and return parsed JSON objects
131
+ */
132
+ csvStringToJsonAsync(csvString: string, options?: { raw?: boolean }): Promise<any[]>;
133
+
134
+ /**
135
+ * Parse a raw CSV string asynchronously and return a JSON string
136
+ */
137
+ csvStringToJsonStringifiedAsync(csvString: string): Promise<string>;
138
+
139
+ /**
140
+ * Parses a CSV file and writes a JSON file asynchronously.
141
+ * @param inputFileName Path to the input CSV file
142
+ * @param outputFileName Path to the output JSON file
143
+ */
144
+ generateJsonFileFromCsvAsync(inputFileName: string, outputFileName: string): Promise<void>;
145
+
146
+ /**
147
+ * Parses a CSV string and returns an array of JSON objects.
148
+ * @param csvString CSV content as a string
149
+ */
124
150
  csvStringToJson(csvString: string): any[];
125
151
 
126
152
  /**
127
- * Parses a csv string and returns a JSON string (validated)
128
- * @param {csvString} csvString CSV content as string
129
- * @return {string} JSON stringified result
130
- */
153
+ * Parses a CSV string and returns a validated JSON string.
154
+ * @param csvString CSV content as string
155
+ * @returns JSON stringified result
156
+ */
131
157
  csvStringToJsonStringified(csvString: string): string;
132
-
133
158
 
134
159
  }
135
160
  const converter: ConvertCsvToJson;
161
+ /**
162
+ * Default singleton parser instance for convert-csv-to-json.
163
+ */
136
164
  export default converter;
137
165
 
138
166
  /**
139
- * Browser API exposes parsing helpers for browser environments
167
+ * Browser API exposes parsing helpers for browser environments.
140
168
  */
141
169
  export interface BrowserApi {
142
170
  formatValueByType(active: boolean): this;
@@ -148,9 +176,28 @@ declare module 'convert-csv-to-json' {
148
176
  ignoreColumnIndexes(indexes: number[]): this;
149
177
  mapRows(mapperFn: (row: any, index: number) => any | null): this;
150
178
 
179
+ /**
180
+ * Parses a CSV string and returns an array of JSON objects.
181
+ * @param csvString CSV content as a string
182
+ */
151
183
  csvStringToJson(csvString: string): any[];
184
+
185
+ /**
186
+ * Parses a CSV string and returns a JSON string.
187
+ * @param csvString CSV content as a string
188
+ */
152
189
  csvStringToJsonStringified(csvString: string): string;
190
+
191
+ /**
192
+ * Parses a CSV string asynchronously and returns an array of JSON objects.
193
+ * @param csvString CSV content as a string
194
+ */
153
195
  csvStringToJsonAsync(csvString: string): Promise<any[]>;
196
+
197
+ /**
198
+ * Parses a CSV string asynchronously and returns a validated JSON string.
199
+ * @param csvString CSV content as a string
200
+ */
154
201
  csvStringToJsonStringifiedAsync(csvString: string): Promise<string>;
155
202
 
156
203
  /**