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-jsThis will automatically download the appropriate diffx binary for your system from GitHub Releases.
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 recursivelyignoreKeysRegex: Ignore keys matching regex patternepsilon: Tolerance for floating-point comparisonscontext: 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 linkLicense
This project is licensed under the MIT License.