电速宝智配引擎
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122
  1. var helper = require('./options-helper');
  2. var xml2js = require('./xml2js');
  3. function validateOptions (userOptions) {
  4. var options = helper.copyOptions(userOptions);
  5. helper.ensureSpacesExists(options);
  6. return options;
  7. }
  8. module.exports = function(xml, userOptions) {
  9. var options, js, json, parentKey;
  10. options = validateOptions(userOptions);
  11. js = xml2js(xml, options);
  12. parentKey = 'compact' in options && options.compact ? '_parent' : 'parent';
  13. // parentKey = ptions.compact ? '_parent' : 'parent'; // consider this
  14. if ('addParent' in options && options.addParent) {
  15. json = JSON.stringify(js, function (k, v) { return k === parentKey? '_' : v; }, options.spaces);
  16. } else {
  17. json = JSON.stringify(js, null, options.spaces);
  18. }
  19. return json.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
  20. };