@mitre/hdf-utilities 3.7.0 → 3.7.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.
Files changed (2) hide show
  1. package/README.md +21 -15
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -203,23 +203,25 @@ if (isValidCsv(fileContent)) {
203
203
  const parsed = parseCsv(fileContent);
204
204
  }
205
205
 
206
- // Sanitize individual values (escape special characters)
207
- const safe = sanitizeCsvValue('Value with "quotes" and, commas');
208
- console.log(safe); // "Value with ""quotes"" and, commas"
206
+ // Sanitize individual values (neutralize formula injection)
207
+ console.log(sanitizeCsvValue('=1+1')); // "'=1+1"
208
+ console.log(sanitizeCsvValue(' -2+3')); // "' -2+3" (leading whitespace kept)
209
+ console.log(sanitizeCsvValue('Value with "quotes" and, commas'));
210
+ // 'Value with "quotes" and, commas' — unchanged; quoting is the serializer's job
209
211
 
210
212
  // Sanitize arrays
211
- const tags = ['AC-1', 'AC-2', null, undefined];
213
+ const tags = ['AC-1', '=cmd|calc', null];
212
214
  const safeTags = sanitizeCsvArray(tags);
213
- console.log(safeTags); // ['AC-1', 'AC-2', '', '']
215
+ console.log(safeTags); // ['AC-1', "'=cmd|calc", 'null']
214
216
 
215
- // Sanitize entire objects
217
+ // Sanitize entire objects (flat string map; values stringified)
216
218
  const requirement = {
217
219
  id: 'REQ-001',
218
220
  title: 'Title with "quotes"',
219
221
  tags: ['AC-1', null]
220
222
  };
221
223
  const safeReq = sanitizeCsvObject(requirement);
222
- // All string values escaped, nulls converted to empty strings
224
+ // { id: 'REQ-001', title: 'Title with "quotes"', tags: 'AC-1,' }
223
225
  ```
224
226
 
225
227
  ## API Reference
@@ -357,7 +359,7 @@ Parse CSV string to array of objects.
357
359
 
358
360
  - **Parameters:**
359
361
  - `csv` - CSV string to parse
360
- - `options` - PapaParse options (optional)
362
+ - `options` - `Partial<CsvParseOptions>` (header, delimiter, typing and size limit; optional)
361
363
  - **Returns:** Array of objects (headers become keys)
362
364
  - **Throws:** Error if CSV is malformed
363
365
 
@@ -367,7 +369,7 @@ Build CSV string from array of objects.
367
369
 
368
370
  - **Parameters:**
369
371
  - `data` - Array of objects to convert
370
- - `options` - PapaParse unparse options (optional)
372
+ - `options` - `Partial<CsvBuildOptions> & { sanitize?: boolean }` (optional)
371
373
  - **Returns:** CSV string with headers
372
374
 
373
375
  #### `isValidCsv(csv: string): boolean`
@@ -380,27 +382,31 @@ Check if string can be parsed as CSV.
380
382
 
381
383
  #### `sanitizeCsvValue(value: unknown): string`
382
384
 
383
- Escape value for safe CSV output.
385
+ Neutralize formula injection in a value bound for CSV.
384
386
 
385
387
  - **Parameters:**
386
388
  - `value` - Value to sanitize
387
- - **Returns:** Escaped string (quotes escaped, nulls → empty string)
389
+ - **Returns:** `String(value)`, prefixed with `'` when its first non-whitespace
390
+ character is `=`, `+`, `-`, `@`, `|`, or `%`. Nothing else is altered: quotes,
391
+ commas and newlines are passed through for the serializer to quote, and `null`
392
+ / `undefined` stringify to `"null"` / `"undefined"`.
388
393
 
389
394
  #### `sanitizeCsvArray(values: unknown[]): string[]`
390
395
 
391
- Sanitize array of values for CSV.
396
+ Apply `sanitizeCsvValue` to each element.
392
397
 
393
398
  - **Parameters:**
394
399
  - `values` - Array to sanitize
395
400
  - **Returns:** Array of sanitized strings
396
401
 
397
- #### `sanitizeCsvObject<T>(obj: T): T`
402
+ #### `sanitizeCsvObject<T extends Record<string, unknown>>(obj: T): Record<string, string>`
398
403
 
399
- Recursively sanitize all string values in object.
404
+ Apply `sanitizeCsvValue` to each own enumerable value of an object.
400
405
 
401
406
  - **Parameters:**
402
407
  - `obj` - Object to sanitize
403
- - **Returns:** New object with sanitized values
408
+ - **Returns:** A flat string map — one level only, every value stringified (an
409
+ array value becomes its comma-joined `String()` form)
404
410
 
405
411
  ## Development
406
412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitre/hdf-utilities",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "Utility functions for HDF libraries (JSON parsing, validation helpers)",
5
5
  "publishConfig": {
6
6
  "access": "public"