Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrielcsapo/optics
🕶 diffing strings with expert vision
https://github.com/gabrielcsapo/optics
ascii diff javascript terminal utility
Last synced: 21 days ago
JSON representation
🕶 diffing strings with expert vision
- Host: GitHub
- URL: https://github.com/gabrielcsapo/optics
- Owner: gabrielcsapo
- License: apache-2.0
- Created: 2018-03-22T20:40:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-26T05:59:34.000Z (over 6 years ago)
- Last Synced: 2024-10-13T20:44:45.546Z (25 days ago)
- Topics: ascii, diff, javascript, terminal, utility
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# optics
> 🕶 diffing strings with expert vision
[![Npm Version](https://img.shields.io/npm/v/optics.svg)](https://www.npmjs.com/package/optics)
[![Build Status](https://travis-ci.org/gabrielcsapo/optics.svg?branch=master)](https://travis-ci.org/gabrielcsapo/optics)
[![Coverage Status](https://lcov-server.gabrielcsapo.com/badge/github%2Ecom/gabrielcsapo/optics.svg)](https://lcov-server.gabrielcsapo.com/coverage/github%2Ecom/gabrielcsapo/optics)
[![Dependency Status](https://starbuck.gabrielcsapo.com/badge/github/gabrielcsapo/optics/status.svg)](https://starbuck.gabrielcsapo.com/github/gabrielcsapo/optics)
[![devDependency Status](https://starbuck.gabrielcsapo.com/badge/github/gabrielcsapo/optics/dev-status.svg)](https://starbuck.gabrielcsapo.com/github/gabrielcsapo/optics#info=devDependencies)
[![npm](https://img.shields.io/npm/dt/optics.svg)]()
[![npm](https://img.shields.io/npm/dm/optics.svg)]()## TOC
- [Installation](#installation)
- [Usage](#usage)
- [diff](#diff)
- [arguments](#arguments)
- [returns](#returns)
- [Usage](#usage)
- [splitDiff](#splitdiff)
- [Usage](#usage)
- [combinedDiff](#combineddiff)
- [Usage](#usage)### Installation
```
npm install optics --save
```### Usage
```js
const Optics = require('optics');const source = `
hello worldhow are you?
what is up?
`const patch = `
hello worldyou 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
```js
const _diff = new Optics(source, patch);_diff.diff({ isCondensed: true, padding: 7 })
```#### splitDiff
> takes the same arguments that [diff](#diff) does.
##### Usage
```js
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](#diff) does.
##### Usage
```js
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]
```