# ngx-diff-lib

> A wrapper in angular to use the diff npm library (https://www.npmjs.com/package/diff) create by RedactedRevolution

Latest version **0.0.3** (published 2020-10-28) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install ngx-diff-lib
pnpm add ngx-diff-lib
yarn add ngx-diff-lib
bun add ngx-diff-lib
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2020-10-28 |
| First published | 2019-10-02 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 219.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Redacted Revolution |
| Maintainers | redactedrevolution |

## Links

- npm: https://www.npmjs.com/package/ngx-diff-lib
- npm.io page: https://npm.io/package/ngx-diff-lib

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Recent versions

- 0.0.3 (latest) — 2020-10-28
- 0.0.2 — 2020-06-23
- 0.0.1 — 2019-10-02

## README

# NgxJsDiffLib

A wrapper in angular to use the diff npm library (https://www.npmjs.com/package/diff) create by RedactedRevolution

Use the service to generate an HTML of the the strings that are being compared.

APIs
setConfig(Config)
Takes in an argument of Config type and sets the config. Refer below for config type

getHTMLForDiff(data1: string, data2: string, config?: Config): StringDom
Accepts 2 strings and a config. If config is sent here it will override the config that/if you have set via setConfig
Returns an output of the type StringDom.(Refer below)

Types
Config {
  domStyleType: DOMStyleType;
  diffType: DiffType;
  classOne?: string;
  classTwo?: string;
  emptyStringNotifier?: string;
  ignoreCase?: boolean;
}

domStyleType - enum DOMStyleType {
    Bold,
    Italics,
    Class
    }
Bold - denotes diffs with `<strong>` tag
Italics - denotes diffs with `<em>` tag
Class - denotes diffs with `<span>` tag with approriate class that is sent
Note :- You will have to set the encapsulation property of your component to ViewEncapsulation.ShadowDom to reflect your css classes

diffType - enum DiffType {
  Chars,
  Words
}
Currently support only for char and word diff
Chars - diff by character
Words - diff by word

classOne - (optional) When DOMStyleType.Class , this will be added to string one

classTwo - (optional) When DOMStyleType.Class , this will be added to string two

emptyStringNotifier - (optional) Use if you want to denote an empty string with any other character

ignoreCase - (optional) Defaults to false

StringDom {
  string1: string;
  string2: string;
}

Example
In your component
DOM: any;
  constructor(private ngxDiff: NgxJsDiffLibService) { }

  ngOnInit() {
  }

  getDOM(in1, in2) {
    this.DOM = this.ngxDiff.getHTMLForDiff(in1, in2, {
      diffType: DiffType.Words,
      domStyleType: DOMStyleType.Class, classOne: 'cr', classTwo: 'bl',
      emptyStringNotifier: '..', ignoreCase: true
    });
  }

In your html
`<div [innerHTML]="DOM.string1"></div>
<div [innerHTML]="DOM.string2"></div>`

Sample Input when using diff words
String 1 :  'Winter is coming'
String 2 :  'Winter is here'

Output
String 1 :  'Winter is <strong>coming</strong>'
String 2 :  'Winter is <strong>here</strong>'

---
_Source: https://npm.io/package/ngx-diff-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
