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

@digitregroup/object-mapper

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@digitregroup/object-mapper

Makes object-to-object transformation easy.

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-86.36%
Maintainers
4
Weekly downloads
 
Created
Source

object-mapper

Makes object-to-object transformation easy.

stars forks

Quick example

const sourceObject = {
  fabfour: { user_count: 4 },
  user: [
    {
      first:       'John',
      last:        'Lennon',
      instruments: [
        { name: 'Guitar', colour: 'Red' },
        { name: 'Bass guitar', colour: 'Blue' }
      ]
    },
    {
      first:   'Paul',
      last:    'McCartney',
      picture: ['picture0.jpg', 'picture1.png', 'picture2.gif' ]
    },
    { first: 'George', last: 'Harrison' },
    { first: 'Ringo', last: 'Starr' }
  ]
};

const mapping = {
  'ringo.last_name':        'user[first=Ringo].last',
  'paul.pictures':          'user.1.picture[]',
  'john.bass.colour':       'user.0.instruments.1.colour',
  'amount_of_band_members': 'fabfour.user_count',
};

const result = ObjectMapper.mapItem(sourceObject, mapping);

//{
//  "ringo": {
//    "last_name": "Starr"
//  },
//  "paul": {
//    "pictures": [
//      "picture0.jpg",
//      "picture1.png",
//      "picture2.gif"
//    ]
//  },
//  "john": {
//    "bass": {
//      "colour": "Blue"
//    }
//  },
//  "amount_of_band_members": 4
//}

Features

Dot notation matching

ObjectMapper.mapItem (
  {parent: {child: {value: 'bar'}}},
  {result: 'parent.child.value'}
);

// {"result":"bar"}

Query matching

ObjectMapper.mapItem (
  {
    children: [
      {name: 'foo', value: 'bar'},
      {name: 'baz', value: 'biz'}
    ]
  },
  {result: 'children[name=baz].value'}
);

// {"result":"biz"}

Data transformation

ObjectMapper.mapItem (
  {
    user: {
      name:      'lennon',
      firstname: 'john'
    }
  },
  {
    'result': [
      'user.name',
      name => name.toUpperCase(),
      uppername => uppername.split('')
    ]
  }
);

// {"result":["L","E","N","N","O","N"]}

Dot notation object conversion

ObjectMapper.mapItem (
  {foo: 'bar'},
  {'target.name.can.be.anything.0': 'foo'}
);

// {"target":{"name":{"can":{"be":{"anything":["bar"]}}}}}

Install

npm install --save @digitregroup/object-mapper

Dependencies

PackageVersionDev
flat^4.1.0
chai^4.2.0
cross-env^5.2.0
laravel-mix^4.0.14
mocha^6.0.2
nyc^13.3.0
vue-template-compiler^2.6.7

Contributing

Contributions welcome; Please submit all pull requests against the develop branch. If your pull request contains JavaScript patches or features, you should include relevant unit tests. Thanks!

Author

DigitRE Group

License

Keywords

FAQs

Package last updated on 16 Oct 2023

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