Skip to content

diff()

typescript
function diff(
  fromXml: string,
  toXml: string,
  options?: DiffOptions,
): DiffResult

Parses and semantically diffs two DMN XML strings.

Parameters

NameTypeDescription
fromXmlstringXML content of the "before" file
toXmlstringXML content of the "after" file
optionsDiffOptionsOptional metadata

DiffOptions

typescript
interface DiffOptions {
  fromFile?: string  // shown in meta and renderer headers
  toFile?: string
}

Returns

DiffResult — a structured object containing the summary, metadata, and list of changes.

Example

typescript
import { diff } from '@veridtools/dmn-diff'

const result = diff(beforeXml, afterXml, {
  fromFile: 'v1.dmn',
  toFile:   'v2.dmn',
})

console.log(result.meta.hasChanges)       // boolean
console.log(result.summary.modified)      // number
console.log(result.changes.length)        // total number of changes

Algorithm

  1. Preprocess — remove BOM, expand CDATA to XML entities
  2. Parse — convert XML to a JavaScript object tree (namespace prefixes stripped)
  3. Normalize — apply defaults (hitPolicy, isCollection, preferredOrientation), trim whitespace, remove DMNDI
  4. Index — build Map<id, element> by traversing the entire tree
  5. Diff — for every ID in either model: added / removed / modified (with field-level comparison)
  6. LCS fallback — for unindexed elements (rules, bindings, contextEntries without IDs)

Released under the MIT License.