JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 95
  • Score
    100M100P100Q74875F
  • License MIT

A Node.js wrapper for the diffx CLI tool - semantic diffing of JSON, YAML, TOML, XML, INI, and CSV files. Focuses on structural meaning rather than formatting.

Package Exports

  • diffx-js
  • diffx-js/lib.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (diffx-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

diffx-js

A Node.js wrapper for the diffx CLI tool.

Installation

npm install diffx-js

This package includes pre-compiled diffx binaries for all supported platforms (Linux x64, macOS x64/ARM64, Windows x64), enabling completely offline installation with no external downloads required.

Supported Platforms

  • Linux x64 - Intel/AMD 64-bit
  • macOS x64 - Intel-based Macs
  • macOS ARM64 - Apple Silicon Macs (M1/M2/M3)
  • Windows x64 - 64-bit Windows

The appropriate binary is automatically selected at runtime based on your system.

Note: Due to bundling all platform binaries, this package is larger (~20MB) than typical npm packages but provides complete offline functionality.

Usage

const { diff, diffString } = require('diffx-js');

async function main() {
  // Compare two files
  const result = await diff('file1.json', 'file2.json');
  
  if (result.length === 0) {
    console.log("No differences found.");
  } else {
    console.log("Differences found:");
    for (const change of result) {
      console.log(`${change.type}: ${change.path} = ${change.new_value}`);
    }
  }

  // Compare with options
  const jsonResult = await diff('config1.yaml', 'config2.yaml', {
    output: 'json',
    ignoreKeysRegex: 'timestamp'
  });

  // Compare directory structures
  const dirResult = await diff('dir1/', 'dir2/', {
    recursive: true,
    output: 'json'
  });

  // Compare strings directly
  const stringResult = await diffString(
    '{"a": 1}', 
    '{"a": 2}', 
    'json',
    { output: 'json' }
  );
}

main();

API Reference

diff(input1, input2, options?)

  • input1, input2: File paths or directory paths to compare
  • options: Optional configuration object
    • format: Input format ('json', 'yaml', 'toml', 'xml', 'ini', 'csv')
    • output: Output format ('cli', 'json', 'yaml', 'unified')
    • recursive: Compare directories recursively
    • ignoreKeysRegex: Ignore keys matching regex pattern
    • epsilon: Tolerance for floating-point comparisons
    • context: Number of context lines in unified output

diffString(content1, content2, format, options?)

  • content1, content2: String content to compare
  • format: Data format ('json', 'yaml', 'toml', etc.)
  • options: Same as diff() options

Development

To link for local development:

npm link

License

This project is licensed under the MIT License.