Skip to content

Commit 4b06df7

Browse files
Akash PorwalAkash Porwal
authored andcommitted
[REFACTOR] - Updated npm package name and other readme info
1 parent c6c9f51 commit 4b06df7

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
JSON-Mapper
1+
JSON-Transform
22
=========
33

4-
A Node package for mapping(transforming) one JSON object into another based on a specified template
4+
A Node package for transforming(mapping) one JSON object to another based on a specified template
55

66
## Installation
77

8-
npm install json-mapper --save
8+
npm install json-transform --save
99

1010
## Usage
1111

12-
var JSONMapper = require('json-mapper');
12+
var JSONTransform = require('json-transform');
1313
var input = {
1414
"id" : 101,
1515
"content" : "My first npm package",
@@ -102,7 +102,7 @@ A Node package for mapping(transforming) one JSON object into another based on a
102102
}
103103
};
104104

105-
var result = JSONMapper.map(input, template);
105+
var result = JSONTransform.transform(input, template);
106106

107107
##### Result
108108
{

index.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,74 @@
22
* Created by codeslayer on 3/13/16.
33
*/
44

5-
var JSONMapper = {
5+
var JSONTransform = {
66

77
/**
8-
* Routes request to mapObject function after sanitation checks in input/mapping
8+
* Routes request to transformObject function after sanitation checks in input/template
99
*
10-
* @param {JSON} input, {JSON} mapping
10+
* @param {JSON} input, {JSON} template
1111
* @return {JSON}
1212
*/
13-
map: function(input, mapping){
14-
if(Utils.isEmpty(input) || Utils.isEmpty(mapping)){
13+
transform: function(input, template){
14+
if(Utils.isEmpty(input) || Utils.isEmpty(template)){
1515
return null
1616
}
1717

18-
return JSONMapper.mapObject(input,mapping);
18+
return JSONTransform.transformObject(input,template);
1919
},
2020

2121
/**
22-
* This function iterates the specified mapping and populates the desired keys from the input
22+
* This function iterates the specified template and populates the desired keys from the input
2323
*
24-
* @param {JSON} input, {JSON} mapping
24+
* @param {JSON} input, {JSON} template
2525
* @return {JSON}
2626
*/
27-
mapObject: function(input, mapping){
28-
var mappedObject = {};
27+
transformObject: function(input, template){
28+
var transformedObject = {};
2929

30-
for(var actualKey in mapping){
30+
for(var actualKey in template){
3131
/*
32-
-> if an object or array needs to be mapped, we take the desired key name and data to be mapped inside an object,
33-
and parse all the keys in data one by one and set the mapped output against the desired key name
34-
-> if a single variable needs to be mapped, we set the desired value against the desired key
32+
-> if an object or array needs to be transformed, we take the desired key name and data to be transformed inside an object,
33+
and parse all the keys in data one by one and set the transformed output against the desired key name
34+
-> if a single variable needs to be transformed, we set the desired value against the desired key
3535
*/
36-
if(Utils.isObject(mapping[actualKey])){
37-
var desiredKeyName = mapping[actualKey]['desiredKey'];
38-
var desiredDataMapping = mapping[actualKey]['desiredData'];
36+
if(Utils.isObject(template[actualKey])){
37+
var desiredKeyName = template[actualKey]['desiredKey'];
38+
var desiredDatatemplate = template[actualKey]['desiredData'];
3939

40-
if(Utils.isObject(desiredDataMapping)){
41-
mappedObject[desiredKeyName] = JSONMapper.mapObject(input[actualKey],desiredDataMapping);
40+
if(Utils.isObject(desiredDatatemplate)){
41+
transformedObject[desiredKeyName] = JSONTransform.mapObject(input[actualKey],desiredDatatemplate);
4242
}
43-
else if(Utils.isArray(desiredDataMapping)){
44-
mappedObject[desiredKeyName] = JSONMapper.mapArray(input[actualKey],desiredDataMapping[0]);
43+
else if(Utils.isArray(desiredDatatemplate)){
44+
transformedObject[desiredKeyName] = JSONTransform.mapArray(input[actualKey],desiredDatatemplate[0]);
4545
}
4646
}
4747
else{
48-
var desiredKeyName = mapping[actualKey];
49-
mappedObject[desiredKeyName] = input[actualKey];
48+
var desiredKeyName = template[actualKey];
49+
transformedObject[desiredKeyName] = input[actualKey];
5050
}
5151
}
5252

53-
return mappedObject;
53+
return transformedObject;
5454
},
5555

5656
/**
57-
* This function iterates an array and maps each object of the array one by one
57+
* This function iterates an array and transforms each object of the array one by one
5858
*
59-
* @param {JSON} input, {JSON} mapping
59+
* @param {JSON} input, {JSON} template
6060
* @return {JSON Array}
6161
*/
62-
mapArray: function(input, mapping){
63-
var mappedArray = [];
62+
transformArray: function(input, template){
63+
var transformedArray = [];
6464
for(var index in input){
6565
var inputObject = input[index];
66-
var mappedObject = JSONMapper.mapObject(inputObject,mapping);
67-
mappedArray.push(mappedObject);
66+
var transformedObject = JSONTransform.mapObject(inputObject,template);
67+
transformedArray.push(transformedObject);
6868
}
6969

70-
return mappedArray;
70+
return transformedArray;
7171
}
7272

7373
};
7474

75-
module.exports = JSONMapper;
75+
module.exports = JSONTransform;

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"name": "json-mapper",
2+
"name": "json-transform",
33
"version": "0.1.0",
4-
"description": "Node package for mapping(transforming) one JSON object into another based on a specified template",
4+
"description": "A Node package for transforming(mapping) one JSON object to another based on a specified template",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/codeslayer1/JSON-Mapper.git"
11+
"url": "git+https://github.com/codeslayer1/JSON-Transform.git"
1212
},
1313
"keywords": [
1414
"json",
@@ -20,7 +20,7 @@
2020
"author": "codeslayer1",
2121
"license": "ISC",
2222
"bugs": {
23-
"url": "https://github.com/codeslayer1/JSON-Mapper/issues"
23+
"url": "https://github.com/codeslayer1/JSON-Transform/issues"
2424
},
25-
"homepage": "https://github.com/codeslayer1/JSON-Mapper#readme"
25+
"homepage": "https://github.com/codeslayer1/JSON-Transform#readme"
2626
}

0 commit comments

Comments
 (0)