Socket
Socket
Sign inDemoInstall

@egjs/list-differ

Package Overview
Dependencies
Maintainers
8
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egjs/list-differ

A module that checks diff when values are added, removed, or changed in an array.


Version published
Weekly downloads
124K
decreased by-3.38%
Maintainers
8
Weekly downloads
 
Created

What is @egjs/list-differ?

@egjs/list-differ is a lightweight JavaScript library designed to efficiently compute the differences between two lists. It is particularly useful for applications that need to update the DOM or other data structures based on changes in a list, such as in virtual DOM implementations or state management libraries.

What are @egjs/list-differ's main functionalities?

Compute Differences Between Lists

This feature allows you to compute the differences between two lists. The `update` method returns an object that describes the changes needed to transform the old list into the new list.

const { ListDiffer } = require('@egjs/list-differ');

const oldList = ['a', 'b', 'c'];
const newList = ['b', 'c', 'd'];

const differ = new ListDiffer();
const result = differ.update(oldList, newList);

console.log(result);

Track Insertions and Deletions

This feature allows you to track which items have been added or removed from the list. The `added` and `removed` properties of the result object provide the indices of the added and removed items, respectively.

const { ListDiffer } = require('@egjs/list-differ');

const oldList = ['a', 'b', 'c'];
const newList = ['b', 'c', 'd'];

const differ = new ListDiffer();
const result = differ.update(oldList, newList);

console.log(result.added); // [2]
console.log(result.removed); // [0]

Track Moved Items

This feature allows you to track items that have been moved within the list. The `maintained` property of the result object provides the indices of the items that have been moved.

const { ListDiffer } = require('@egjs/list-differ');

const oldList = ['a', 'b', 'c'];
const newList = ['c', 'a', 'b'];

const differ = new ListDiffer();
const result = differ.update(oldList, newList);

console.log(result.maintained); // [2, 0, 1]

Other packages similar to @egjs/list-differ

Keywords

FAQs

Package last updated on 08 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc