Skip to content

Commit

Permalink
Merge pull request #75 from fastcodejava/master
Browse files Browse the repository at this point in the history
Modified jsonapter.js added console.log for value should not be used as a template.
  • Loading branch information
fastcodejava committed Jun 19, 2017
2 parents 83ba042 + f3eba23 commit 88fb269
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 87 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ console.log(r); // // [{cost: 20, num: 1}, {cost: 30, num: 2}]
This rule is used to get timeStamp as `{occurred: {timeStamp: {serialize: true}}`.
It will produce an output `occurred: "2017-06-12T22:54:39.502Z"`.
The `serialize` option is `true` by default. If it is `false` it will keep it a `Date` object.
The `serialize` option can be a `function` as well which one can use to formar the `Date` object.
If the timeStamp tag is invoked multiple times in the same template the output will be same.

<a name="size" />
Expand Down
4 changes: 4 additions & 0 deletions lib/jsonapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ var prototype = {

var actionKey = _.find(this.actionKeys, templateHasKey(template));

if (actionKey === 'value' && !template.lookup && _.isPlainObject(template[actionKey])) {
console.log("****ALERT****, value should not be used as a template, it will be removed soon.");
}

var result = input !== null && actionKey ? this[actionKey](template, input, parent, params, arrayIndex, arraySize, options) : input;

if (result === null && !util.isNullOrUndefined(template.default)) {
Expand Down
174 changes: 87 additions & 87 deletions test/test_cases/case-pruneValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,32 @@ exports.templateForDefaultValues = {
};

exports.outputForEmptyStringPresence = {
"address": "",
"familyName": "",
"firstName": "TIM",
"groups": [1, 2],
"lastName": "DOE",
"middleName": "JOE"
address: "",
familyName: "",
firstName: "TIM",
groups: [1, 2],
lastName: "DOE",
middleName: "JOE"
};
exports.outputForDefaultValues = {
"address": "",
"age": NaN,
"familyName": "",
"firstName": "TIM",
"friends": [],
"groups": [1, 2],
"lastName": "DOE",
"middleName": "JOE",
"numbers": []
address: "",
age: NaN,
familyName: "",
firstName: "TIM",
friends: [],
groups: [1, 2],
lastName: "DOE",
middleName: "JOE",
numbers: []
};

exports.outputForNaNPresence = {

"age": NaN,
"firstName": "TIM",
"groups": [1, 2],
"lastName": "DOE",
"middleName": "JOE"
age: NaN,
firstName: "TIM",
groups: [1, 2],
lastName: "DOE",
middleName: "JOE"
};

exports.input = {
Expand Down Expand Up @@ -267,7 +267,7 @@ exports.template = {
dataKey: "numbers",
default: "1"
},
"dotValue": {
dotValue: {
dataKey: "h.a1"
}
}
Expand All @@ -287,7 +287,7 @@ exports.template = {
arrayContent: [{
arrayContent: [{
dataKey: "a.i",
value: weatherTemplate
template: weatherTemplate
}],
default: []
}]
Expand All @@ -297,48 +297,48 @@ exports.template = {
};

exports.expectedWithPruneOptions = {
"dest_a1": "i am key c1",
"dest_a6": true,
"dest_a7": false,
"dest_b": {
"dest_b0": "value a.e",
"dest_b1": "I am Default for NaN"
dest_a1: "i am key c1",
dest_a6: true,
dest_a7: false,
dest_b: {
dest_b0: "value a.e",
dest_b1: "I am Default for NaN"
},
"dest_e": "value a.e",
"dest_f": [{
"firstName": "sampleFirstName"
dest_e: "value a.e",
dest_f: [{
firstName: "sampleFirstName"
}, {
"firstName": "sampleFirstName",
"group": [1, 3]
firstName: "sampleFirstName",
group: [1, 3]
}, {
"firstName": "sampleFirstName"
firstName: "sampleFirstName"
}],
"dest_g": {
"firstName": "sampleLastName",
"Numbers": "1"
dest_g: {
firstName: "sampleLastName",
Numbers: "1"
},
"dest_h": {
dest_h: {
"dest.h1.firstName": "sampleFirstName"
},
dest_i: [{
"city": "Dallas",
"temperature": "70F",
"weather": "sunny",
"days": [
city: "Dallas",
temperature: "70F",
weather: "sunny",
days: [
"mon",
"tue",
"wed"
]
}, {
"days": [
days: [
"thr",
"fri",
"sat"
]
}, {
"city": "Irving",
"temperature": "70F",
"weather": "sunny"
city: "Irving",
temperature: "70F",
weather: "sunny"
}]
};

Expand Down Expand Up @@ -375,79 +375,79 @@ exports.expectedWithOutPruneOptions = {
"dest.h1.firstName": "sampleFirstName",
"dest.h2.lastName": ""
},
"dest_i": [{
"city": "Dallas",
"days": [
dest_i: [{
city: "Dallas",
days: [
"mon",
"tue",
"wed"
],
"temperature": "70F",
"weather": "sunny"
temperature: "70F",
weather: "sunny"
}, {
"days": [
days: [
"thr",
"fri",
"sat"
],
"temperature": NaN,
"weather": ""
temperature: NaN,
weather: ""
}, {
"city": "Irving",
"days": [],
"temperature": "70F",
"weather": "sunny"
city: "Irving",
days: [],
temperature: "70F",
weather: "sunny"
}]
};

exports.expectedWithEmptyArrays = {
"dest_a1": "i am key c1",
"dest_a4": [],
"dest_a6": true,
"dest_a7": false,
"dest_b": {
"dest_b0": "value a.e",
"dest_b1": "I am Default for NaN"
dest_a1: "i am key c1",
dest_a4: [],
dest_a6: true,
dest_a7: false,
dest_b: {
dest_b0: "value a.e",
dest_b1: "I am Default for NaN"
},
"dest_e": "value a.e",
"dest_f": [{
"firstName": "sampleFirstName",
"group": []
dest_e: "value a.e",
dest_f: [{
firstName: "sampleFirstName",
group: []
}, {
"firstName": "sampleFirstName",
"group": [1,
firstName: "sampleFirstName",
group: [1,
3
]
}, {
"firstName": "sampleFirstName",
"group": []
firstName: "sampleFirstName",
group: []
}],
"dest_g": {
"firstName": "sampleLastName",
"Numbers": "1"
dest_g: {
firstName: "sampleLastName",
Numbers: "1"
},
"dest_h": {
dest_h: {
"dest.h1.firstName": "sampleFirstName"
},
"dest_i": [{
"city": "Dallas",
"temperature": "70F",
"weather": "sunny",
"days": [
dest_i: [{
city: "Dallas",
temperature: "70F",
weather: "sunny",
days: [
"mon",
"tue",
"wed"
]
}, {
"days": [
days: [
"thr",
"fri",
"sat"
]
}, {
"city": "Irving",
"days": [],
"temperature": "70F",
"weather": "sunny"
city: "Irving",
days: [],
temperature: "70F",
weather: "sunny"
}]
};

0 comments on commit 88fb269

Please sign in to comment.