README.md
1# libnpmdiff
2
3[](https://npm.im/libnpmdiff)
4[](https://npm.im/libnpmdiff)
5[](https://github.com/npm/cli/actions/workflows/ci-libnpmdiff.yml)
6The registry diff lib.
7
8## Table of Contents
9
10* [Example](#example)
11* [Install](#install)
12* [Contributing](#contributing)
13* [API](#api)
14* [LICENSE](#license)
15
16## Example
17
18```js
19const libdiff = require('libnpmdiff')
20
21const patch = await libdiff([
22 'abbrev@1.1.0',
23 'abbrev@1.1.1'
24])
25console.log(
26 patch
27)
28```
29
30Returns:
31
32```patch
33diff --git a/package.json b/package.json
34index v1.1.0..v1.1.1 100644
35--- a/package.json
36+++ b/package.json
37@@ -1,6 +1,6 @@
38 {
39 "name": "abbrev",
40- "version": "1.1.0",
41+ "version": "1.1.1",
42 "description": "Like ruby's abbrev module, but in js",
43 "author": "Isaac Z. Schlueter <i@izs.me>",
44 "main": "abbrev.js",
45
46```
47
48## Install
49
50`$ npm install libnpmdiff`
51
52### Contributing
53
54The npm team enthusiastically welcomes contributions and project participation!
55There's a bunch of things you can do if you want to contribute! The
56[Contributor Guide](https://github.com/npm/cli/blob/latest/CONTRIBUTING.md)
57outlines the process for community interaction and contribution. Please don't
58hesitate to jump in if you'd like to, or even ask us questions if something
59isn't clear.
60
61All participants and maintainers in this project are expected to follow the
62[npm Code of Conduct](https://docs.npmjs.com/policies/conduct), and just
63generally be excellent to each other.
64
65Please refer to the [Changelog](CHANGELOG.md) for project history details, too.
66
67Happy hacking!
68
69### API
70
71#### `> libnpmdif([ a, b ], [opts]) -> Promise<String>`
72
73Fetches the registry tarballs and compare files between a spec `a` and spec `b`. **npm** spec types are usually described in `<pkg-name>@<version>` form but multiple other types are alsos supported, for more info on valid specs take a look at [`npm-package-arg`](https://github.com/npm/npm-package-arg).
74
75**Options**:
76
77- `color <Boolean>`: Should add ANSI colors to string output? Defaults to `false`.
78- `tagVersionPrefix <Sring>`: What prefix should be used to define version numbers. Defaults to `v`
79- `diffUnified <Number>`: How many lines of code to print before/after each diff. Defaults to `3`.
80- `diffFiles <Array<String>>`: If set only prints patches for the files listed in this array (also accepts globs). Defaults to `undefined`.
81- `diffIgnoreAllSpace <Boolean>`: Whether or not should ignore changes in whitespace (very useful to avoid indentation changes extra diff lines). Defaults to `false`.
82- `diffNameOnly <Boolean>`: Prints only file names and no patch diffs. Defaults to `false`.
83- `diffNoPrefix <Boolean>`: If true then skips printing any prefixes in filenames. Defaults to `false`.
84- `diffSrcPrefix <String>`: Prefix to be used in the filenames from `a`. Defaults to `a/`.
85- `diffDstPrefix <String>`: Prefix to be used in the filenames from `b`. Defaults to `b/`.
86- `diffText <Boolean>`: Should treat all files as text and try to print diff for binary files. Defaults to `false`.
87- ...`cache`, `registry`, `where` and other common options accepted by [pacote](https://github.com/npm/pacote#options)
88
89Returns a `Promise` that fullfils with a `String` containing the resulting patch diffs.
90
91Throws an error if either `a` or `b` are missing or if trying to diff more than two specs.
92
93## LICENSE
94
95[ISC](./LICENSE)
96