tethys-feature-service/node_modules/xml-js/lib/options-helper.js

44 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-10-02 13:04:02 +00:00
var isArray = require('./array-helper').isArray;
module.exports = {
copyOptions: function (options) {
var key, copy = {};
for (key in options) {
if (options.hasOwnProperty(key)) {
copy[key] = options[key];
}
}
return copy;
},
ensureFlagExists: function (item, options) {
if (!(item in options) || typeof options[item] !== 'boolean') {
options[item] = false;
}
},
ensureSpacesExists: function (options) {
if (!('spaces' in options) || (typeof options.spaces !== 'number' && typeof options.spaces !== 'string')) {
options.spaces = 0;
}
},
ensureAlwaysArrayExists: function (options) {
if (!('alwaysArray' in options) || (typeof options.alwaysArray !== 'boolean' && !isArray(options.alwaysArray))) {
options.alwaysArray = false;
}
},
ensureKeyExists: function (key, options) {
if (!(key + 'Key' in options) || typeof options[key + 'Key'] !== 'string') {
options[key + 'Key'] = options.compact ? '_' + key : key;
}
},
checkFnExists: function (key, options) {
return key + 'Fn' in options;
}
};