Gathering detailed insights and metrics for @egjs/list-differ
Gathering detailed insights and metrics for @egjs/list-differ
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
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
63 Stars
22 Commits
3 Forks
10 Watching
10 Branches
9 Contributors
Updated on 01 Aug 2024
TypeScript (66.45%)
HTML (31.8%)
JavaScript (1.74%)
Cumulative downloads
Total Downloads
Last day
-14.9%
21,716
Compared to previous day
Last week
-0.2%
128,125
Compared to previous week
Last month
5.2%
539,938
Compared to previous month
Last year
42.8%
5,339,206
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, 8, 2, 1, 7], e => e); 7const result = differ.update([4, 3, 8, 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, 8, 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// An array of index pairs to be `ordered` that can synchronize `list` before adding data. (Formatted by: Array<[prevIndex, nextIndex]>) 24// [[0, 3], [0, 2], [0, 1]] 25console.log(result.ordered); 26// An array of index pairs of `prevList` and `list` that have not been added/removed so data is preserved 27// [[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]] 28console.log(result.maintained);
prevList
and list
with different indexes from prevList
and list
changed | |
---|---|
[[3, 0], [2, 1], [1, 3], [0, 4], [6, 5]] | |
prevList | |
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 | [[0, 3], [0, 2], [0, 1]] |
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, 8, 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 const element = nextList.splice(from, 1)[0]; 7 nextList.splice(to, 0, element); 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});
maintained => 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
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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