@everymundo/ngx-object-diff

中文文档
0.0.4发布于 2023/03/10MITTypeScriptESM + CJS近 30 天下载 2334

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

原始使用文档
文档目录5 节
  1. Installation
  2. Import the NgxObjectDiffModule
  3. Inject the service
  4. Component
  5. Alternate approach

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

版本与发布记录

@everymundo/ngx-object-diff 共发布 1 个版本,首次发布于 2023/03/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.4latest2023/03/103 年前

关于 @everymundo/ngx-object-diff 的常见问题

@everymundo/ngx-object-diff 是什么?

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

如何安装 @everymundo/ngx-object-diff?

在项目目录运行 npm install @everymundo/ngx-object-diff,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/core(>=13.0.0)、@angular/common(>=13.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@everymundo/ngx-object-diff 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@everymundo/ngx-object-diff 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@everymundo/ngx-object-diff 可以商用吗?

@everymundo/ngx-object-diff 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@everymundo/ngx-object-diff 的下载量有多少?

根据 npm 官方下载统计,@everymundo/ngx-object-diff 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,334 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@everymundo/ngx-object-diff 还在维护吗?

最新版本 0.0.4 发布于 2023/03/10(3 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/03/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。