Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
collection-visit
Advanced tools
Visit a method over the items in an object, or map visit over the objects in an array.
The collection-visit npm package is designed to provide a simple way to visit and apply functions to elements in an object or array. It allows developers to easily manipulate and handle collections of data by iterating over them and invoking a specified method on each element of the collection.
Visiting objects
This feature allows you to visit a specific path within an object and perform operations on it. In the code sample, the `visit` function is used to log the value at the path 'a.b' within the object.
const visit = require('collection-visit');
const obj = { a: { b: { c: 'd' } } };
visit(obj, 'a.b', console.log); // logs { c: 'd' }
Visiting arrays
This feature enables visiting elements within an array and applying a function to each element. The code sample demonstrates visiting each object in the array and logging the 'name' property.
const visit = require('collection-visit');
const arr = [{ name: 'Alice' }, { name: 'Bob' }];
visit(arr, 'name', console.log); // logs 'Alice' and 'Bob'
Lodash is a comprehensive toolkit similar to collection-visit but with a broader range of utilities for working with arrays, numbers, objects, strings, etc. It includes functions like _.get and _.set for deep property access similar to what collection-visit offers but with additional capabilities like deep cloning, merging, and more.
Object-visit is similar to collection-visit but is specifically tailored for objects. It allows you to visit and update values at specified paths within an object. It's more specialized compared to collection-visit which handles both arrays and objects.
Visit a method over the items in an object, or map visit over the objects in an array.
Install with npm:
$ npm install --save collection-visit
var visit = require('collection-visit');
var ctx = {
data: {},
set: function (key, value) {
if (typeof key === 'object') {
visit(ctx, 'set', key);
} else {
ctx.data[key] = value;
}
}
};
ctx.set('a', 'a');
ctx.set('b', 'b');
ctx.set('c', 'c');
ctx.set({d: {e: 'f'}});
console.log(ctx.data);
//=> {a: 'a', b: 'b', c: 'c', d: { e: 'f' }};
visit
over an array of objects. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
13 | jonschlinkert |
9 | doowb |
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.5.0, on April 09, 2017.
FAQs
Visit a method over the items in an object, or map visit over the objects in an array.
The npm package collection-visit receives a total of 8,176,530 weekly downloads. As such, collection-visit popularity was classified as popular.
We found that collection-visit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.