New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ob-map

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ob-map

Simple object to object mapping.

0.2.1
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

ob-map

npm Build Status npm

Simple object mapper for creating flat javascript objects.

Description

Maps an object to a flat structure. Map object keys from one key to another with the help of a mapping object. Supports mapping of a nested object to a flat structure.

Installation

npm

npm install --save ob-map

yarn

yarn add ob-map

Usage

Flat Structure

import { map } from 'ob-map';

map(
  {
    a: 1,
    b: 2
  },
  {
    y: 'a',
    z: 'b'
  }
);
// => {y: 1, z: 2}

Nested Structure

import { map } from 'ob-map';

const obj = {
  a: {
    b: {
      c: 1
    }
  },
  d: {
    e: 2
  }
};

const mapping = {
  x: 'a.b.c',
  y: 'd.e'
};

map(obj, mapping);
// => {x: 1, y: 2}

Bulk Map

import { bulkMap } from 'ob-map';

const arr = [
  {
    a: 1,
    b: 2,
    c: 3
  },
  {
    a: 3,
    b: 4,
    c: 5
  }
];

const mapping = {
  x: 'a',
  y: 'b',
  z: 'c'
};

bulkMap(arr, mapping);
// => [{ x: 1, y: 2, z: 3 },{ x: 3, y: 4, z: 5 }]

Keywords

object mapper

FAQs

Package last updated on 16 Dec 2018

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