@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.
- package/LICENSE.md +55 -0
- package/dist/csv/index.d.ts +27 -29
- package/dist/csv/index.d.ts.map +1 -1
- package/dist/csv/index.js +179 -218
- package/dist/csv/index.js.map +1 -1
- package/dist/hash/index.d.ts +15 -12
- package/dist/hash/index.d.ts.map +1 -1
- package/dist/hash/index.js +90 -98
- package/dist/hash/index.js.map +1 -1
- package/dist/index.d.ts +36 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -17
- package/dist/index.js.map +1 -1
- package/dist/json/index.d.ts +13 -9
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +45 -54
- package/dist/json/index.js.map +1 -1
- package/dist/object/index.d.ts +6 -3
- package/dist/object/index.d.ts.map +1 -1
- package/dist/object/index.js +54 -60
- package/dist/object/index.js.map +1 -1
- package/dist/string/index.d.ts +5 -2
- package/dist/string/index.d.ts.map +1 -1
- package/dist/string/index.js +55 -56
- package/dist/string/index.js.map +1 -1
- package/dist/xml/index.d.ts +13 -13
- package/dist/xml/index.d.ts.map +1 -1
- package/dist/xml/index.js +136 -166
- package/dist/xml/index.js.map +1 -1
- package/package.json +30 -30
- package/dist/severity/index.d.ts +0 -29
- package/dist/severity/index.d.ts.map +0 -1
- package/dist/severity/index.js +0 -52
- package/dist/severity/index.js.map +0 -1
package/dist/xml/index.js
CHANGED
|
@@ -1,187 +1,157 @@
|
|
|
1
|
+
import { findValuesByKey } from "../object/index.js";
|
|
2
|
+
import { XMLBuilder, XMLParser, XMLValidator } from "fast-xml-parser";
|
|
3
|
+
//#region src/xml/index.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';
|
|
6
|
-
export { findValuesByKey as findXmlValues } from '../object/index.js';
|
|
5
|
+
* XML parsing utilities for HDF converters
|
|
6
|
+
* Provides XML parsing with sensible defaults for security tool output
|
|
7
|
+
*/
|
|
7
8
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
* Default options for XML parsing optimized for security tool converters.
|
|
10
|
+
*
|
|
11
|
+
* **XXE Safety**: fast-xml-parser v5.x does not process DTD or external entities
|
|
12
|
+
* by default. The `processEntities: false` option is set as defense-in-depth to
|
|
13
|
+
* ensure entity expansion is disabled even if future versions change defaults.
|
|
14
|
+
* See: https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v5/2.XMLparseOptions.md
|
|
15
|
+
*/
|
|
15
16
|
const DEFAULT_PARSE_OPTIONS = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
attributeNamePrefix: "",
|
|
18
|
+
textNodeName: "#text",
|
|
19
|
+
ignoreAttributes: false,
|
|
20
|
+
ignoreDeclaration: true,
|
|
21
|
+
parseAttributeValue: false,
|
|
22
|
+
parseTagValue: false,
|
|
23
|
+
removeNSPrefix: true,
|
|
24
|
+
processEntities: false
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
* Default options for XML building
|
|
28
|
+
*/
|
|
28
29
|
const DEFAULT_BUILD_OPTIONS = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
attributeNamePrefix: "",
|
|
31
|
+
textNodeName: "#text",
|
|
32
|
+
ignoreAttributes: false,
|
|
33
|
+
format: true,
|
|
34
|
+
indentBy: " ",
|
|
35
|
+
suppressEmptyNode: false
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
const mergedOptions = {
|
|
60
|
-
...DEFAULT_PARSE_OPTIONS,
|
|
61
|
-
...options,
|
|
62
|
-
};
|
|
63
|
-
const parser = new XMLParser(mergedOptions);
|
|
64
|
-
return parser.parse(xml);
|
|
38
|
+
* Parse XML string to JavaScript object
|
|
39
|
+
*
|
|
40
|
+
* @param xml - XML string to parse
|
|
41
|
+
* @param options - Optional parser configuration (merged with defaults)
|
|
42
|
+
* @returns Parsed JavaScript object
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const xmlString = '<root><item id="1">Test</item></root>';
|
|
47
|
+
* const result = parseXml(xmlString);
|
|
48
|
+
* // Returns: { root: { item: { id: '1', '#text': 'Test' } } }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function parseXml(xml, options) {
|
|
52
|
+
if (options?.maxSize !== void 0 && xml.length > options.maxSize) throw new Error(`Input exceeds maximum allowed size: ${xml.length} bytes exceeds limit of ${options.maxSize} bytes`);
|
|
53
|
+
const validation = XMLValidator.validate(xml);
|
|
54
|
+
if (validation !== true) throw new Error(`Invalid XML: ${validation.err.msg}`);
|
|
55
|
+
return new XMLParser({
|
|
56
|
+
...DEFAULT_PARSE_OPTIONS,
|
|
57
|
+
...options
|
|
58
|
+
}).parse(xml);
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const builder = new XMLBuilder(mergedOptions);
|
|
86
|
-
return builder.build(obj);
|
|
61
|
+
* Build XML string from JavaScript object
|
|
62
|
+
*
|
|
63
|
+
* @param obj - JavaScript object to convert to XML
|
|
64
|
+
* @param options - Optional builder configuration (merged with defaults)
|
|
65
|
+
* @returns XML string
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const obj = { root: { item: { id: '1', '#text': 'Test' } } };
|
|
70
|
+
* const xml = buildXml(obj);
|
|
71
|
+
* // Returns formatted XML string
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function buildXml(obj, options) {
|
|
75
|
+
return new XMLBuilder({
|
|
76
|
+
...DEFAULT_BUILD_OPTIONS,
|
|
77
|
+
...options
|
|
78
|
+
}).build(obj);
|
|
87
79
|
}
|
|
88
80
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
const result = XMLValidator.validate(xml);
|
|
106
|
-
return result === true;
|
|
81
|
+
* Validate if a string is well-formed XML
|
|
82
|
+
*
|
|
83
|
+
* @param xml - String to validate
|
|
84
|
+
* @returns True if valid XML, false otherwise
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* isValidXml('<root><item>Test</item></root>'); // true
|
|
89
|
+
* isValidXml('<root><item>Test</root>'); // false (mismatched tags)
|
|
90
|
+
* isValidXml('not xml'); // false
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function isValidXml(xml) {
|
|
94
|
+
if (!xml || xml.trim().length === 0) return false;
|
|
95
|
+
return XMLValidator.validate(xml) === true;
|
|
107
96
|
}
|
|
108
97
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const mergedOptions = {
|
|
134
|
-
...DEFAULT_PARSE_OPTIONS,
|
|
135
|
-
...options,
|
|
136
|
-
isArray: (tagName) => arrayTags.includes(tagName),
|
|
137
|
-
};
|
|
138
|
-
const parser = new XMLParser(mergedOptions);
|
|
139
|
-
return parser.parse(xml);
|
|
98
|
+
* Parse XML with array handling for repeated elements
|
|
99
|
+
* Forces specified tag names to always be arrays, even if only one element exists
|
|
100
|
+
*
|
|
101
|
+
* @param xml - XML string to parse
|
|
102
|
+
* @param arrayTags - Array of tag names that should always be parsed as arrays
|
|
103
|
+
* @returns Parsed JavaScript object with forced arrays
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const xml = '<root><item>Test</item></root>';
|
|
108
|
+
* const result = parseXmlWithArrays(xml, ['item']);
|
|
109
|
+
* // Returns: { root: { item: ['Test'] } }
|
|
110
|
+
* // Without arrayTags, would return: { root: { item: 'Test' } }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function parseXmlWithArrays(xml, arrayTags, options) {
|
|
114
|
+
if (options?.maxSize !== void 0 && xml.length > options.maxSize) throw new Error(`Input exceeds maximum allowed size: ${xml.length} bytes exceeds limit of ${options.maxSize} bytes`);
|
|
115
|
+
const validation = XMLValidator.validate(xml);
|
|
116
|
+
if (validation !== true) throw new Error(`Invalid XML: ${validation.err.msg}`);
|
|
117
|
+
return new XMLParser({
|
|
118
|
+
...DEFAULT_PARSE_OPTIONS,
|
|
119
|
+
...options,
|
|
120
|
+
isArray: (tagName) => arrayTags.includes(tagName)
|
|
121
|
+
}).parse(xml);
|
|
140
122
|
}
|
|
141
123
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
return '';
|
|
164
|
-
}
|
|
124
|
+
* Extract text content from XML, stripping all tags
|
|
125
|
+
*
|
|
126
|
+
* @param xml - XML string
|
|
127
|
+
* @returns Plain text content with tags removed
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const xml = '<root><b>Bold</b> and <i>italic</i></root>';
|
|
132
|
+
* const text = extractTextFromXml(xml);
|
|
133
|
+
* // Returns: 'Bold and italic'
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
function extractTextFromXml(xml) {
|
|
137
|
+
if (!isValidXml(xml)) return "";
|
|
138
|
+
try {
|
|
139
|
+
return extractTextRecursive(parseXml(xml, { ignoreAttributes: true })).trim();
|
|
140
|
+
} catch {
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
165
143
|
}
|
|
166
144
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
145
|
+
* Recursively extract text from parsed XML object
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
170
148
|
function extractTextRecursive(obj) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return obj.map(extractTextRecursive).join(' ');
|
|
176
|
-
}
|
|
177
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
178
|
-
const record = obj;
|
|
179
|
-
// Recursively extract text from all properties
|
|
180
|
-
return Object.values(record)
|
|
181
|
-
.map(extractTextRecursive)
|
|
182
|
-
.filter(text => text.length > 0)
|
|
183
|
-
.join(' ');
|
|
184
|
-
}
|
|
185
|
-
return '';
|
|
149
|
+
if (typeof obj === "string" || typeof obj === "number") return String(obj);
|
|
150
|
+
if (Array.isArray(obj)) return obj.map(extractTextRecursive).join(" ");
|
|
151
|
+
if (typeof obj === "object" && obj !== null) return Object.values(obj).map(extractTextRecursive).filter((text) => text.length > 0).join(" ");
|
|
152
|
+
return "";
|
|
186
153
|
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export { buildXml, extractTextFromXml, findValuesByKey as findXmlValues, isValidXml, parseXml, parseXmlWithArrays };
|
|
156
|
+
|
|
187
157
|
//# sourceMappingURL=index.js.map
|
package/dist/xml/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/xml/index.ts"],"sourcesContent":["/**\n * XML parsing utilities for HDF converters\n * Provides XML parsing with sensible defaults for security tool output\n */\n\nimport { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';\nimport type { X2jOptions, XmlBuilderOptions } from 'fast-xml-parser';\n\nexport { findValuesByKey as findXmlValues } from '../object/index.js';\n\n/**\n * Default options for XML parsing optimized for security tool converters.\n *\n * **XXE Safety**: fast-xml-parser v5.x does not process DTD or external entities\n * by default. The `processEntities: false` option is set as defense-in-depth to\n * ensure entity expansion is disabled even if future versions change defaults.\n * See: https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v5/2.XMLparseOptions.md\n */\nconst DEFAULT_PARSE_OPTIONS: Partial<X2jOptions> = {\n attributeNamePrefix: '',\n textNodeName: '#text',\n ignoreAttributes: false,\n ignoreDeclaration: true,\n parseAttributeValue: false,\n parseTagValue: false,\n removeNSPrefix: true,\n processEntities: false,\n};\n\n/**\n * Default options for XML building\n */\nconst DEFAULT_BUILD_OPTIONS: Partial<XmlBuilderOptions> = {\n attributeNamePrefix: '',\n textNodeName: '#text',\n ignoreAttributes: false,\n format: true,\n indentBy: ' ',\n suppressEmptyNode: false,\n};\n\n/**\n * Parse XML string to JavaScript object\n *\n * @param xml - XML string to parse\n * @param options - Optional parser configuration (merged with defaults)\n * @returns Parsed JavaScript object\n *\n * @example\n * ```typescript\n * const xmlString = '<root><item id=\"1\">Test</item></root>';\n * const result = parseXml(xmlString);\n * // Returns: { root: { item: { id: '1', '#text': 'Test' } } }\n * ```\n */\nexport function parseXml(\n xml: string,\n options?: Partial<X2jOptions> & { maxSize?: number }\n): Record<string, unknown> {\n if (options?.maxSize !== undefined && xml.length > options.maxSize) {\n throw new Error(\n `Input exceeds maximum allowed size: ${xml.length} bytes exceeds limit of ${options.maxSize} bytes`\n );\n }\n\n // Validate XML first\n const validation = XMLValidator.validate(xml);\n if (validation !== true) {\n throw new Error(`Invalid XML: ${validation.err.msg}`);\n }\n\n const mergedOptions = {\n ...DEFAULT_PARSE_OPTIONS,\n ...options,\n };\n\n const parser = new XMLParser(mergedOptions);\n return parser.parse(xml) as Record<string, unknown>;\n}\n\n/**\n * Build XML string from JavaScript object\n *\n * @param obj - JavaScript object to convert to XML\n * @param options - Optional builder configuration (merged with defaults)\n * @returns XML string\n *\n * @example\n * ```typescript\n * const obj = { root: { item: { id: '1', '#text': 'Test' } } };\n * const xml = buildXml(obj);\n * // Returns formatted XML string\n * ```\n */\nexport function buildXml(\n obj: Record<string, unknown>,\n options?: Partial<XmlBuilderOptions>\n): string {\n const mergedOptions = {\n ...DEFAULT_BUILD_OPTIONS,\n ...options,\n };\n\n const builder = new XMLBuilder(mergedOptions);\n return builder.build(obj) as string;\n}\n\n/**\n * Validate if a string is well-formed XML\n *\n * @param xml - String to validate\n * @returns True if valid XML, false otherwise\n *\n * @example\n * ```typescript\n * isValidXml('<root><item>Test</item></root>'); // true\n * isValidXml('<root><item>Test</root>'); // false (mismatched tags)\n * isValidXml('not xml'); // false\n * ```\n */\nexport function isValidXml(xml: string): boolean {\n if (!xml || xml.trim().length === 0) {\n return false;\n }\n\n const result = XMLValidator.validate(xml);\n return result === true;\n}\n\n/**\n * Parse XML with array handling for repeated elements\n * Forces specified tag names to always be arrays, even if only one element exists\n *\n * @param xml - XML string to parse\n * @param arrayTags - Array of tag names that should always be parsed as arrays\n * @returns Parsed JavaScript object with forced arrays\n *\n * @example\n * ```typescript\n * const xml = '<root><item>Test</item></root>';\n * const result = parseXmlWithArrays(xml, ['item']);\n * // Returns: { root: { item: ['Test'] } }\n * // Without arrayTags, would return: { root: { item: 'Test' } }\n * ```\n */\nexport function parseXmlWithArrays(\n xml: string,\n arrayTags: string[],\n options?: Partial<X2jOptions> & { maxSize?: number }\n): Record<string, unknown> {\n if (options?.maxSize !== undefined && xml.length > options.maxSize) {\n throw new Error(\n `Input exceeds maximum allowed size: ${xml.length} bytes exceeds limit of ${options.maxSize} bytes`\n );\n }\n\n // Validate XML first (consistency with parseXml)\n const validation = XMLValidator.validate(xml);\n if (validation !== true) {\n throw new Error(`Invalid XML: ${validation.err.msg}`);\n }\n\n const mergedOptions: Partial<X2jOptions> = {\n ...DEFAULT_PARSE_OPTIONS,\n ...options,\n isArray: (tagName: string) => arrayTags.includes(tagName),\n };\n\n const parser = new XMLParser(mergedOptions);\n return parser.parse(xml) as Record<string, unknown>;\n}\n\n/**\n * Extract text content from XML, stripping all tags\n *\n * @param xml - XML string\n * @returns Plain text content with tags removed\n *\n * @example\n * ```typescript\n * const xml = '<root><b>Bold</b> and <i>italic</i></root>';\n * const text = extractTextFromXml(xml);\n * // Returns: 'Bold and italic'\n * ```\n */\nexport function extractTextFromXml(xml: string): string {\n if (!isValidXml(xml)) {\n return '';\n }\n\n try {\n const parsed = parseXml(xml, { ignoreAttributes: true });\n return extractTextRecursive(parsed).trim();\n } catch {\n return '';\n }\n}\n\n/**\n * Recursively extract text from parsed XML object\n * @private\n */\nfunction extractTextRecursive(obj: unknown): string {\n if (typeof obj === 'string' || typeof obj === 'number') {\n return String(obj);\n }\n\n if (Array.isArray(obj)) {\n return obj.map(extractTextRecursive).join(' ');\n }\n\n if (typeof obj === 'object' && obj !== null) {\n const record = obj as Record<string, unknown>;\n\n // Recursively extract text from all properties\n return Object.values(record)\n .map(extractTextRecursive)\n .filter(text => text.length > 0)\n .join(' ');\n }\n\n return '';\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAM,wBAA6C;CACjD,qBAAqB;CACrB,cAAc;CACd,kBAAkB;CAClB,mBAAmB;CACnB,qBAAqB;CACrB,eAAe;CACf,gBAAgB;CAChB,iBAAiB;CAClB;;;;AAKD,MAAM,wBAAoD;CACxD,qBAAqB;CACrB,cAAc;CACd,kBAAkB;CAClB,QAAQ;CACR,UAAU;CACV,mBAAmB;CACpB;;;;;;;;;;;;;;;AAgBD,SAAgB,SACd,KACA,SACyB;AACzB,KAAI,SAAS,YAAY,KAAA,KAAa,IAAI,SAAS,QAAQ,QACzD,OAAM,IAAI,MACR,uCAAuC,IAAI,OAAO,0BAA0B,QAAQ,QAAQ,QAC7F;CAIH,MAAM,aAAa,aAAa,SAAS,IAAI;AAC7C,KAAI,eAAe,KACjB,OAAM,IAAI,MAAM,gBAAgB,WAAW,IAAI,MAAM;AASvD,QADe,IAAI,UALG;EACpB,GAAG;EACH,GAAG;EACJ,CAE0C,CAC7B,MAAM,IAAI;;;;;;;;;;;;;;;;AAiB1B,SAAgB,SACd,KACA,SACQ;AAOR,QADgB,IAAI,WALE;EACpB,GAAG;EACH,GAAG;EACJ,CAE4C,CAC9B,MAAM,IAAI;;;;;;;;;;;;;;;AAgB3B,SAAgB,WAAW,KAAsB;AAC/C,KAAI,CAAC,OAAO,IAAI,MAAM,CAAC,WAAW,EAChC,QAAO;AAIT,QADe,aAAa,SAAS,IAAI,KACvB;;;;;;;;;;;;;;;;;;AAmBpB,SAAgB,mBACd,KACA,WACA,SACyB;AACzB,KAAI,SAAS,YAAY,KAAA,KAAa,IAAI,SAAS,QAAQ,QACzD,OAAM,IAAI,MACR,uCAAuC,IAAI,OAAO,0BAA0B,QAAQ,QAAQ,QAC7F;CAIH,MAAM,aAAa,aAAa,SAAS,IAAI;AAC7C,KAAI,eAAe,KACjB,OAAM,IAAI,MAAM,gBAAgB,WAAW,IAAI,MAAM;AAUvD,QADe,IAAI,UANwB;EACzC,GAAG;EACH,GAAG;EACH,UAAU,YAAoB,UAAU,SAAS,QAAQ;EAC1D,CAE0C,CAC7B,MAAM,IAAI;;;;;;;;;;;;;;;AAgB1B,SAAgB,mBAAmB,KAAqB;AACtD,KAAI,CAAC,WAAW,IAAI,CAClB,QAAO;AAGT,KAAI;AAEF,SAAO,qBADQ,SAAS,KAAK,EAAE,kBAAkB,MAAM,CAAC,CACrB,CAAC,MAAM;SACpC;AACN,SAAO;;;;;;;AAQX,SAAS,qBAAqB,KAAsB;AAClD,KAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,SAC5C,QAAO,OAAO,IAAI;AAGpB,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,IAAI,qBAAqB,CAAC,KAAK,IAAI;AAGhD,KAAI,OAAO,QAAQ,YAAY,QAAQ,KAIrC,QAAO,OAAO,OAHC,IAGa,CACzB,IAAI,qBAAqB,CACzB,QAAO,SAAQ,KAAK,SAAS,EAAE,CAC/B,KAAK,IAAI;AAGd,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mitre/hdf-utilities",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Utility functions for HDF libraries (JSON parsing, validation helpers)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,49 +10,37 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./json": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"types": "./dist/json/index.d.ts",
|
|
18
|
+
"import": "./dist/json/index.js"
|
|
19
19
|
},
|
|
20
20
|
"./hash": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"types": "./dist/hash/index.d.ts",
|
|
22
|
+
"import": "./dist/hash/index.js"
|
|
23
23
|
},
|
|
24
24
|
"./xml": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"types": "./dist/xml/index.d.ts",
|
|
26
|
+
"import": "./dist/xml/index.js"
|
|
27
27
|
},
|
|
28
28
|
"./csv": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"types": "./dist/csv/index.d.ts",
|
|
30
|
+
"import": "./dist/csv/index.js"
|
|
31
31
|
},
|
|
32
32
|
"./object": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"types": "./dist/object/index.d.ts",
|
|
34
|
+
"import": "./dist/object/index.js"
|
|
35
35
|
},
|
|
36
36
|
"./string": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"types": "./dist/string/index.d.ts",
|
|
38
|
+
"import": "./dist/string/index.js"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "pnpm clean && tsc",
|
|
46
|
-
"clean": "rimraf dist",
|
|
47
|
-
"test": "pnpm run test:ts",
|
|
48
|
-
"test:ts": "vitest run",
|
|
49
|
-
"test:go": "echo 'No Go tests in hdf-utilities'",
|
|
50
|
-
"test:watch": "vitest",
|
|
51
|
-
"test:coverage": "vitest run --coverage",
|
|
52
|
-
"type-check": "tsc --noEmit",
|
|
53
|
-
"lint": "eslint src test",
|
|
54
|
-
"lint:fix": "eslint src test --fix"
|
|
55
|
-
},
|
|
56
44
|
"repository": {
|
|
57
45
|
"type": "git",
|
|
58
46
|
"url": "https://github.com/mitre/hdf-libs.git",
|
|
@@ -62,10 +50,10 @@
|
|
|
62
50
|
"license": "Apache-2.0",
|
|
63
51
|
"dependencies": {
|
|
64
52
|
"d3-dsv": "^3.0.1",
|
|
65
|
-
"fast-xml-parser": "5.
|
|
53
|
+
"fast-xml-parser": "5.7.1"
|
|
66
54
|
},
|
|
67
55
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
56
|
+
"node": ">=22.0.0"
|
|
69
57
|
},
|
|
70
58
|
"keywords": [
|
|
71
59
|
"hdf",
|
|
@@ -78,5 +66,17 @@
|
|
|
78
66
|
"@stryker-mutator/core": "^9.5.1",
|
|
79
67
|
"@stryker-mutator/vitest-runner": "^9.5.1",
|
|
80
68
|
"@types/d3-dsv": "^3.0.7"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsdown",
|
|
72
|
+
"clean": "rimraf dist",
|
|
73
|
+
"test": "pnpm run test:ts",
|
|
74
|
+
"test:ts": "vitest run",
|
|
75
|
+
"test:go": "echo 'No Go tests in hdf-utilities'",
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"test:coverage": "vitest run --coverage",
|
|
78
|
+
"type-check": "tsc --noEmit",
|
|
79
|
+
"lint": "eslint src test",
|
|
80
|
+
"lint:fix": "eslint src test --fix"
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|
package/dist/severity/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Severity-to-impact mapping utilities.
|
|
3
|
-
*
|
|
4
|
-
* These define the canonical bidirectional mapping between severity labels
|
|
5
|
-
* (critical, high, medium, low, informational) and HDF impact scores (0.0–1.0),
|
|
6
|
-
* aligned with CVSS 3.x severity bands normalized to 0–1.
|
|
7
|
-
*
|
|
8
|
-
* Threshold ranges (used by impactToSeverity):
|
|
9
|
-
* >=0.9 = critical (CVSS 9.0–10.0)
|
|
10
|
-
* [0.7, 0.9) = high (CVSS 7.0–8.9)
|
|
11
|
-
* [0.4, 0.7) = medium (CVSS 4.0–6.9)
|
|
12
|
-
* (0.0, 0.4) = low (CVSS 0.1–3.9)
|
|
13
|
-
* 0.0 = informational (CVSS 0.0)
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Map a severity string to an impact score.
|
|
17
|
-
*
|
|
18
|
-
* @param severity - Severity level (case-insensitive)
|
|
19
|
-
* @returns Impact score between 0.0 and 1.0; defaults to 0.5 for unrecognized values
|
|
20
|
-
*/
|
|
21
|
-
export declare function severityToImpact(severity: string): number;
|
|
22
|
-
/**
|
|
23
|
-
* Map an impact score to a severity string.
|
|
24
|
-
*
|
|
25
|
-
* @param impact - Impact score (0.0 to 1.0)
|
|
26
|
-
* @returns Severity level string
|
|
27
|
-
*/
|
|
28
|
-
export declare function impactToSeverity(impact: number): string;
|
|
29
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/severity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMvD"}
|
package/dist/severity/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Severity-to-impact mapping utilities.
|
|
3
|
-
*
|
|
4
|
-
* These define the canonical bidirectional mapping between severity labels
|
|
5
|
-
* (critical, high, medium, low, informational) and HDF impact scores (0.0–1.0),
|
|
6
|
-
* aligned with CVSS 3.x severity bands normalized to 0–1.
|
|
7
|
-
*
|
|
8
|
-
* Threshold ranges (used by impactToSeverity):
|
|
9
|
-
* >=0.9 = critical (CVSS 9.0–10.0)
|
|
10
|
-
* [0.7, 0.9) = high (CVSS 7.0–8.9)
|
|
11
|
-
* [0.4, 0.7) = medium (CVSS 4.0–6.9)
|
|
12
|
-
* (0.0, 0.4) = low (CVSS 0.1–3.9)
|
|
13
|
-
* 0.0 = informational (CVSS 0.0)
|
|
14
|
-
*/
|
|
15
|
-
const severityMap = {
|
|
16
|
-
critical: 0.9,
|
|
17
|
-
high: 0.7,
|
|
18
|
-
medium: 0.5,
|
|
19
|
-
low: 0.3,
|
|
20
|
-
info: 0.0,
|
|
21
|
-
none: 0.0,
|
|
22
|
-
informational: 0.0,
|
|
23
|
-
information: 0.0,
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Map a severity string to an impact score.
|
|
27
|
-
*
|
|
28
|
-
* @param severity - Severity level (case-insensitive)
|
|
29
|
-
* @returns Impact score between 0.0 and 1.0; defaults to 0.5 for unrecognized values
|
|
30
|
-
*/
|
|
31
|
-
export function severityToImpact(severity) {
|
|
32
|
-
const normalized = severity.toLowerCase();
|
|
33
|
-
return severityMap[normalized] ?? 0.5;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Map an impact score to a severity string.
|
|
37
|
-
*
|
|
38
|
-
* @param impact - Impact score (0.0 to 1.0)
|
|
39
|
-
* @returns Severity level string
|
|
40
|
-
*/
|
|
41
|
-
export function impactToSeverity(impact) {
|
|
42
|
-
if (impact >= 0.9)
|
|
43
|
-
return 'critical';
|
|
44
|
-
if (impact >= 0.7)
|
|
45
|
-
return 'high';
|
|
46
|
-
if (impact >= 0.4)
|
|
47
|
-
return 'medium';
|
|
48
|
-
if (impact > 0.0)
|
|
49
|
-
return 'low';
|
|
50
|
-
return 'informational';
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/severity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,GAA2B;IAC1C,QAAQ,EAAE,GAAG;IACb,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,GAAG;IACX,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,aAAa,EAAE,GAAG;IAClB,WAAW,EAAE,GAAG;CACjB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC1C,OAAO,WAAW,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,UAAU,CAAC;IACrC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,MAAM,CAAC;IACjC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,QAAQ,CAAC;IACnC,IAAI,MAAM,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO,eAAe,CAAC;AACzB,CAAC"}
|