https://github.com/okdistribute/diffs-to-string
Turns a diffs stream or array of diffs into a string.
https://github.com/okdistribute/diffs-to-string
Last synced: 5 months ago
JSON representation
Turns a diffs stream or array of diffs into a string.
- Host: GitHub
- URL: https://github.com/okdistribute/diffs-to-string
- Owner: okdistribute
- Created: 2015-06-02T23:59:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-11T22:55:51.000Z (almost 10 years ago)
- Last Synced: 2025-01-03T09:42:59.484Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 139 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# diffs-to-string
Turns an array of diffs into a string. You can generate a changes stream by using [sorted-diff-stream](github.com/maxogden/sorted-diff-stream).
[](https://nodei.co/npm/diffs-to-string/)
### basic example
```js
var diffs2string = require('diffs-to-string')var changes = [
[ { country: 'germany', capital: null },
{ country: 'germany', code: 'de', capital: 'berlin' } ],
[ { country: 'ireland', capital: 'dublin' },
{ country: 'ireland', code: 'ie', capital: 'dublin' } ],
[ { country: 'france', capital: 'paris' },
{ country: null, code: 'fr', capital: 'paris'} ],
[ { country: 'spain', capital: 'madrid' },
{ country: 'spain', code: 'es', capital: 'barcelona' } ]
]var visual = diffs2string(changes)
console.log(visual)
```Outputs:
```
row 1
country: germany
+ capital: berlin
+ code: de
row 2
country: ireland
capital: dublin
+ code: ie
row 3
- country: france
capital: paris
+ code: fr
row 4
country: spain
? capital: madrid -> barcelona
+ code: es
```### with streams
```js
var diffs2string = require('diffs-to-string').stream
var diffStream = from.obj(changes)diffStream.pipe(diffs2string())
```### custom row path and row header
```js
function getRowValue (row) {
return row.value
}function getRowHeader (diff) {
return 'this is row ' + diff['some-value'] + '\n'
}var opts = {
getRowValue: getRowValue,
getRowHeader: getRowHeader
}diffStream.pipe(diffs2string.stream(opts))
var visual = diffs2string(changes, opts)
```