remove-one-element-arrays
Version:
Removes the one-element arrays from an object.
35 lines (27 loc) • 1.09 kB
JavaScript
;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var iterateObj = require("iterate-object");
/**
* removeOneElementArrays
* Removes the one-element arrays from an object.
*
* @name removeOneElementArrays
* @function
* @param {Object} input The input object.
* @returns {Object} The convert object.
*/
function removeOneElementArrays(input) {
if ((typeof input === "undefined" ? "undefined" : _typeof(input)) !== "object") {
return input;
}
if (Array.isArray(input) && input.length === 1) {
return removeOneElementArrays(input[0]);
}
iterateObj(input, function (val, key) {
if ((typeof val === "undefined" ? "undefined" : _typeof(val)) === "object" && val) {
input[key] = removeOneElementArrays(val);
}
});
return input;
};
module.exports = removeOneElementArrays;