Socket
Socket
Sign inDemoInstall

collection-visit

Package Overview
Dependencies
9
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    collection-visit

Visit a method over the items in an object, or map visit over the objects in an array.


Version published
Weekly downloads
11M
decreased by-10.92%
Maintainers
1
Install size
86.1 kB
Created
Weekly downloads
 

Package description

What is collection-visit?

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.

What are collection-visit's main functionalities?

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'

Other packages similar to collection-visit

Readme

Source

collection-visit NPM version

Visit a method over the items in an object, or map visit over the objects in an array.

  • map-visit: Map visit over an array of objects.
  • object-visit: Call the given method on each value in the given object.

Install

Install with npm

$ npm i collection-visit --save

Usage

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' }};

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on August 05, 2015.

Keywords

FAQs

Last updated on 05 Aug 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc