optics
v0.1.0
Published
🕶 diffing strings with expert vision
Downloads
43
Readme
optics
🕶 diffing strings with expert vision
TOC
Installation
npm install optics --save
Usage
const Optics = require('optics');
const source = `
hello world
how are you?
what is up?
`
const patch = `
hello world
you are who?
what is up?
`
const _diff = new Optics(source, patch)
Given an Optics instance you can now do the following to view it.
- splitDiff
- combinedDiff
- diff
diff
diff takes the following arguments passed an object
{ isCondensed = false, padding = 4 }
arguments
- isCondensed (boolean): this controls if the diff output is trimmed of unnecessary text that hasn't chnaged or not.
- padding (integer): this is used if isCondensed is set to true to control how much of that unnecessary is preserved in the output.
returns
- combined (string): a combined view of both removed and added values to the string
- removed (string): only outputs the removed values and the original values of the diff
- added (string): only outputs the added values and the original values of the diff
- totalLines (integer): the total number of lines (the max value between patch and source in order to get an even output)
- maxLineLength (integer): the longest string value
Usage
const _diff = new Optics(source, patch);
_diff.diff({ isCondensed: true, padding: 7 })
splitDiff
takes the same arguments that diff does.
Usage
const _diff = new Optics(source, patch);
_diff.splitDiff({ isCondensed: true, padding: 7 });
outputs (ansii colors will output if your output supports it)
[0] | [0]
[1] hello world | [1] hello world
[2] | [2]
[3] - how are you? | [3] + you are who?
[4] | [4]
[5] what is up? | [5] what is up?
[6] | [6]
combinedDiff
takes the same arguments that diff does.
Usage
const _diff = new Optics(source, patch);
_diff.combinedDiff({ isCondensed: true, padding: 7 });
outputs (ansii colors will output if your output supports it)
[0]
[1] hello world
[2]
[3] - how are you?
[3] + you are who?
[4]
[5] what is up?
[6]