awesome-json2json
Advanced tools
Comparing version 0.4.3 to 0.5.0
@@ -99,2 +99,8 @@ "use strict"; | ||
currentKey = currentKey.replace(/\[\]$/, ''); | ||
if (/\?$/.test(currentKey)) { | ||
currentKey = currentKey.replace(/\?$/, ''); | ||
if (result[currentKey] === undefined) { | ||
return []; | ||
} | ||
} | ||
result = currentKey === '' ? result : result[currentKey]; | ||
@@ -101,0 +107,0 @@ return result.map(function (jsonItem) { |
{ | ||
"name": "awesome-json2json", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"description": "An awesome json to json mapper", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -146,2 +146,8 @@ interface IContext { | ||
currentKey = currentKey.replace(/\[\]$/, ''); | ||
if (/\?$/.test(currentKey)) { | ||
currentKey = currentKey.replace(/\?$/, ''); | ||
if (result[currentKey] === undefined) { | ||
return []; | ||
} | ||
} | ||
result = currentKey === '' ? result : result[currentKey]; | ||
@@ -148,0 +154,0 @@ return result.map((jsonItem) => { |
@@ -515,2 +515,28 @@ const assert = require('assert'); | ||
}); | ||
it('should support optional array', () => { | ||
assert.deepEqual(json2json(ARRAY_FOO_BAR, { | ||
new_foo: { | ||
$path: 'not_exist_array?[]', | ||
new_bar: 'bar' | ||
} | ||
}), { | ||
new_foo: [] | ||
}); | ||
}); | ||
// it('should have $index context in $formatting argument', () => { | ||
// assert.deepEqual(json2json(ARRAY_FOO_BAR, { | ||
// new_foo: { | ||
// $path: 'foo[].bar', | ||
// new_bar: (barValue, { $index, $root }) => { | ||
// return barValue + '_formatted_' + $root.foo[$index].bar; | ||
// } | ||
// } | ||
// }), { | ||
// new_foo: [ | ||
// { new_bar: '1_formatted_1' }, | ||
// { new_bar: '2_formatted_2' }, | ||
// { new_bar: '3_formatted_3' } | ||
// ] | ||
// }); | ||
// }); | ||
}); | ||
@@ -517,0 +543,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55967
1142