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

record-diff

v0.2.3

Published

> 一个对比两个记录集的差异的工具包,根据指定 keyName 来对比两条记录,并可分析出差异路径。 > - 可设置忽略某个键值 > - 支持是否全等对比 > - 输出差异节点路径 > - 细分变更类型,按新增,修改,删除

Downloads

5

Readme

record-diff

一个对比两个记录集的差异的工具包,根据指定 keyName 来对比两条记录,并可分析出差异路径。

  • 可设置忽略某个键值
  • 支持是否全等对比
  • 输出差异节点路径
  • 细分变更类型,按新增,修改,删除

Installation

npm i record-diff

Usage

const recordDiff = require('record-diff');
const a1 = [{id: 1 x: 'sth here', y: 'yy'}, {id: 2, xx: 1}];
const b1 = [{id: 1, x: 'sth changed', z: 'zz'}, {id: 3, xxx: 2}];
console.log(recordDiff(a1, b1, 'id'));
output:
{
    "changed": [ // 被变更的记录
        {
            "id": 1,
            "x": "sth changed",
            "z": "zz"
        }
    ],
    "changedDetails": [ // 被变更记录的详细路径节点
        {
            "1": {
                "$unset": {
                    "y": true
                },
                "$set": {
                    "x": "sth changed",
                    "z": "zz"
                }
            }
        }
    ],
    "added": [ // 新增的记录
        {
            "id": 3,
            "xxx": 2
        }
    ],
    "removed": [ // 移除的记录
        {
            "id": 2,
            "xx": 1
        }
    ]
}

API

recordDiff(beforeRecord, afterRecord, keyName, options);

beforeRecord = [] Array

被对比的数据集

afterRecord = [] Array

新的数据集

key = 'id' String|Number

每条记录中的主键,用于对于

options

  • strictEqual = true boolean 是否使用严格匹配模式来对比每个值,即使用 ===

  • ignoreKey string
    忽略对比某个 key

  • stringifyEqual = false boolean 是否把值都转为 String 值来对比

  • inc = false boolean 是否对比差值,如果为 true,则尝试转换值为数值类型,并计算差值,会在 changedDetails $inc 字段中体现。