Skip to content

Commit

Permalink
Merge pull request #1425 from lucasnetau/trimObject-fix
Browse files Browse the repository at this point in the history
Improve the definition of utils.trimObj() to not modify the source object
  • Loading branch information
kevinchappell authored Oct 5, 2023
2 parents 57bf6e6 + b807646 commit 0ec49b9
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 @@ -14,11 +14,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 0ec49b9

Please sign in to comment.