@mitre/hdf-diff 2.0.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/README.md +87 -0
- package/dist/diff.d.ts +49 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +791 -0
- package/dist/diff.js.map +1 -0
- package/dist/exit-codes.d.ts +42 -0
- package/dist/exit-codes.d.ts.map +1 -0
- package/dist/exit-codes.js +74 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/matching/cci-match.d.ts +14 -0
- package/dist/matching/cci-match.d.ts.map +1 -0
- package/dist/matching/cci-match.js +102 -0
- package/dist/matching/cci-match.js.map +1 -0
- package/dist/matching/exact-id.d.ts +9 -0
- package/dist/matching/exact-id.d.ts.map +1 -0
- package/dist/matching/exact-id.js +88 -0
- package/dist/matching/exact-id.js.map +1 -0
- package/dist/matching/fuzzy-match.d.ts +26 -0
- package/dist/matching/fuzzy-match.d.ts.map +1 -0
- package/dist/matching/fuzzy-match.js +145 -0
- package/dist/matching/fuzzy-match.js.map +1 -0
- package/dist/matching/index.d.ts +36 -0
- package/dist/matching/index.d.ts.map +1 -0
- package/dist/matching/index.js +71 -0
- package/dist/matching/index.js.map +1 -0
- package/dist/matching/mapped-id.d.ts +13 -0
- package/dist/matching/mapped-id.d.ts.map +1 -0
- package/dist/matching/mapped-id.js +101 -0
- package/dist/matching/mapped-id.js.map +1 -0
- package/dist/matching/types.d.ts +34 -0
- package/dist/matching/types.d.ts.map +1 -0
- package/dist/matching/types.js +2 -0
- package/dist/matching/types.js.map +1 -0
- package/dist/normalize.d.ts +20 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +120 -0
- package/dist/normalize.js.map +1 -0
- package/dist/renderers/csv.d.ts +15 -0
- package/dist/renderers/csv.d.ts.map +1 -0
- package/dist/renderers/csv.js +77 -0
- package/dist/renderers/csv.js.map +1 -0
- package/dist/renderers/filter.d.ts +11 -0
- package/dist/renderers/filter.d.ts.map +1 -0
- package/dist/renderers/filter.js +29 -0
- package/dist/renderers/filter.js.map +1 -0
- package/dist/renderers/index.d.ts +17 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +29 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/json.d.ts +13 -0
- package/dist/renderers/json.d.ts.map +1 -0
- package/dist/renderers/json.js +41 -0
- package/dist/renderers/json.js.map +1 -0
- package/dist/renderers/markdown.d.ts +13 -0
- package/dist/renderers/markdown.d.ts.map +1 -0
- package/dist/renderers/markdown.js +133 -0
- package/dist/renderers/markdown.js.map +1 -0
- package/dist/renderers/terminal.d.ts +14 -0
- package/dist/renderers/terminal.d.ts.map +1 -0
- package/dist/renderers/terminal.js +173 -0
- package/dist/renderers/terminal.js.map +1 -0
- package/dist/renderers/types.d.ts +12 -0
- package/dist/renderers/types.d.ts.map +1 -0
- package/dist/renderers/types.js +2 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/sbom.d.ts +42 -0
- package/dist/sbom.d.ts.map +1 -0
- package/dist/sbom.js +203 -0
- package/dist/sbom.js.map +1 -0
- package/dist/status.d.ts +27 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +137 -0
- package/dist/status.js.map +1 -0
- package/dist/summary.d.ts +6 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/summary.js +47 -0
- package/dist/summary.js.map +1 -0
- package/dist/types.d.ts +208 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +20 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +108 -0
- package/dist/validate.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/** Common English stop words to exclude from tokenization */
|
|
2
|
+
const STOP_WORDS = new Set([
|
|
3
|
+
'a', 'an', 'the', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
4
|
+
'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
|
|
5
|
+
'should', 'may', 'might', 'shall', 'can', 'to', 'of', 'in', 'for',
|
|
6
|
+
'on', 'with', 'at', 'by', 'from', 'as', 'into', 'through', 'during',
|
|
7
|
+
'before', 'after', 'above', 'below', 'between', 'out', 'off', 'over',
|
|
8
|
+
'under', 'again', 'further', 'then', 'once', 'and', 'but', 'or', 'nor',
|
|
9
|
+
'not', 'no', 'so', 'if', 'it', 'its', 'that', 'this', 'these', 'those',
|
|
10
|
+
'each', 'every', 'all', 'both', 'few', 'more', 'most', 'other', 'some',
|
|
11
|
+
'such', 'than', 'too', 'very', 'just', 'about',
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* Tokenize a title string into a set of meaningful tokens.
|
|
15
|
+
*
|
|
16
|
+
* - Lowercases the string
|
|
17
|
+
* - Splits on whitespace and punctuation
|
|
18
|
+
* - Filters out common stop words
|
|
19
|
+
* - Returns unique tokens as a Set
|
|
20
|
+
*/
|
|
21
|
+
export function tokenize(text) {
|
|
22
|
+
if (!text)
|
|
23
|
+
return new Set();
|
|
24
|
+
const tokens = text
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.split(/[\s\-_/\\,.;:!?()[\]{}"']+/)
|
|
27
|
+
.filter((t) => t.length > 0 && !STOP_WORDS.has(t));
|
|
28
|
+
return new Set(tokens);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compute Jaccard similarity between two sets.
|
|
32
|
+
* Returns |intersection| / |union|, or 0 if both sets are empty.
|
|
33
|
+
*/
|
|
34
|
+
export function jaccardSimilarity(a, b) {
|
|
35
|
+
if (a.size === 0 && b.size === 0)
|
|
36
|
+
return 0.0;
|
|
37
|
+
let intersectionSize = 0;
|
|
38
|
+
// Iterate over the smaller set for efficiency
|
|
39
|
+
const [smaller, larger] = a.size <= b.size ? [a, b] : [b, a];
|
|
40
|
+
for (const item of smaller) {
|
|
41
|
+
if (larger.has(item)) {
|
|
42
|
+
intersectionSize++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const unionSize = a.size + b.size - intersectionSize;
|
|
46
|
+
// Unreachable: if both sets are empty, we return above. If either is non-empty, unionSize > 0.
|
|
47
|
+
// Guard kept for mathematical correctness.
|
|
48
|
+
/* c8 ignore next */
|
|
49
|
+
if (unionSize === 0)
|
|
50
|
+
return 0.0;
|
|
51
|
+
return intersectionSize / unionSize;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Default minimum confidence threshold for fuzzy title matching.
|
|
55
|
+
*/
|
|
56
|
+
const DEFAULT_MIN_CONFIDENCE = 0.6;
|
|
57
|
+
/**
|
|
58
|
+
* Create a fuzzy title matching strategy.
|
|
59
|
+
*
|
|
60
|
+
* Matches requirements by token-based Jaccard similarity on the `title` field.
|
|
61
|
+
* Uses greedy best-match: for each unmatched old requirement, finds the
|
|
62
|
+
* best-matching unmatched new requirement above the confidence threshold.
|
|
63
|
+
*
|
|
64
|
+
* @param minConfidence Minimum Jaccard similarity to accept a match (default: 0.6)
|
|
65
|
+
*/
|
|
66
|
+
export function createFuzzyTitleStrategy(minConfidence) {
|
|
67
|
+
const threshold = minConfidence ?? DEFAULT_MIN_CONFIDENCE;
|
|
68
|
+
return {
|
|
69
|
+
name: 'fuzzyTitle',
|
|
70
|
+
match(oldReqs, newReqs) {
|
|
71
|
+
const result = {
|
|
72
|
+
matched: [],
|
|
73
|
+
unmatchedOld: [],
|
|
74
|
+
unmatchedNew: [],
|
|
75
|
+
};
|
|
76
|
+
// Pre-tokenize all titles
|
|
77
|
+
const oldTokens = [];
|
|
78
|
+
for (let i = 0; i < oldReqs.length; i++) {
|
|
79
|
+
const title = oldReqs[i]['title'];
|
|
80
|
+
if (typeof title === 'string' && title.length > 0) {
|
|
81
|
+
const tokens = tokenize(title);
|
|
82
|
+
if (tokens.size > 0) {
|
|
83
|
+
oldTokens.push({ idx: i, tokens });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const newTokens = [];
|
|
88
|
+
for (let i = 0; i < newReqs.length; i++) {
|
|
89
|
+
const title = newReqs[i]['title'];
|
|
90
|
+
if (typeof title === 'string' && title.length > 0) {
|
|
91
|
+
const tokens = tokenize(title);
|
|
92
|
+
if (tokens.size > 0) {
|
|
93
|
+
newTokens.push({ idx: i, tokens });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Track matched indices
|
|
98
|
+
const matchedOldIndices = new Set();
|
|
99
|
+
const matchedNewIndices = new Set();
|
|
100
|
+
// Build a list of all potential matches with similarity scores
|
|
101
|
+
const candidates = [];
|
|
102
|
+
for (const old of oldTokens) {
|
|
103
|
+
for (const nw of newTokens) {
|
|
104
|
+
const sim = jaccardSimilarity(old.tokens, nw.tokens);
|
|
105
|
+
if (sim >= threshold) {
|
|
106
|
+
candidates.push({
|
|
107
|
+
oldIdx: old.idx,
|
|
108
|
+
newIdx: nw.idx,
|
|
109
|
+
similarity: sim,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Sort by similarity descending (greedy best-match)
|
|
115
|
+
candidates.sort((a, b) => b.similarity - a.similarity);
|
|
116
|
+
// Greedily assign matches
|
|
117
|
+
for (const candidate of candidates) {
|
|
118
|
+
if (matchedOldIndices.has(candidate.oldIdx) || matchedNewIndices.has(candidate.newIdx)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
result.matched.push({
|
|
122
|
+
oldReq: oldReqs[candidate.oldIdx],
|
|
123
|
+
newReq: newReqs[candidate.newIdx],
|
|
124
|
+
strategy: 'fuzzyTitle',
|
|
125
|
+
confidence: candidate.similarity,
|
|
126
|
+
});
|
|
127
|
+
matchedOldIndices.add(candidate.oldIdx);
|
|
128
|
+
matchedNewIndices.add(candidate.newIdx);
|
|
129
|
+
}
|
|
130
|
+
// Collect unmatched
|
|
131
|
+
for (let i = 0; i < oldReqs.length; i++) {
|
|
132
|
+
if (!matchedOldIndices.has(i)) {
|
|
133
|
+
result.unmatchedOld.push(oldReqs[i]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
for (let i = 0; i < newReqs.length; i++) {
|
|
137
|
+
if (!matchedNewIndices.has(i)) {
|
|
138
|
+
result.unmatchedNew.push(newReqs[i]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=fuzzy-match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuzzy-match.js","sourceRoot":"","sources":["../../src/matching/fuzzy-match.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO;IACnE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACnE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK;IACjE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ;IACnE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM;IACpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,E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}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MatchResult } from './types.js';
|
|
2
|
+
export type { MatchResult, MatchPair, MatchStrategy } from './types.js';
|
|
3
|
+
export { createExactIdStrategy } from './exact-id.js';
|
|
4
|
+
export { createMappedIdStrategy } from './mapped-id.js';
|
|
5
|
+
export { createCciMatchStrategy } from './cci-match.js';
|
|
6
|
+
export { createFuzzyTitleStrategy, tokenize, jaccardSimilarity } from './fuzzy-match.js';
|
|
7
|
+
/**
|
|
8
|
+
* Options for configuring requirement matching.
|
|
9
|
+
*/
|
|
10
|
+
export interface MatchOptions {
|
|
11
|
+
/** Primary matching strategy name (default: 'exactId') */
|
|
12
|
+
strategy?: string;
|
|
13
|
+
/** Fallback strategy names, applied in order to remaining unmatched requirements */
|
|
14
|
+
fallbackStrategies?: string[];
|
|
15
|
+
/** Mapping table for the 'mappedId' strategy (old ID -> new ID) */
|
|
16
|
+
mappingTable?: Record<string, string>;
|
|
17
|
+
/** Minimum confidence threshold for fuzzy matching (default: 0.6) */
|
|
18
|
+
minConfidence?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Match requirements between two evaluations using a primary strategy
|
|
22
|
+
* and optional fallback strategies.
|
|
23
|
+
*
|
|
24
|
+
* The registry applies strategies in order:
|
|
25
|
+
* 1. Primary strategy matches what it can
|
|
26
|
+
* 2. Unmatched requirements pass to the next fallback strategy
|
|
27
|
+
* 3. Process continues until all strategies are exhausted or all
|
|
28
|
+
* requirements are matched
|
|
29
|
+
*
|
|
30
|
+
* @param oldReqs Requirements from the old evaluation
|
|
31
|
+
* @param newReqs Requirements from the new evaluation
|
|
32
|
+
* @param options Matching configuration
|
|
33
|
+
* @returns Combined match result from all strategies
|
|
34
|
+
*/
|
|
35
|
+
export declare function matchRequirements(oldReqs: Record<string, unknown>[], newReqs: Record<string, unknown>[], options?: MatchOptions): MatchResult;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/matching/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,YAAY,CAAC;AAO7D,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEzF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAqBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClC,OAAO,CAAC,EAAE,YAAY,GACrB,WAAW,CAmCb"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createExactIdStrategy } from './exact-id.js';
|
|
2
|
+
import { createMappedIdStrategy } from './mapped-id.js';
|
|
3
|
+
import { createCciMatchStrategy } from './cci-match.js';
|
|
4
|
+
import { createFuzzyTitleStrategy } from './fuzzy-match.js';
|
|
5
|
+
export { createExactIdStrategy } from './exact-id.js';
|
|
6
|
+
export { createMappedIdStrategy } from './mapped-id.js';
|
|
7
|
+
export { createCciMatchStrategy } from './cci-match.js';
|
|
8
|
+
export { createFuzzyTitleStrategy, tokenize, jaccardSimilarity } from './fuzzy-match.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create a strategy instance by name, using the provided options for
|
|
11
|
+
* strategies that require configuration.
|
|
12
|
+
*/
|
|
13
|
+
function createStrategy(name, options) {
|
|
14
|
+
switch (name) {
|
|
15
|
+
case 'exactId':
|
|
16
|
+
return createExactIdStrategy();
|
|
17
|
+
case 'mappedId':
|
|
18
|
+
return createMappedIdStrategy(options.mappingTable ?? {});
|
|
19
|
+
case 'cciMatch':
|
|
20
|
+
return createCciMatchStrategy();
|
|
21
|
+
case 'fuzzyTitle':
|
|
22
|
+
return createFuzzyTitleStrategy(options.minConfidence);
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`Unknown matching strategy: '${name}'`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Match requirements between two evaluations using a primary strategy
|
|
29
|
+
* and optional fallback strategies.
|
|
30
|
+
*
|
|
31
|
+
* The registry applies strategies in order:
|
|
32
|
+
* 1. Primary strategy matches what it can
|
|
33
|
+
* 2. Unmatched requirements pass to the next fallback strategy
|
|
34
|
+
* 3. Process continues until all strategies are exhausted or all
|
|
35
|
+
* requirements are matched
|
|
36
|
+
*
|
|
37
|
+
* @param oldReqs Requirements from the old evaluation
|
|
38
|
+
* @param newReqs Requirements from the new evaluation
|
|
39
|
+
* @param options Matching configuration
|
|
40
|
+
* @returns Combined match result from all strategies
|
|
41
|
+
*/
|
|
42
|
+
export function matchRequirements(oldReqs, newReqs, options) {
|
|
43
|
+
const opts = options ?? {};
|
|
44
|
+
const primaryName = opts.strategy ?? 'exactId';
|
|
45
|
+
const fallbackNames = opts.fallbackStrategies ?? [];
|
|
46
|
+
// Build all strategy instances once up front (also validates names —
|
|
47
|
+
// createStrategy throws for unknown strategy names).
|
|
48
|
+
const allNames = [primaryName, ...fallbackNames];
|
|
49
|
+
const strategies = allNames.map((name) => createStrategy(name, opts));
|
|
50
|
+
// Accumulate all matched pairs
|
|
51
|
+
const allMatched = [];
|
|
52
|
+
// Start with all requirements unmatched
|
|
53
|
+
let currentUnmatchedOld = oldReqs;
|
|
54
|
+
let currentUnmatchedNew = newReqs;
|
|
55
|
+
// Apply strategies in order
|
|
56
|
+
for (const strategy of strategies) {
|
|
57
|
+
if (currentUnmatchedOld.length === 0 || currentUnmatchedNew.length === 0) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const result = strategy.match(currentUnmatchedOld, currentUnmatchedNew);
|
|
61
|
+
allMatched.push(...result.matched);
|
|
62
|
+
currentUnmatchedOld = result.unmatchedOld;
|
|
63
|
+
currentUnmatchedNew = result.unmatchedNew;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
matched: allMatched,
|
|
67
|
+
unmatchedOld: currentUnmatchedOld,
|
|
68
|
+
unmatchedNew: currentUnmatchedNew,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/matching/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAgBzF;;;GAGG;AACH,SAAS,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AC;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;QAExE,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QACnC,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC;QAC1C,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,OAAO,EAAE,UAAU;QACnB,YAAY,EAAE,mBAAmB;QACjC,YAAY,EAAE,mBAAmB;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MatchStrategy } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a mapped ID matching strategy.
|
|
4
|
+
*
|
|
5
|
+
* Translates old requirement IDs using a mapping table before matching.
|
|
6
|
+
* Only matches requirements whose old ID appears in the mapping table and
|
|
7
|
+
* whose mapped new ID exists in the new requirements.
|
|
8
|
+
*
|
|
9
|
+
* Confidence is 0.95 for mapped matches (slightly less than exact ID
|
|
10
|
+
* because the match depends on the accuracy of the mapping table).
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMappedIdStrategy(mapping: Record<string, string>): MatchStrategy;
|
|
13
|
+
//# sourceMappingURL=mapped-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapped-id.d.ts","sourceRoot":"","sources":["../../src/matching/mapped-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CA8FrF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a mapped ID matching strategy.
|
|
3
|
+
*
|
|
4
|
+
* Translates old requirement IDs using a mapping table before matching.
|
|
5
|
+
* Only matches requirements whose old ID appears in the mapping table and
|
|
6
|
+
* whose mapped new ID exists in the new requirements.
|
|
7
|
+
*
|
|
8
|
+
* Confidence is 0.95 for mapped matches (slightly less than exact ID
|
|
9
|
+
* because the match depends on the accuracy of the mapping table).
|
|
10
|
+
*/
|
|
11
|
+
export function createMappedIdStrategy(mapping) {
|
|
12
|
+
return {
|
|
13
|
+
name: 'mappedId',
|
|
14
|
+
match(oldReqs, newReqs) {
|
|
15
|
+
const result = {
|
|
16
|
+
matched: [],
|
|
17
|
+
unmatchedOld: [],
|
|
18
|
+
unmatchedNew: [],
|
|
19
|
+
};
|
|
20
|
+
// Build a map of new requirements by id, detecting duplicates.
|
|
21
|
+
// When multiple requirements share the same ID, the ID is ambiguous
|
|
22
|
+
// and cannot be used for matching — all duplicates go to unmatchedNew.
|
|
23
|
+
const newById = new Map();
|
|
24
|
+
const duplicateNewIds = new Set();
|
|
25
|
+
for (const req of newReqs) {
|
|
26
|
+
const id = req['id'];
|
|
27
|
+
if (typeof id === 'string') {
|
|
28
|
+
if (newById.has(id)) {
|
|
29
|
+
duplicateNewIds.add(id);
|
|
30
|
+
newById.delete(id);
|
|
31
|
+
}
|
|
32
|
+
else if (!duplicateNewIds.has(id)) {
|
|
33
|
+
newById.set(id, req);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Build a map of old requirements by id, detecting duplicates.
|
|
38
|
+
const oldById = new Map();
|
|
39
|
+
const duplicateOldIds = new Set();
|
|
40
|
+
for (const req of oldReqs) {
|
|
41
|
+
const id = req['id'];
|
|
42
|
+
if (typeof id === 'string') {
|
|
43
|
+
if (oldById.has(id)) {
|
|
44
|
+
duplicateOldIds.add(id);
|
|
45
|
+
oldById.delete(id);
|
|
46
|
+
}
|
|
47
|
+
else if (!duplicateOldIds.has(id)) {
|
|
48
|
+
oldById.set(id, req);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Track which new reqs have been matched
|
|
53
|
+
const matchedNewIds = new Set();
|
|
54
|
+
// Try to match old requirements using the mapping table (skip duplicate old IDs)
|
|
55
|
+
for (const oldReq of oldReqs) {
|
|
56
|
+
const oldId = oldReq['id'];
|
|
57
|
+
if (typeof oldId !== 'string' || duplicateOldIds.has(oldId)) {
|
|
58
|
+
result.unmatchedOld.push(oldReq);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const mappedNewId = mapping[oldId];
|
|
62
|
+
if (mappedNewId === undefined) {
|
|
63
|
+
result.unmatchedOld.push(oldReq);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Skip if the mapped new ID is a duplicate
|
|
67
|
+
if (duplicateNewIds.has(mappedNewId)) {
|
|
68
|
+
result.unmatchedOld.push(oldReq);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const newReq = newById.get(mappedNewId);
|
|
72
|
+
if (newReq && !matchedNewIds.has(mappedNewId)) {
|
|
73
|
+
result.matched.push({
|
|
74
|
+
oldReq,
|
|
75
|
+
newReq,
|
|
76
|
+
strategy: 'mappedId',
|
|
77
|
+
confidence: 0.95,
|
|
78
|
+
});
|
|
79
|
+
matchedNewIds.add(mappedNewId);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
result.unmatchedOld.push(oldReq);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Collect unmatched new requirements (including all duplicates)
|
|
86
|
+
for (const req of newReqs) {
|
|
87
|
+
const id = req['id'];
|
|
88
|
+
if (typeof id === 'string') {
|
|
89
|
+
if (duplicateNewIds.has(id) || !matchedNewIds.has(id)) {
|
|
90
|
+
result.unmatchedNew.push(req);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
result.unmatchedNew.push(req);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=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CAAC;oBAC9C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;wBAClB,MAAM;wBACN,MAAM;wBACN,QAAQ,EAAE,UAAU;wBACpB,UAAU,EAAE,IAAI;qBACjB,CAAC,CAAC;oBACH,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;YAED,gEAAgE;YAChE,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;gBAC1B,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;gBACrB,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;oBAC3B,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;wBACtD,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAChC,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of matching requirements between two evaluations.
|
|
3
|
+
*/
|
|
4
|
+
export interface MatchResult {
|
|
5
|
+
/** Paired requirements with their match metadata */
|
|
6
|
+
matched: MatchPair[];
|
|
7
|
+
/** Requirements only in the old evaluation (unmatched) */
|
|
8
|
+
unmatchedOld: Record<string, unknown>[];
|
|
9
|
+
/** Requirements only in the new evaluation (unmatched) */
|
|
10
|
+
unmatchedNew: Record<string, unknown>[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A single matched pair of requirements.
|
|
14
|
+
*/
|
|
15
|
+
export interface MatchPair {
|
|
16
|
+
/** The requirement from the old evaluation */
|
|
17
|
+
oldReq: Record<string, unknown>;
|
|
18
|
+
/** The requirement from the new evaluation */
|
|
19
|
+
newReq: Record<string, unknown>;
|
|
20
|
+
/** Name of the strategy that produced this match */
|
|
21
|
+
strategy: string;
|
|
22
|
+
/** Confidence score for the match (0.0 - 1.0) */
|
|
23
|
+
confidence: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A pluggable strategy for matching requirements between evaluations.
|
|
27
|
+
*/
|
|
28
|
+
export interface MatchStrategy {
|
|
29
|
+
/** Unique name for this strategy */
|
|
30
|
+
name: string;
|
|
31
|
+
/** Match old requirements against new requirements */
|
|
32
|
+
match(oldReqs: Record<string, unknown>[], newReqs: Record<string, unknown>[]): MatchResult;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/matching/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACxC,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,WAAW,CAAC;CAC5F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/matching/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize InSpec exec-json v1 format to HDF v2 structure for diffing.
|
|
3
|
+
*
|
|
4
|
+
* V1 uses: profiles[].controls[].results[].code_desc, source_location, start_time
|
|
5
|
+
* V2 uses: baselines[].requirements[].results[].codeDesc, sourceLocation, startTime
|
|
6
|
+
*
|
|
7
|
+
* This module detects v1 documents and converts them in-memory to v2 shape
|
|
8
|
+
* so the diff engine only needs to handle one format.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Detect whether a document is v1 (InSpec exec-json) format.
|
|
12
|
+
* V1 has `profiles` at the top level; v2 has `baselines`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isV1Format(doc: Record<string, unknown>): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Normalize a document to v2-like structure. If already v2, returns as-is.
|
|
17
|
+
* If v1, converts profiles→baselines, controls→requirements, and snake_case→camelCase.
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeToV2(doc: Record<string, unknown>): Record<string, unknown>;
|
|
20
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwCH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAEhE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBnF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize InSpec exec-json v1 format to HDF v2 structure for diffing.
|
|
3
|
+
*
|
|
4
|
+
* V1 uses: profiles[].controls[].results[].code_desc, source_location, start_time
|
|
5
|
+
* V2 uses: baselines[].requirements[].results[].codeDesc, sourceLocation, startTime
|
|
6
|
+
*
|
|
7
|
+
* This module detects v1 documents and converts them in-memory to v2 shape
|
|
8
|
+
* so the diff engine only needs to handle one format.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Detect whether a document is v1 (InSpec exec-json) format.
|
|
12
|
+
* V1 has `profiles` at the top level; v2 has `baselines`.
|
|
13
|
+
*/
|
|
14
|
+
export function isV1Format(doc) {
|
|
15
|
+
return Array.isArray(doc['profiles']) && !Array.isArray(doc['baselines']);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalize a document to v2-like structure. If already v2, returns as-is.
|
|
19
|
+
* If v1, converts profiles→baselines, controls→requirements, and snake_case→camelCase.
|
|
20
|
+
*/
|
|
21
|
+
export function normalizeToV2(doc) {
|
|
22
|
+
if (!isV1Format(doc)) {
|
|
23
|
+
return doc;
|
|
24
|
+
}
|
|
25
|
+
const profiles = doc['profiles'];
|
|
26
|
+
const baselines = profiles.map(normalizeProfile);
|
|
27
|
+
// Preserve timestamp from statistics if available
|
|
28
|
+
const statistics = doc['statistics'];
|
|
29
|
+
return {
|
|
30
|
+
baselines,
|
|
31
|
+
statistics,
|
|
32
|
+
timestamp: doc['timestamp'],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function normalizeProfile(profile) {
|
|
36
|
+
const controls = profile.controls ?? [];
|
|
37
|
+
const requirements = controls.map(normalizeControl);
|
|
38
|
+
return {
|
|
39
|
+
name: profile.name,
|
|
40
|
+
title: profile.title,
|
|
41
|
+
version: profile.version,
|
|
42
|
+
checksum: profile.sha256 ? { algorithm: 'sha256', value: profile.sha256 } : undefined,
|
|
43
|
+
groups: profile.groups ?? [],
|
|
44
|
+
supports: profile.supports ?? [],
|
|
45
|
+
inputs: profile.attributes ?? [],
|
|
46
|
+
requirements,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function normalizeControl(control) {
|
|
50
|
+
const v1Results = control.results ?? [];
|
|
51
|
+
const results = v1Results.map(normalizeResult);
|
|
52
|
+
return {
|
|
53
|
+
id: control.id,
|
|
54
|
+
title: control.title,
|
|
55
|
+
descriptions: control.desc
|
|
56
|
+
? [{ label: 'default', data: control.desc }]
|
|
57
|
+
: [],
|
|
58
|
+
impact: control.impact,
|
|
59
|
+
tags: control.tags ?? {},
|
|
60
|
+
refs: control.refs ?? [],
|
|
61
|
+
code: control.code,
|
|
62
|
+
sourceLocation: control.source_location ?? control.sourceLocation,
|
|
63
|
+
results,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Map InSpec v1 result status values to HDF v2 Result_Status enum values.
|
|
68
|
+
*
|
|
69
|
+
* InSpec v1 uses: "passed", "failed", "skipped", "error"
|
|
70
|
+
* HDF v2 uses: "passed", "failed", "notApplicable", "notReviewed", "error"
|
|
71
|
+
*
|
|
72
|
+
* "skipped" in InSpec means the test was not executed (typically because a
|
|
73
|
+
* `describe.one_of` condition was not met, or `only_if` excluded it).
|
|
74
|
+
* This maps to "notReviewed" in HDF v2 — the requirement was not assessed.
|
|
75
|
+
*/
|
|
76
|
+
function normalizeResultStatus(v1Status) {
|
|
77
|
+
switch (v1Status) {
|
|
78
|
+
case 'skipped':
|
|
79
|
+
return 'notReviewed';
|
|
80
|
+
default:
|
|
81
|
+
return v1Status;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Normalize a timestamp string to RFC 3339 / ISO 8601 date-time format.
|
|
86
|
+
*
|
|
87
|
+
* InSpec v1 uses formats like "2017-09-22 14:12:15 -0400" which are not valid
|
|
88
|
+
* RFC 3339. This function attempts to parse and re-format such timestamps.
|
|
89
|
+
* If parsing fails, the original string is returned as-is.
|
|
90
|
+
*/
|
|
91
|
+
function normalizeTimestamp(timestamp) {
|
|
92
|
+
// Already valid ISO 8601 (contains 'T')
|
|
93
|
+
if (timestamp.includes('T')) {
|
|
94
|
+
return timestamp;
|
|
95
|
+
}
|
|
96
|
+
// Try to parse InSpec format: "YYYY-MM-DD HH:MM:SS +HHMM"
|
|
97
|
+
const parsed = new Date(timestamp);
|
|
98
|
+
if (!isNaN(parsed.getTime())) {
|
|
99
|
+
return parsed.toISOString();
|
|
100
|
+
}
|
|
101
|
+
return timestamp;
|
|
102
|
+
}
|
|
103
|
+
function normalizeResult(result) {
|
|
104
|
+
const rawStartTime = result.start_time ?? result.startTime ?? '';
|
|
105
|
+
const normalized = {
|
|
106
|
+
status: normalizeResultStatus(result.status),
|
|
107
|
+
codeDesc: result.code_desc ?? result.codeDesc ?? '',
|
|
108
|
+
startTime: rawStartTime ? normalizeTimestamp(rawStartTime) : rawStartTime,
|
|
109
|
+
};
|
|
110
|
+
// Only include optional fields when they have values
|
|
111
|
+
const runTime = result.run_time ?? result.runTime;
|
|
112
|
+
if (runTime !== undefined) {
|
|
113
|
+
normalized['runTime'] = runTime;
|
|
114
|
+
}
|
|
115
|
+
if (result.message !== undefined) {
|
|
116
|
+
normalized['message'] = result.message;
|
|
117
|
+
}
|
|
118
|
+
return normalized;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwCH;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,GAA4B;IACrD,OAAO,KA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IACvC,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;IACjE,MAAM,UAAU,GAA4B;QAC1C,MAAM,EAAE,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5C,QAAQ,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,IAAI,EAAE;QACnD,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY;KAC1E,CAAC;IAEF,qDAAqD;IACrD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC;IAClD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,UAAU,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;IAClC,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,UAAU,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HdfComparison } from '../types.js';
|
|
2
|
+
import type { RenderOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Render an HdfComparison as a CSV string.
|
|
5
|
+
*
|
|
6
|
+
* One row per requirement. Columns:
|
|
7
|
+
* - ID, Title, State, Old Status, New Status, Impact (Old), Impact (New), Change Reasons
|
|
8
|
+
*
|
|
9
|
+
* When `detail: 'full'`, an additional Field Changes column is included.
|
|
10
|
+
*
|
|
11
|
+
* Header row is always included. Standard CSV escaping (RFC 4180).
|
|
12
|
+
* Default detail level: `'control'`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function renderCsv(comparison: HdfComparison, options?: RenderOptions): string;
|
|
15
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../../src/renderers/csv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+BhD;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,aAAa,EACzB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAyCR"}
|