@mitre/hdf-utilities 3.0.1 → 3.1.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.
@@ -1,61 +1,52 @@
1
- export { findValuesByKey as findJsonValues } from '../object/index.js';
1
+ import { findValuesByKey } from "../object/index.js";
2
+ //#region src/json/index.ts
2
3
  /**
3
- * Safely parse a JSON string
4
- * @param input - JSON string to parse
5
- * @returns Parsed JSON value
6
- * @throws Error if input is not valid JSON
7
- */
8
- export function parseJSON(input) {
9
- if (typeof input !== 'string') {
10
- throw new Error('Input must be a string');
11
- }
12
- if (input.trim() === '') {
13
- throw new Error('Input cannot be empty');
14
- }
15
- try {
16
- return JSON.parse(input);
17
- }
18
- catch (error) {
19
- throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
20
- }
4
+ * Safely parse a JSON string
5
+ * @param input - JSON string to parse
6
+ * @returns Parsed JSON value
7
+ * @throws Error if input is not valid JSON
8
+ */
9
+ function parseJSON(input) {
10
+ if (typeof input !== "string") throw new Error("Input must be a string");
11
+ if (input.trim() === "") throw new Error("Input cannot be empty");
12
+ try {
13
+ return JSON.parse(input);
14
+ } catch (error) {
15
+ throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
16
+ }
21
17
  }
22
18
  /**
23
- * Safely stringify a value to JSON
24
- * @param value - Value to stringify
25
- * @param options - Stringification options
26
- * @returns JSON string
27
- * @throws Error if value contains circular references or cannot be stringified
28
- */
29
- export function stringifyJSON(value, options = {}) {
30
- const { pretty = false, indent = 2 } = options;
31
- try {
32
- if (pretty) {
33
- return JSON.stringify(value, null, indent);
34
- }
35
- return JSON.stringify(value);
36
- }
37
- catch (error) {
38
- throw new Error(`Failed to stringify JSON: ${error instanceof Error ? error.message : String(error)}`);
39
- }
19
+ * Safely stringify a value to JSON
20
+ * @param value - Value to stringify
21
+ * @param options - Stringification options
22
+ * @returns JSON string
23
+ * @throws Error if value contains circular references or cannot be stringified
24
+ */
25
+ function stringifyJSON(value, options = {}) {
26
+ const { pretty = false, indent = 2 } = options;
27
+ try {
28
+ if (pretty) return JSON.stringify(value, null, indent);
29
+ return JSON.stringify(value);
30
+ } catch (error) {
31
+ throw new Error(`Failed to stringify JSON: ${error instanceof Error ? error.message : String(error)}`);
32
+ }
40
33
  }
41
34
  /**
42
- * Check if a string is valid JSON
43
- * @param input - String to validate
44
- * @returns true if input is valid JSON, false otherwise
45
- */
46
- export function isValidJSON(input) {
47
- if (typeof input !== 'string') {
48
- return false;
49
- }
50
- if (input.trim() === '') {
51
- return false;
52
- }
53
- try {
54
- JSON.parse(input);
55
- return true;
56
- }
57
- catch {
58
- return false;
59
- }
35
+ * Check if a string is valid JSON
36
+ * @param input - String to validate
37
+ * @returns true if input is valid JSON, false otherwise
38
+ */
39
+ function isValidJSON(input) {
40
+ if (typeof input !== "string") return false;
41
+ if (input.trim() === "") return false;
42
+ try {
43
+ JSON.parse(input);
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
60
48
  }
49
+ //#endregion
50
+ export { findValuesByKey as findJsonValues, isValidJSON, parseJSON, stringifyJSON };
51
+
61
52
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAYvE;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAc,KAAa;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAC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":["export { findValuesByKey as findJsonValues } from '../object/index.js';\n\n/**\n * Options for JSON stringification\n */\nexport interface StringifyOptions {\n /** Enable pretty printing with indentation */\n pretty?: boolean;\n /** Number of spaces for indentation (default: 2) */\n indent?: number;\n}\n\n/**\n * Safely parse a JSON string\n * @param input - JSON string to parse\n * @returns Parsed JSON value\n * @throws Error if input is not valid JSON\n */\nexport function parseJSON<T = unknown>(input: string): T {\n if (typeof input !== 'string') {\n throw new Error('Input must be a string');\n }\n\n if (input.trim() === '') {\n throw new Error('Input cannot be empty');\n }\n\n try {\n return JSON.parse(input) as T;\n } catch (error) {\n throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Safely stringify a value to JSON\n * @param value - Value to stringify\n * @param options - Stringification options\n * @returns JSON string\n * @throws Error if value contains circular references or cannot be stringified\n */\nexport function stringifyJSON(value: unknown, options: StringifyOptions = {}): string {\n const { pretty = false, indent = 2 } = options;\n\n try {\n if (pretty) {\n return JSON.stringify(value, null, indent);\n }\n return JSON.stringify(value);\n } catch (error) {\n throw new Error(`Failed to stringify JSON: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Check if a string is valid JSON\n * @param input - String to validate\n * @returns true if input is valid JSON, false otherwise\n */\nexport function isValidJSON(input: unknown): boolean {\n if (typeof input !== 'string') {\n return false;\n }\n\n if (input.trim() === '') {\n return false;\n }\n\n try {\n JSON.parse(input);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,UAAuB,OAAkB;AACvD,KAAI,OAAO,UAAU,SACnB,OAAM,IAAI,MAAM,yBAAyB;AAG3C,KAAI,MAAM,MAAM,KAAK,GACnB,OAAM,IAAI,MAAM,wBAAwB;AAG1C,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;UACjB,OAAO;AACd,QAAM,IAAI,MAAM,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG;;;;;;;;;;AAW9F,SAAgB,cAAc,OAAgB,UAA4B,EAAE,EAAU;CACpF,MAAM,EAAE,SAAS,OAAO,SAAS,MAAM;AAEvC,KAAI;AACF,MAAI,OACF,QAAO,KAAK,UAAU,OAAO,MAAM,OAAO;AAE5C,SAAO,KAAK,UAAU,MAAM;UACrB,OAAO;AACd,QAAM,IAAI,MAAM,6BAA6B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG;;;;;;;;AAS1G,SAAgB,YAAY,OAAyB;AACnD,KAAI,OAAO,UAAU,SACnB,QAAO;AAGT,KAAI,MAAM,MAAM,KAAK,GACnB,QAAO;AAGT,KAAI;AACF,OAAK,MAAM,MAAM;AACjB,SAAO;SACD;AACN,SAAO"}
@@ -1,3 +1,4 @@
1
+ //#region src/object/index.d.ts
1
2
  /**
2
3
  * Generic object query utilities for traversing parsed data structures.
3
4
  *
@@ -16,7 +17,7 @@
16
17
  * @param maxDepth - Maximum recursion depth (default 100). Nodes beyond this depth are silently skipped.
17
18
  * @returns Flat array of all matched values
18
19
  */
19
- export declare function findValuesByKey(obj: unknown, key: string, maxDepth?: number): unknown[];
20
+ declare function findValuesByKey(obj: unknown, key: string, maxDepth?: number): unknown[];
20
21
  /**
21
22
  * Extract all values for a named field from an array of objects.
22
23
  *
@@ -26,7 +27,7 @@ export declare function findValuesByKey(obj: unknown, key: string, maxDepth?: nu
26
27
  * @param column - Property name to extract
27
28
  * @returns Array of values for that column
28
29
  */
29
- export declare function extractColumn(rows: Record<string, unknown>[], column: string): unknown[];
30
+ declare function extractColumn(rows: Record<string, unknown>[], column: string): unknown[];
30
31
  /**
31
32
  * Filter an array of objects to rows where a column matches a value.
32
33
  *
@@ -37,5 +38,7 @@ export declare function extractColumn(rows: Record<string, unknown>[], column: s
37
38
  * @param value - Value to match against
38
39
  * @returns Filtered array of matching rows
39
40
  */
40
- export declare function findRows(rows: Record<string, unknown>[], column: string, value: unknown): Record<string, unknown>[];
41
+ declare function findRows(rows: Record<string, unknown>[], column: string, value: unknown): Record<string, unknown>[];
42
+ //#endregion
43
+ export { extractColumn, findRows, findValuesByKey };
41
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,QAAQ,SAAM,GACb,OAAO,EAAE,CAIX;AAiCD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,MAAM,EAAE,MAAM,GACb,OAAO,EAAE,CAEX;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAE3B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/object/index.ts"],"mappings":";;AAmBA;;;;;;;;;AAkDA;;;;;;;;iBAlDgB,eAAA,CACd,GAAA,WACA,GAAA,UACA,QAAA;AAgEF;;;;;;;;;AAAA,iBAjBgB,aAAA,CACd,IAAA,EAAM,MAAA,qBACN,MAAA;;;;;;;;;;;iBAec,QAAA,CACd,IAAA,EAAM,MAAA,qBACN,MAAA,UACA,KAAA,YACC,MAAA"}
@@ -1,70 +1,64 @@
1
+ //#region src/object/index.ts
1
2
  /**
2
- * Generic object query utilities for traversing parsed data structures.
3
- *
4
- * These functions work on any plain JS objects — parsed XML, JSON, or CSV rows
5
- * are all objects by the time converters work with them.
6
- */
3
+ * Generic object query utilities for traversing parsed data structures.
4
+ *
5
+ * These functions work on any plain JS objects — parsed XML, JSON, or CSV rows
6
+ * are all objects by the time converters work with them.
7
+ */
7
8
  /**
8
- * Recursively find all values for a given key anywhere in a nested object tree.
9
- *
10
- * Walks the entire tree depth-first. When a property matching `key` is found,
11
- * its value is collected. Recurse continues into all child values (objects and
12
- * arrays) regardless of whether the current level matched.
13
- *
14
- * @param obj - Object tree to search (parsed XML, JSON, etc.)
15
- * @param key - Property name to search for
16
- * @param maxDepth - Maximum recursion depth (default 100). Nodes beyond this depth are silently skipped.
17
- * @returns Flat array of all matched values
18
- */
19
- export function findValuesByKey(obj, key, maxDepth = 100) {
20
- const results = [];
21
- walk(obj, key, results, 0, maxDepth);
22
- return results;
9
+ * Recursively find all values for a given key anywhere in a nested object tree.
10
+ *
11
+ * Walks the entire tree depth-first. When a property matching `key` is found,
12
+ * its value is collected. Recurse continues into all child values (objects and
13
+ * arrays) regardless of whether the current level matched.
14
+ *
15
+ * @param obj - Object tree to search (parsed XML, JSON, etc.)
16
+ * @param key - Property name to search for
17
+ * @param maxDepth - Maximum recursion depth (default 100). Nodes beyond this depth are silently skipped.
18
+ * @returns Flat array of all matched values
19
+ */
20
+ function findValuesByKey(obj, key, maxDepth = 100) {
21
+ const results = [];
22
+ walk(obj, key, results, 0, maxDepth);
23
+ return results;
23
24
  }
24
25
  function walk(node, key, results, depth, maxDepth) {
25
- if (depth > maxDepth) {
26
- return;
27
- }
28
- if (node === null || node === undefined || typeof node !== 'object') {
29
- return;
30
- }
31
- if (Array.isArray(node)) {
32
- for (const item of node) {
33
- walk(item, key, results, depth + 1, maxDepth);
34
- }
35
- return;
36
- }
37
- const record = node;
38
- if (key in record) {
39
- results.push(record[key]);
40
- }
41
- for (const value of Object.values(record)) {
42
- walk(value, key, results, depth + 1, maxDepth);
43
- }
26
+ if (depth > maxDepth) return;
27
+ if (node === null || node === void 0 || typeof node !== "object") return;
28
+ if (Array.isArray(node)) {
29
+ for (const item of node) walk(item, key, results, depth + 1, maxDepth);
30
+ return;
31
+ }
32
+ const record = node;
33
+ if (key in record) results.push(record[key]);
34
+ for (const value of Object.values(record)) walk(value, key, results, depth + 1, maxDepth);
44
35
  }
45
36
  /**
46
- * Extract all values for a named field from an array of objects.
47
- *
48
- * Rows where the column is `undefined` are skipped.
49
- *
50
- * @param rows - Array of objects (e.g. parsed CSV rows)
51
- * @param column - Property name to extract
52
- * @returns Array of values for that column
53
- */
54
- export function extractColumn(rows, column) {
55
- return rows.map((r) => r[column]).filter((v) => v !== undefined);
37
+ * Extract all values for a named field from an array of objects.
38
+ *
39
+ * Rows where the column is `undefined` are skipped.
40
+ *
41
+ * @param rows - Array of objects (e.g. parsed CSV rows)
42
+ * @param column - Property name to extract
43
+ * @returns Array of values for that column
44
+ */
45
+ function extractColumn(rows, column) {
46
+ return rows.map((r) => r[column]).filter((v) => v !== void 0);
56
47
  }
57
48
  /**
58
- * Filter an array of objects to rows where a column matches a value.
59
- *
60
- * Uses strict equality (`===`).
61
- *
62
- * @param rows - Array of objects to filter
63
- * @param column - Property name to check
64
- * @param value - Value to match against
65
- * @returns Filtered array of matching rows
66
- */
67
- export function findRows(rows, column, value) {
68
- return rows.filter((r) => r[column] === value);
49
+ * Filter an array of objects to rows where a column matches a value.
50
+ *
51
+ * Uses strict equality (`===`).
52
+ *
53
+ * @param rows - Array of objects to filter
54
+ * @param column - Property name to check
55
+ * @param value - Value to match against
56
+ * @returns Filtered array of matching rows
57
+ */
58
+ function findRows(rows, column, value) {
59
+ return rows.filter((r) => r[column] === value);
69
60
  }
61
+ //#endregion
62
+ export { extractColumn, findRows, findValuesByKey };
63
+
70
64
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAY,EACZ,GAAW,EACX,QAAQ,GAAG,GAAG;IAEd,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE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AA+B,EAC/B,MAAc,EACd,KAAc;IAEd,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;AACjD,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/object/index.ts"],"sourcesContent":["/**\n * Generic object query utilities for traversing parsed data structures.\n *\n * These functions work on any plain JS objects — parsed XML, JSON, or CSV rows\n * are all objects by the time converters work with them.\n */\n\n/**\n * Recursively find all values for a given key anywhere in a nested object tree.\n *\n * Walks the entire tree depth-first. When a property matching `key` is found,\n * its value is collected. Recurse continues into all child values (objects and\n * arrays) regardless of whether the current level matched.\n *\n * @param obj - Object tree to search (parsed XML, JSON, etc.)\n * @param key - Property name to search for\n * @param maxDepth - Maximum recursion depth (default 100). Nodes beyond this depth are silently skipped.\n * @returns Flat array of all matched values\n */\nexport function findValuesByKey(\n obj: unknown,\n key: string,\n maxDepth = 100,\n): unknown[] {\n const results: unknown[] = [];\n walk(obj, key, results, 0, maxDepth);\n return results;\n}\n\nfunction walk(\n node: unknown,\n key: string,\n results: unknown[],\n depth: number,\n maxDepth: number,\n): void {\n if (depth > maxDepth) {\n return;\n }\n\n if (node === null || node === undefined || typeof node !== 'object') {\n return;\n }\n\n if (Array.isArray(node)) {\n for (const item of node) {\n walk(item, key, results, depth + 1, maxDepth);\n }\n return;\n }\n\n const record = node as Record<string, unknown>;\n if (key in record) {\n results.push(record[key]);\n }\n for (const value of Object.values(record)) {\n walk(value, key, results, depth + 1, maxDepth);\n }\n}\n\n/**\n * Extract all values for a named field from an array of objects.\n *\n * Rows where the column is `undefined` are skipped.\n *\n * @param rows - Array of objects (e.g. parsed CSV rows)\n * @param column - Property name to extract\n * @returns Array of values for that column\n */\nexport function extractColumn(\n rows: Record<string, unknown>[],\n column: string,\n): unknown[] {\n return rows.map((r) => r[column]).filter((v) => v !== undefined);\n}\n\n/**\n * Filter an array of objects to rows where a column matches a value.\n *\n * Uses strict equality (`===`).\n *\n * @param rows - Array of objects to filter\n * @param column - Property name to check\n * @param value - Value to match against\n * @returns Filtered array of matching rows\n */\nexport function findRows(\n rows: Record<string, unknown>[],\n column: string,\n value: unknown,\n): Record<string, unknown>[] {\n return rows.filter((r) => r[column] === value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,gBACd,KACA,KACA,WAAW,KACA;CACX,MAAM,UAAqB,EAAE;AAC7B,MAAK,KAAK,KAAK,SAAS,GAAG,SAAS;AACpC,QAAO;;AAGT,SAAS,KACP,MACA,KACA,SACA,OACA,UACM;AACN,KAAI,QAAQ,SACV;AAGF,KAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,OAAO,SAAS,SACzD;AAGF,KAAI,MAAM,QAAQ,KAAK,EAAE;AACvB,OAAK,MAAM,QAAQ,KACjB,MAAK,MAAM,KAAK,SAAS,QAAQ,GAAG,SAAS;AAE/C;;CAGF,MAAM,SAAS;AACf,KAAI,OAAO,OACT,SAAQ,KAAK,OAAO,KAAK;AAE3B,MAAK,MAAM,SAAS,OAAO,OAAO,OAAO,CACvC,MAAK,OAAO,KAAK,SAAS,QAAQ,GAAG,SAAS;;;;;;;;;;;AAalD,SAAgB,cACd,MACA,QACW;AACX,QAAO,KAAK,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAQ,MAAM,MAAM,KAAA,EAAU;;;;;;;;;;;;AAalE,SAAgB,SACd,MACA,QACA,OAC2B;AAC3B,QAAO,KAAK,QAAQ,MAAM,EAAE,YAAY,MAAM"}
@@ -1,3 +1,4 @@
1
+ //#region src/string/index.d.ts
1
2
  /**
2
3
  * String manipulation utilities for HDF converters.
3
4
  *
@@ -24,7 +25,7 @@
24
25
  * stripHtml('no tags here'); // 'no tags here'
25
26
  * ```
26
27
  */
27
- export declare function stripHtml(html: string): string;
28
+ declare function stripHtml(html: string): string;
28
29
  /**
29
30
  * Parse a timestamp string in various common formats.
30
31
  *
@@ -46,5 +47,7 @@ export declare function stripHtml(html: string): string;
46
47
  * parseTimestamp(''); // null
47
48
  * ```
48
49
  */
49
- export declare function parseTimestamp(s: string): Date | null;
50
+ declare function parseTimestamp(s: string): Date | null;
51
+ //#endregion
52
+ export { parseTimestamp, stripHtml };
50
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAWrD"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/string/index.ts"],"mappings":";;AA2BA;;;;;AA0BA;;;;;;;;;;;;;;;;;;;;iBA1BgB,SAAA,CAAU,IAAA;;;;;;;;;;;;;;;;;;;;;;iBA0BV,cAAA,CAAe,CAAA,WAAY,IAAA"}
@@ -1,62 +1,61 @@
1
+ //#region src/string/index.ts
1
2
  /**
2
- * String manipulation utilities for HDF converters.
3
- *
4
- * These handle common operations on security tool output strings:
5
- * HTML stripping for STIG descriptions and SonarQube messages,
6
- * and multi-format timestamp parsing for tool output dates.
7
- */
3
+ * String manipulation utilities for HDF converters.
4
+ *
5
+ * These handle common operations on security tool output strings:
6
+ * HTML stripping for STIG descriptions and SonarQube messages,
7
+ * and multi-format timestamp parsing for tool output dates.
8
+ */
8
9
  /**
9
- * Remove HTML tags from a string and normalize whitespace.
10
- *
11
- * Strips all HTML/XML tags, collapses multiple whitespace characters
12
- * into single spaces, and trims leading/trailing whitespace.
13
- *
14
- * For XML documents, use {@link extractTextFromXml} from the xml module instead.
15
- * This function is for inline HTML in non-XML strings (STIG descriptions,
16
- * SonarQube messages, etc.).
17
- *
18
- * @param html - String potentially containing HTML tags
19
- * @returns Plain text with tags removed and whitespace normalized
20
- *
21
- * @example
22
- * ```typescript
23
- * stripHtml('<p>hello</p> <b>world</b>'); // 'hello world'
24
- * stripHtml('no tags here'); // 'no tags here'
25
- * ```
26
- */
27
- export function stripHtml(html) {
28
- const stripped = html.replace(/<[^>]*>/g, ' ');
29
- return stripped.replace(/\s+/g, ' ').trim();
10
+ * Remove HTML tags from a string and normalize whitespace.
11
+ *
12
+ * Strips all HTML/XML tags, collapses multiple whitespace characters
13
+ * into single spaces, and trims leading/trailing whitespace.
14
+ *
15
+ * For XML documents, use {@link extractTextFromXml} from the xml module instead.
16
+ * This function is for inline HTML in non-XML strings (STIG descriptions,
17
+ * SonarQube messages, etc.).
18
+ *
19
+ * @param html - String potentially containing HTML tags
20
+ * @returns Plain text with tags removed and whitespace normalized
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * stripHtml('<p>hello</p> <b>world</b>'); // 'hello world'
25
+ * stripHtml('no tags here'); // 'no tags here'
26
+ * ```
27
+ */
28
+ function stripHtml(html) {
29
+ return html.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
30
30
  }
31
31
  /**
32
- * Parse a timestamp string in various common formats.
33
- *
34
- * Attempts to parse the input using the JavaScript Date constructor, which
35
- * supports ISO 8601, RFC 2822, and several other formats natively.
36
- *
37
- * Returns `null` if the input is empty or cannot be parsed.
38
- *
39
- * Equivalent to the Go `ParseTimestamp` in shared/go/converterutil.go.
40
- *
41
- * @param s - Timestamp string to parse
42
- * @returns Parsed Date or null if unparseable
43
- *
44
- * @example
45
- * ```typescript
46
- * parseTimestamp('2024-01-15T10:30:00Z'); // Date object
47
- * parseTimestamp('Mon, 15 Jan 2024 10:30:00 UTC'); // Date object
48
- * parseTimestamp('not a date'); // null
49
- * parseTimestamp(''); // null
50
- * ```
51
- */
52
- export function parseTimestamp(s) {
53
- if (!s || s.trim().length === 0) {
54
- return null;
55
- }
56
- const parsed = new Date(s);
57
- if (isNaN(parsed.getTime())) {
58
- return null;
59
- }
60
- return parsed;
32
+ * Parse a timestamp string in various common formats.
33
+ *
34
+ * Attempts to parse the input using the JavaScript Date constructor, which
35
+ * supports ISO 8601, RFC 2822, and several other formats natively.
36
+ *
37
+ * Returns `null` if the input is empty or cannot be parsed.
38
+ *
39
+ * Equivalent to the Go `ParseTimestamp` in shared/go/converterutil.go.
40
+ *
41
+ * @param s - Timestamp string to parse
42
+ * @returns Parsed Date or null if unparseable
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * parseTimestamp('2024-01-15T10:30:00Z'); // Date object
47
+ * parseTimestamp('Mon, 15 Jan 2024 10:30:00 UTC'); // Date object
48
+ * parseTimestamp('not a date'); // null
49
+ * parseTimestamp(''); // null
50
+ * ```
51
+ */
52
+ function parseTimestamp(s) {
53
+ if (!s || s.trim().length === 0) return null;
54
+ const parsed = new Date(s);
55
+ if (isNaN(parsed.getTime())) return null;
56
+ return parsed;
61
57
  }
58
+ //#endregion
59
+ export { parseTimestamp, stripHtml };
60
+
62
61
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,cAAc,CAAC,CAAS;IACtC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/string/index.ts"],"sourcesContent":["/**\n * String manipulation utilities for HDF converters.\n *\n * These handle common operations on security tool output strings:\n * HTML stripping for STIG descriptions and SonarQube messages,\n * and multi-format timestamp parsing for tool output dates.\n */\n\n/**\n * Remove HTML tags from a string and normalize whitespace.\n *\n * Strips all HTML/XML tags, collapses multiple whitespace characters\n * into single spaces, and trims leading/trailing whitespace.\n *\n * For XML documents, use {@link extractTextFromXml} from the xml module instead.\n * This function is for inline HTML in non-XML strings (STIG descriptions,\n * SonarQube messages, etc.).\n *\n * @param html - String potentially containing HTML tags\n * @returns Plain text with tags removed and whitespace normalized\n *\n * @example\n * ```typescript\n * stripHtml('<p>hello</p> <b>world</b>'); // 'hello world'\n * stripHtml('no tags here'); // 'no tags here'\n * ```\n */\nexport function stripHtml(html: string): string {\n const stripped = html.replace(/<[^>]*>/g, ' ');\n return stripped.replace(/\\s+/g, ' ').trim();\n}\n\n/**\n * Parse a timestamp string in various common formats.\n *\n * Attempts to parse the input using the JavaScript Date constructor, which\n * supports ISO 8601, RFC 2822, and several other formats natively.\n *\n * Returns `null` if the input is empty or cannot be parsed.\n *\n * Equivalent to the Go `ParseTimestamp` in shared/go/converterutil.go.\n *\n * @param s - Timestamp string to parse\n * @returns Parsed Date or null if unparseable\n *\n * @example\n * ```typescript\n * parseTimestamp('2024-01-15T10:30:00Z'); // Date object\n * parseTimestamp('Mon, 15 Jan 2024 10:30:00 UTC'); // Date object\n * parseTimestamp('not a date'); // null\n * parseTimestamp(''); // null\n * ```\n */\nexport function parseTimestamp(s: string): Date | null {\n if (!s || s.trim().length === 0) {\n return null;\n }\n\n const parsed = new Date(s);\n if (isNaN(parsed.getTime())) {\n return null;\n }\n\n return parsed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,UAAU,MAAsB;AAE9C,QADiB,KAAK,QAAQ,YAAY,IAAI,CAC9B,QAAQ,QAAQ,IAAI,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;AAwB7C,SAAgB,eAAe,GAAwB;AACrD,KAAI,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAC5B,QAAO;CAGT,MAAM,SAAS,IAAI,KAAK,EAAE;AAC1B,KAAI,MAAM,OAAO,SAAS,CAAC,CACzB,QAAO;AAGT,QAAO"}
@@ -1,9 +1,7 @@
1
- /**
2
- * XML parsing utilities for HDF converters
3
- * Provides XML parsing with sensible defaults for security tool output
4
- */
5
- import type { X2jOptions, XmlBuilderOptions } from 'fast-xml-parser';
6
- export { findValuesByKey as findXmlValues } from '../object/index.js';
1
+ import { findValuesByKey } from "../object/index.js";
2
+ import { X2jOptions, XmlBuilderOptions } from "fast-xml-parser";
3
+
4
+ //#region src/xml/index.d.ts
7
5
  /**
8
6
  * Parse XML string to JavaScript object
9
7
  *
@@ -18,8 +16,8 @@ export { findValuesByKey as findXmlValues } from '../object/index.js';
18
16
  * // Returns: { root: { item: { id: '1', '#text': 'Test' } } }
19
17
  * ```
20
18
  */
21
- export declare function parseXml(xml: string, options?: Partial<X2jOptions> & {
22
- maxSize?: number;
19
+ declare function parseXml(xml: string, options?: Partial<X2jOptions> & {
20
+ maxSize?: number;
23
21
  }): Record<string, unknown>;
24
22
  /**
25
23
  * Build XML string from JavaScript object
@@ -35,7 +33,7 @@ export declare function parseXml(xml: string, options?: Partial<X2jOptions> & {
35
33
  * // Returns formatted XML string
36
34
  * ```
37
35
  */
38
- export declare function buildXml(obj: Record<string, unknown>, options?: Partial<XmlBuilderOptions>): string;
36
+ declare function buildXml(obj: Record<string, unknown>, options?: Partial<XmlBuilderOptions>): string;
39
37
  /**
40
38
  * Validate if a string is well-formed XML
41
39
  *
@@ -49,7 +47,7 @@ export declare function buildXml(obj: Record<string, unknown>, options?: Partial
49
47
  * isValidXml('not xml'); // false
50
48
  * ```
51
49
  */
52
- export declare function isValidXml(xml: string): boolean;
50
+ declare function isValidXml(xml: string): boolean;
53
51
  /**
54
52
  * Parse XML with array handling for repeated elements
55
53
  * Forces specified tag names to always be arrays, even if only one element exists
@@ -66,8 +64,8 @@ export declare function isValidXml(xml: string): boolean;
66
64
  * // Without arrayTags, would return: { root: { item: 'Test' } }
67
65
  * ```
68
66
  */
69
- export declare function parseXmlWithArrays(xml: string, arrayTags: string[], options?: Partial<X2jOptions> & {
70
- maxSize?: number;
67
+ declare function parseXmlWithArrays(xml: string, arrayTags: string[], options?: Partial<X2jOptions> & {
68
+ maxSize?: number;
71
69
  }): Record<string, unknown>;
72
70
  /**
73
71
  * Extract text content from XML, stripping all tags
@@ -82,5 +80,7 @@ export declare function parseXmlWithArrays(xml: string, arrayTags: string[], opt
82
80
  * // Returns: 'Bold and italic'
83
81
  * ```
84
82
  */
85
- export declare function extractTextFromXml(xml: string): string;
83
+ declare function extractTextFromXml(xml: string): string;
84
+ //#endregion
85
+ export { buildXml, extractTextFromXml, findValuesByKey as findXmlValues, isValidXml, parseXml, parseXmlWithArrays };
86
86
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/xml/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAiCtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC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