Data Object Mapper is an npm package designed to simplify the process of mapping properties between objects in JavaScript. It provides a set of functions that allow you to easily map properties from one object to another, whether you need shallow or deep property mapping.
You can install Data Object Mapper via npm or yarn:
# Installation
npm install data-object-mapper
or
yarn add data-object-mapper
To use Data Object Mapper, you can import the functions you need and integrate them into your project. Below are some examples of how to use Data Object Mapper:
import { mapObjects } from 'data-object-mapper';
const sourceObject = {
name: 'John Doe',
age: 30,
};
const targetObject = {
name: '',
country: 'USA',
};
mapObjects(sourceObject, targetObject);
console.log(targetObject);
// Output: { name: 'John Doe', country: 'USA' }
import { deepMapObjects } from 'data-object-mapper';
const sourceObject = {
user: {
name: 'John Doe',
age: 30,
},
};
const targetObject = {
user: {
name: '',
country: 'USA',
},
};
deepMapObjects(sourceObject, targetObject);
console.log(targetObject);
// Output: { user: { name: 'John Doe', country: 'USA' } }
Mapper provides the following functions:
- mapObjects(sourceObject, targetObjects): Shallow property mapping between objects.
- deepMapObjects(sourceObject, targetObjects): Deep property mapping between objects.
Before using Mapper, make sure to import the functions you need and define your source and target objects. Adjust your source and target objects according to your mapping requirements.
You can run tests for Data Object Mapper using a testing framework such as Jest:
npm test
or
yarn test
This package is licensed under the MIT License.
Author: Joe Mansour
Contributions are welcome. Feel free to open issues and pull requests.
For more details and examples, visit the GitHub repository.