Gathering detailed insights and metrics for @egjs/list-differ
Gathering detailed insights and metrics for @egjs/list-differ
➕➖🔄 A module that checks the diff when values are added, removed, or changed in an array.
npm install @egjs/list-differ
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
99.5
Quality
82.6
Maintenance
100
Vulnerability
100
License
TypeScript (66.45%)
HTML (31.8%)
JavaScript (1.74%)
Total Downloads
13,471,628
Last Day
22,832
Last Week
103,172
Last Month
469,317
Last Year
5,661,987
63 Stars
22 Commits
3 Forks
10 Watching
10 Branches
9 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
@egjs/list-differ@1.0.1
Unpacked Size
101.98 kB
Size
17.83 kB
File Count
19
NPM Version
8.5.5
Node Version
16.15.0
Publised On
07 Apr 2023
Cumulative downloads
Total Downloads
Last day
-4.7%
22,832
Compared to previous day
Last week
-14.8%
103,172
Compared to previous week
Last month
-0%
469,317
Compared to previous month
Last year
48.9%
5,661,987
Compared to previous year
➕➖🔄 A module that checks the diff when values are added, removed, or changed in an array.
1$ npm i @egjs/list-differ
1<script src="//naver.github.io/egjs-list-differ/release/latest/dist/list-differ.min.js"></script>
Package | Version | Description |
---|---|---|
@egjs/children-differ | A module that checks diff in DOM children. | |
@egjs/react-children-differ | React port of @egjs/children-differ | |
@egjs/ngx-children-differ | Angular port of @egjs/children-differ | |
@egjs/vue-children-differ | Vue.js port of @egjs/children-differ |
1import ListDiffer, { diff } from "@egjs/list-differ"; 2 3// script => eg.ListDiffer 4// Value is key 5const differ = new ListDiffer([1, 2, 3, 4, 5, 6, 7], e => e); 6// const result = diff([1, 2, 3, 4, 5, 6, 7], [4, 3, 6, 2, 1, 7], e => e); 7const result = differ.update([4, 3, 6, 2, 1, 7]); 8// List before update 9// [1, 2, 3, 4, 5, 6, 7] 10console.log(result.prevList); 11// Updated list 12// [4, 3, 6, 2, 1, 7] 13console.log(result.list); 14// Index array of values added to `list` 15// [2] 16console.log(result.added); 17// Index array of values removed in `prevList` 18// [5, 4] 19console.log(result.removed); 20// An array of index pairs of `prevList` and `list` with different indexes from `prevList` and `list` 21// [[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]] 22console.log(result.changed); 23// The subset of `changed` and an array of index pairs that moved data directly. Indicate an array of absolute index pairs of `ordered`.(Formatted by: Array<[index of prevList, index of list]>) 24// [[3, 0], [2, 1], [1, 3]] 25console.log(result.pureChanged); 26// An array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array<[prevIndex, nextIndex]>) 27// [[3, 0], [3, 1], [3, 2]] 28console.log(result.ordered); 29// An array of index pairs of `prevList` and `list` that have not been added/removed so data is preserved 30// [[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]] 31console.log(result.maintained);
prevList
and list
with different indexes from prevList
and list
changed
and an array of index pairs that moved data directly. Indicate an array of absolute index pairs of ordered
.(Formatted by: Array<[index of prevList, index of list]>)changed | pureChanged: | |
---|---|---|
[[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]] | [[[3, 0], [2, 1], [1, 3]] | |
prevList | ||
process | - | |
list |
An array of index pairs to be ordered
that can synchronize list
before adding data. (Formatted by: Array<[prevIndex, nextIndex]>)
removed -> ordered -> added | |
---|---|
prevList | |
removed [5, 4] | |
ordered | [[3, 0], [3, 1], [3, 2]] |
ordered[0] [3 => 0] | |
ordered[1] [3 => 1] | |
ordered[2] [3 => 2] | |
added [2] | |
list |
1import ListDiffer, { diff } from "@egjs/list-differ"; 2 3const prevList = [1, 2, 3, 4, 5, 6, 7]; 4const list = [4, 3, 6, 2, 1, 7]; 5// const differ = new ListDiffer(prevList, e => e); 6// const result = differ.update(list); 7const result = diff(prevList, list, e => e);
removed => ordered => added | |
---|---|
prevList | |
process | |
list |
1const nextList = prevList.slice(); 2result.removed.forEach(index => { 3 nextList.splice(index, 1); 4}); 5result.ordered.forEach(([from, to], i) => { 6 nextList.splice(from, 1); 7 nextList.splice(to, 0, list[result.pureChanged[i][1]]); 8}); 9result.added.forEach(index => { 10 nextList.splice(index, 0, list[index]); 11}); 12// `nextList` is the same as `list`. 13console.log(nextList);
1const parentElement = document.querySelector(".parent"); 2const children = parentElement.children; 3 4result.removed.forEach(index => { 5 children[index].remove(); 6}); 7result.ordered.forEach(([from, to]) => { 8 parentElement.insertBefore(children[from], children[from < to ? to + 1 : to]); 9}); 10result.added.forEach(index => { 11 parentElement.insertBefore(document.createElement("div"), children[index]); 12});
maintaind => added | |
---|---|
prevList | |
process | |
list |
1const nextList: number[] = []; 2result.removed.forEach(index => { 3 // There is a remove operation for the index. 4 // prevList[index]; 5}); 6result.maintained.forEach(([from, to]) => { 7 nextList[to] = list[to]; 8}); 9result.added.forEach(index => { 10 nextList[index] = list[index]; 11}); 12// `nextList` is the same as `list`. 13console.log(nextList);
1const parentElement = document.querySelector(".parent"); 2const children = parentElement.children; 3const prevChildren: Element[] = [].slice.call(parentElement.children); 4 5result.removed.forEach(index => { 6 prevChildren[index].remove(); 7}); 8result.maintained.forEach(([from, to]) => { 9 parentElement.appendChild(prevChildren[from]); 10}); 11result.added.forEach(index => { 12 parentElement.insertBefore(document.createElement("div"), children[index]); 13});
See CONTRIBUTING.md.
Please file an Issue.
@egjs/list-differ is released under the MIT license.
Copyright (c) 2019-present NAVER Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/7 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
65 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More