Skip to content

Commit

Permalink
fix: Improve the definition of utils.trimObj() to not modify the sour…
Browse files Browse the repository at this point in the history
…ce object
  • Loading branch information
lucasnetau committed Sep 25, 2023
1 parent 843eca7 commit b807646
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ window.fbEditors = {
}

/**
* Remove null or undefined values
* @param {Object} attrs {attrName: attrValue}
* @return {Object} Object trimmed of null or undefined values
*/
export const trimObj = function (attrs, removeFalse = false) {
* Remove null or undefined values from an object, original object is not modified
* @param {Object} obj {attrName: attrValue}
* @param {boolean} [removeFalse=false] Remove values === false
* @return {Object} Object trimmed of null or undefined values
*/
export const trimObj = function (obj, removeFalse = false) {
if (null == obj || typeof obj !== 'object') return obj
const attrs = (typeof window.structuredClone === 'function') ? window.structuredClone(obj) : Object.assign({}, obj)
/** @type {(null|undefined|''|false)[]} xmlRemove */
const xmlRemove = [null, undefined, '']
if (removeFalse) {
xmlRemove.push(false)
Expand Down

0 comments on commit b807646

Please sign in to comment.