On Sat Feb 15 01:56 PM, Dick Van den Brink wrote: > I like the idea of json config files but how to handle cases where a element > can > occur multiple times? With only one element, it would generate an object, but > with multiple elements it would change into an array. This might make the code > which reads the config a bit more difficult/error prone because it needs to > check > the type everytime. > What do you guys think? Or is this a non-issue? Btw, I took a part of a > plugin.xml > as an example. > Xml: > <engines> > <engine name="cordova-android" version=">=3.2.0" /> > <engine name="cordova-ios" version=">=3.0.0" /> </engines> Jason (array > because engine element is found multiple times):
Good point, It's more an issue with xml2js: https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/src/xml2js.coffee#L210 Could add an option for type conversion: https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/src/xml2js.coffee#L160 if (@options.jsType['array'][key]) obj[key] = [newValue] Not perfect since all 'engine' tags would be an array but should be good enough for Cordova. Or do the conversions in the 'cleanup', if( typeof json['engines']['engine'] != 'array') json['engines']['engine'] = [json['engines']['engine']]; https://github.com/jbondc/cordova-labs/blob/master/cordova-lib/config.ts#L52 Looks fixable either way, J