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

lodash-mixin-diff-value

v2.0.0

Published

Lodash mixin to get a JSON object that represent the value variation of an object compared to another

Downloads

21

Readme

lodash-mixin-diff-value

Build Status npm version JavaScript Style Guide

This is a lodash mixin for getting a JSON object that rappresent the value variation of a JSON respect another.

Installation

npm install lodash-mixin-diff-value

Usage

const _ = require('lodash');
const differenceValues = require('lodash-mixin-diff-value');

_.mixin({ differenceValues });

const diff = _.differenceValues(editedJson, originalJson[, options]);

options is a json with the fields:

| Key | Values | Default | Description | | --- | ------ | ------- | ----------- | | extract | [only-add, only-remove, only-changed, only-add-change] | only-add-change | Described below | dateCheck | true or false | true | For performance: deactivate the date object and string evaluation | dateFormatIn | date-fns formats | yyyy-MM-dd'T'HH:mm:ss.SSS'Z' | The format to use to evaluate string during date checking | dateFormatOut | date-fns formats | yyyy-MM-dd'T'HH:mm:ss.SSS'Z' | The format to use to evaluate date-string comparison

Field: extract

  • only-add: will return only field that occurs in editedJson and not in originalJson
  • only-remove: will return only field that not occurs in editedJson and are in originalJson
  • only-changed: will return only field that occurs in editedJson and originalJson too
  • only-add-change: like only-add + only-changed

Field: dateCheck

If true: activate deep controls for the date object and strings. The input are evaluated with the options.dateFormatIn format and compared using the options.dateFormatOut format. This will enable you to read corectly a date in a format like options.dateFormatIn: yyyy-MM-dd but consider the date changed only if the year and month change options.dateFormatOut: yyyy-MM.

If false: only Date objects are evaluated as date.toISOString() for comparison.

Field: dateFormat

This format let you to execute the diff value on portion of the date string not only on the complete date. This cost in performance because all the string will be checked if match with this format.

Test

For run the tests simply execute:

npm test

Example

See test for more examples.

const oldObj = {
  a: 'b',
  arr: [1, 2, 3, { a: 111 }],
  more: 'more',
  intarr: [1, 2, 3, 4],
  newarr: [{ k: 'XXX' }, { k: 'val' }, 3333],
  arrtwo: [{ k: 'nod' }, { k: 'val' }],
  json: { a: 'a', b: 'b', c: 'c', d: { deep: [12, 3, { mode: 'deep' }] } },
  o: { sub: 'json' },
};

const newObj = {
  a: 'b',
  arr: [1, 22, 3, { a: 111, q: 'none' }],
  intarr: [1, 2, 3, 4],
  newarr: [{ k: 'XXX' }, { k: 'val' }, 3333],
  arrtwo: [{ k: 'XXX' }, { k: 'val' }, 3333],
  json: { a: 'a', b: 'b', c: 'c', d: { deep: [12, 333, { mode: 'deeper' }] } },
  o: { sub: 'json' },
};

const out = _.differenceValues(newObj, oldObj);

// Will print out:
{
  "arr": [
    22,
    {
      "q": "none"
    }
  ],
  "arrtwo": [
    {
      "k": "XXX"
    },
    3333
  ],
  "json": {
    "d": {
      "deep": [
        333,
        {
          "mode": "deeper"
        }
      ]
    }
  }
}

Todo

  • JSDoc
  • More test and validity-check
  • Managen functions

License

Copyright Manuel Spigolon, Licensed under MIT.