
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
record-comparison
Advanced tools
A javascript tool to compare array quickly and you can do something when matching
A javascript tool to compare array quickly and you can do something when matching, for browsers and NodeJS servers
Via Janden Ma
MIT LICENCE
This package is now EOL, you can continue to use it but maybe no more support or maintenance.
Well, don't worry, you can migrate to @rinxun/record-comparison seamlessly, and the new package is more friendly with TypeScript.
detailBookMark
would be messed. (v0.3.3)If you use this tool to compare arrays, you need to specify one of those as the master array, so others are detail array(s).
When you call compare()
function, this tool will generate a master pointer for master array and detail pointer for detail array.
If master item and detail item have finished matching, you need to call detailMoveNext()
to move detail pointer to next detail item for next comparison.
If master item and detail item can't matched, you need to call masterMoveNext()
to move master pointer to next master item for next comparison.
npm
npm install record-comparison -S
yarn
yarn add record-comparison --save
Single comparison
// if NodeJS server
const RecordComparison = require("record-comparison");
// if browsers
// import RecordComparison from "record-comparison";
const rc = new RecordComparison(
[
{ name: "Lucy", age: 28, amount: 10 },
{ name: "Yuki", age: 20, amount: 20 },
{ name: "Tommy", age: 26, amount: 30 },
{ name: "Ben", age: 29, amount: 40 }
],
[
{ name: "Tommy", age: 28, amount: 109 },
{ name: "Joey", age: 23, amount: 200 },
{ name: "Lucy", age: 27, amount: 101 },
{ name: "Andy", age: 30, amount: 38 },
{ name: "Yuki", age: 22, amount: 59 },
{ name: "Ben", age: 29, amount: 8 }
]
);
rc.masterFields = [{ field: "name", order: "DESC" }];
rc.detailFields = [{ field: "name", order: "DESC" }];
while (rc.masterEof) {
while (rc.compare()) {
rc.currentRow["amount"] = rc.currentRow["amount"] + rc.detailRow["amount"];
rc.detailMoveNext();
}
rc.masterMoveNext();
}
console.log(rc.master);
/**
[
{ name: "Ben", age: 29, amount: 48 },
{ name: "Lucy", age: 28, amount: 111 },
{ name: "Tommy", age: 26, amount: 139 },
{ name: "Yuki", age: 20, amount: 79 },
]
**/
Multiple comparison
// if NodeJS server
const RecordComparison = require("record-comparison");
// if browsers
// import RecordComparison from "record-comparison";
const rc = new RecordComparison(
[
{ name: "Lucy", age: 28, amount: 10 },
{ name: "Yuki", age: 20, amount: 20 },
{ name: "Tommy", age: 26, amount: 30 },
{ name: "Ben", age: 29, amount: 40 }
],
[
[
{ name: "Tommy", age: 28, amount: 109 },
{ name: "Joey", age: 23, amount: 200 },
{ name: "Lucy", age: 27, amount: 101 },
{ name: "Andy", age: 30, amount: 38 },
{ name: "Yuki", age: 22, amount: 59 },
{ name: "Ben", age: 29, amount: 8 }
],
[
{ name: "Joey", age: 23, amount: 30 },
{ name: "Yuki", age: 22, amount: 12 },
{ name: "Lucy", age: 27, amount: 20 },
]
]
);
rc.masterFields = [{ field: "name", order: "DESC" }];
rc.detailFieldsArr = [
[{ field: "name", order: "DESC" }],
[{ field: "name", order: "DESC" }]
];
while (rc.masterEof) {
while (rc.compare(0)) {
rc.currentRow["amount"] = rc.currentRow["amount"] + rc.detailRow["amount"];
rc.detailMoveNext(0);
}
while (rc.compare(1)) {
rc.currentRow["amount"] = rc.currentRow["amount"] - rc.detailRow["amount"];
rc.detailMoveNext(1);
}
rc.masterMoveNext();
}
console.log(rc.master);
/**
[
{ name: "Ben", age: 29, amount: 48 },
{ name: "Lucy", age: 28, amount: 91 },
{ name: "Tommy", age: 26, amount: 139 },
{ name: "Yuki", age: 20, amount: 59 },
]
**/
Import library package
import RecordComparison from 'record-comparison'
// or
const RecordComparison = require('record-comparison')
Instantiate RecordComparison
const rc = new RecordComparison(masterArray, detailArray);
Array<object>
Array<object>
Array<Array<object>>
API
Array<object>
Array<object>
Array<Array<object>>
object
index
parameter in compare()
)object
Array<{ field: string, order?: 'ASC' | 'DESC' }> | null
field
is the field nameorder
is the ordering rule, default 'ASC'
for ascending
Array<{ field: string, order?: 'ASC' | 'DESC' }> | null
field
is the field nameorder
is the ordering rule, default 'ASC'
for ascending
Array<Array<{ field: string; order?: 'ASC' | 'DESC' }>> | null
field
is the field nameorder
is the ordering rule, default 'ASC'
for ascending
false
that means finish comparingboolean
true
to ensure the performanceFunction
number
, for multiple comparison, default 0
True
for matching, or False
0
).number
0
).number
, for multiple comparison, default 0
number
number
, for multiple comparison, default 0
FAQs
A javascript tool to compare array quickly and you can do something when matching
The npm package record-comparison receives a total of 122 weekly downloads. As such, record-comparison popularity was classified as not popular.
We found that record-comparison demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.