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

@everymundo/ngx-object-diff

v0.0.4

Published

An Angular 2+ library to compare and show object differences.

Downloads

173

Readme

NgxObjectDiff

An Angular 2+ library to compare and show object differences.

Demo

Screenshot

Installation

npm i ngx-object-diff

Available methods on NgxObjectDiff service

setOpenChar: set the opening character for the view, default is {

setCloseChar: set the closing character for the view, default is }

diff: compare and build all the difference of two objects including prototype properties

diffOwnProperties: compare and build the difference of two objects taking only its own properties into account

toJsonView: format a diff object to a full JSON formatted object view

toJsonDiffView: format a diff object to a JSON formatted view with only changes

objToJsonView: format any javascript object to a JSON formatted view

Usage

Import the NgxObjectDiffModule

import { NgxObjectDiffModule } from 'ngx-object-diff';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxObjectDiffModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Inject the service

  constructor(private objectDiff: NgxObjectDiffService) { }

  ngOnInit(): void {
    // This is required only if you want to show a JSON formatted view of your object
    this.object1View = this.objectDiff.objToJsonView(this.object1);
    this.object2View = this.objectDiff.objToJsonView(this.object2);
    
    // you can directly diff your objects js now or parse a Json to object and diff
    let diff = this.objectDiff.diff(this.object1, this.object2);
    // you can directly diff your objects including prototype properties and inherited properties using `diff` method
    let diffAll = ObjectDiff.diff($scope.yourObjectOne, $scope.yourObjectTwo);    

    // gives a full object view with Diff highlighted
    this.diffView = this.objectDiff.toJsonView(diff)
    // gives object view with only Diff highlighted
    this.diffValueChanges = ObjectDiff.toJsonDiffView(diff);
  }

Component

Bind the variables to ngx-object-diff Component.It will takes care of styling.

   <ngx-object-diff [obj]="object1View"></ngx-object-diff>
   <ngx-object-diff [obj]="object1View"></ngx-object-diff>
   <ngx-object-diff [obj]="diffView"></ngx-object-diff>
   <ngx-object-diff [obj]="diffValueChanges"></ngx-object-diff>

Alternate approach

Bind the variables directly in your html using the innerHTML property binding of Angular Use a <pre> element for better results

      <pre [innerHTML]="object1View" ></pre>
      <pre [innerHTML]="object2View" ></pre>
      <pre [innerHTML]="diffView" ></pre>
      <pre [innerHTML]="diffValueChanges"></pre>

Based on https://github.com/hipster-labs/angular-object-diff