Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iter-object

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iter-object

An object iterator and object replacer with callbacks for key-value pairs

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
450
increased by3.69%
Maintainers
1
Weekly downloads
 
Created
Source

iter-object

Downloads Version License

An object iterator and object replacer with callbacks for key-value pairs

Installation

npm install iter-object

or

yarn add iter-object

Usage

MethodParamsDescription
iter_obj(src: Object, fn: Function )Iterate over objects and display key-value pairs
iter_repl(src: Object, fn: Function ) => anyIterate over object and return modified or new values
iterObject

Example:

import { iter_obj } from 'iter-object';

const src = {
    owner: 'Alex',
    car: {
        make: 'Toyota',
        model: 'Matrix',
        year: 2013
    }
}

iter_obj(src, (key, value) => {
    console.log(key, value);
});

// output:
// owner Alex
// car { make: 'Toyota', model: 'Matrix', year: 2013 }
// make Toyota
// model Matrix
// year 2013
iterReplace

Example:

import { iter_repl } from 'iter-object';

const sellerContent = {
  owner: 'Alex',
  car: {
    make: 'Toyota',
    model: 'Matrix',
    year: 2013,
  },
};

const buyerContent = iter_repl(sellerContent, (key, value) => {
  switch(key) {
      case 'owner': {
          return 'New Buyer';
      }
      case 'car': {
          return { ...value, color: 'White' };
      }
      default: {
          return value;
      }
  }
});

console.log(JSON.stringify(buyerContent, null, 2));

// output:
// {
//   "owner": "New Buyer",
//   "car": {
//     "make": "Toyota",
//     "model": "Matrix",
//     "year": 2013,
//     "color": "White"
//   }

Keywords

FAQs

Package last updated on 05 Nov 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc