Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
array-keys
Advanced tools
Very simple library to manage array elements using a key instead of array index position. When dealing with very large sets of data all organized in an object reference, if the object structure is changing a lot you can end up with memory leaks and slow performance. In these cases it's better to keep an array of objects instead of and object of objects. The cost of iterating through the array is cheaper than the lack of garbage collection which can occur in large, changing, object hashes.
Should run in both node.js and browser environments.
var ak = new ArrayKeys({
identifier: 'key' // defaults to `id`
});
ak.getRecord('myInvalidKey'}); // returns undefined
ak.addRecord({
key: 'myKey1',
value: 'hello world!'
}); // returns true
ak.getRecord('myKey1'); // returns { key: 'myKey1', value: 'hello world!' }
ak.addRecord({
key: 'myKey2',
value: 'hello space!'
}); // returns true
ak.forEachRecord(function (record) {
// this function is called once for each record
}).finally(function (count) {
// function called after the above callback is called for each record
// count is the total number of records processed
});
ak.getIdentifiers(); // returns ['myKey1', 'myKey2']
ArrayKeys
also optionally supports emitting events. This functionality must be explicity enabled during object instantiation.
add
remove
update
var ak = new ArrayKeys({
emitEvents: true
});
ak.events.on('add', function (record) {
console.log(record.id); // 'foobar'
});
ak.addRecord({
id: 'foobar',
here: [ 'is', 'some' ],
data: true
});
var ak = new ArrayKeys({
identifier: 'id',
emitEvents: true
});
Add a new record.
ak.addRecord({
id: 'helloworld123',
foo: 'bar'
});
ak.addRecord({
id: 'pizza777',
blah: [ 1, 2, 3 ]
});
Get a record by it's identifier.
var record = ak.getRecord('helloworld123');
Get an array of the values of the record identifiers.
var ids = ak.getIdentifiers(); // 'helloworld123', 'pizza777'
Indicates whether a record exists by returning true
or false
.
if (ak.exists('blahblahblah')) {
console.log('yes!');
} else {
console.log('no');
}
// returns false, 'no'
Returns the number of the position of the record, specified by identifier.
var position = ak.getIndex('pizza777'); // returns 1
Calls a callback handler function for each record in the list, asyncronously.
ak.forEachRecord(function (record) {
// ... do something with record
}).finally(function (count) {
// ... do something at the end of the operation. First param is the number
// of items processed.
})
Removes the record specified by identifier.
ak.removeRecord('helloworld123');
Removes all records.
ak.removeAll();
ak.events.on('update', function (record){
...
});
ak.events.on('add', function (record){
...
});
ak.events.on('remove', function (record){
...
});
Project developed and maintained by Nick Jennings
FAQs
a simple interface to manage large arrays of objects easily
The npm package array-keys receives a total of 338 weekly downloads. As such, array-keys popularity was classified as not popular.
We found that array-keys 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.