npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@miccou/ngx-text-diff

v17.0.1

Published

A Text Diff component for Angular.

Downloads

91

Readme

ngx-text-diff

  • A simple text diff component to be used with Angular and based on google diff match patch library.

Dependencies

  • diff-match-patch: ^1.0.5
  • tslib: ^2.0.0

Required Packages

These packages will not be auto-installed and must be installed in addition to this library.

  • @angular/common >= 17.0.0
  • @angular/core >= 17.0.0
  • @angular/forms >= 17.0.0
  • @angular/cdk >= 16.0.0 or >= 17.0.0 (used for scrolling synchronization) (supports 16 and 17 to support people using @angular/material@16 for legacy components)

Demo

Ngx Text Diff Demo

Installation

npm i @miccou/ngx-text-diff

API

module: NgxTextDiffModule
component: NgxTextDiffComponent
selector: td-ngx-text-diff

Inputs

| Input | Type | Required | Description | | -------------------- | ----------------- | ------------------------------- | ----------------------------------------------------------------------------------------------- | | left | string | Yes | First text to be compared | | right | string | Yes | Second text to be compared | | diffContent | Observable | Optional | DiffContent observable | | format | DiffTableFormat | Optional, default: SideBySide | Possible values: -SideBySide -LineByLine | | loading | boolean | Optional, default: false | Possible values: -true: shows an loading spinner.- false: hides the loading spinner | | hideMatchingLines | boolean | Optional, default: false | Possible values: -true: Only shows lines with differences.- false: shows all lines | | showToolbar | boolean | Optional, default: true | Possible values: -true: shows the toolbar.- false: hides the format toolbar | | showBtnToolbar | boolean | Optional, default: true | Possible values: -true: shows the format toolbar.- false: hides the format toolbar | | outerContainerClass | any | Optional | ngClass object for the outer div | | outerContainerStyle | any | Optional | ngStyle object for the outer style | | toolbarClass | any | Optional | ngClass object for the toolbar div | | toolbarStyle | any | Optional | ngStyle object for the toolbar style | | compareRowsClass | any | Optional | ngClass object for the div surrounding the table rows | | compareRowsStyle | any | Optional | ngStyle object for the div surrounding the table rows | | synchronizeScrolling | boolean | Optional, default: true | Possible values: -true: Scrolls both tables together.- false: Scrolls individually |

Output

| Input | Type | Required | Description | | -------------- | ----------- | -------- | --------------------------------------- | | compareResults | DiffResults | Optional | Event fired when comparison is executed |

Custom Objects

export interface DiffContent {
  leftContent: string;
  rightContent: string;
}

export type DiffTableFormat = 'SideBySide' | 'LineByLine';

export interface DiffResults {
  hasDiff: boolean;
  diffsCount: number;
  rowsWithDiff: {
    leftLineNumber?: number;
    rightLineNumber?: number;
    numDiffs: number;
  }[];
}

Usage

  1. Register the NgxTextDiffModule in a module, for example app module.
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ScrollDispatchModule } from '@angular/cdk/scrolling';

import { AppComponent } from './app.component';
import { NgxTextDiffModule } from '@miccou/ngx-text-diff';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, ScrollDispatchModule, NgxTextDiffModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
import { Component, OnInit } from '@angular/core';
import { DiffContent, DiffResults } from '@miccou/ngx-text-diff/lib/ngx-text-diff.model';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: []
})
export class HomeComponent implements OnInit {
  left = `some text to\nbe compared!`
  right = `A changed\n version \n of the text to\nbe compared!`

  constructor() {}

  ngOnInit() {
  }

  onCompareResults(diffResults: DiffResults) {
    console.log('diffResults', diffResults);
  }
}
<td-ngx-text-diff
  [left]="left"
  [right]="right"
  (compareResults)="onCompareResults($event)"
>

Build the NgxTextDiff module

Run ng build ngx-text-diff to build the library. The build artifacts will be stored in the dist/ngx-text-diff directory.

Credits

This project is based on google diff match patch.

Thanks to the original author Alfredo Benassi and most recent maintainer Anargyros Roussos for their work on this project.