0.0.1 • Published 6 years ago

dto-utils v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

DTO-UTILS Inspired from Dot Net Data Transfer Object Concept, Utility contains method which rename keys in existing object using plain JavaScript code.

DTO-UTILS - Javascript utility to rename specific keys from array of object or collection easily

DTO-UTILS currently contains one method mapTo

Installation

In a browser:

Using npm:

$ npm i -g npm
$ npm i --save dto-utils

In Node.js:

// Load dto utils
var DTO = require('dto-utils');

How to use:

var collection=[{"category":"version control",url:"https://www.github.com"},{"category":"search engine",url:"https://www.google.com"}];

//Provide key value pair in which key is old key and value is new key(renamed key)
var newKeys={"category":"type"};

var isAllowKeyOverwrite=false;

// By default isAllowKeyOverwrite is true in utils, you can override by pssing appropriate flag
var newCollection=DTO.mapTo(collection,newKeys,isAllowKeyOverwrite); 

// newCollection have updated value like this [{"type":"version control",url:"https://www.github.com"},{"type":"search engine",url:"https://www.google.com"}]