Skip to content

Commit

Permalink
Use wild-wild-path for recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent da3a72d commit d05a005
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/config/empty.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import filterObj from 'filter-obj'
import isPlainObj from 'is-plain-obj'

import { mapValues } from '../utils/map.js'
import { exclude } from './normalize/lib/wild_wild_utils/main.js'

// We remove `null` values so that those can be used to unset properties from
// shared configurations.
// We remove `undefined` values so `Object.keys()` does not show them and to
// make printing configuration nicer.
export const removeEmptyValues = function (object) {
const objectA = removeEmptyChildren(object)
return mapValues(objectA, removeEmptyChildren, { deep: true })
}

const removeEmptyChildren = function (value) {
if (isPlainObj(value)) {
return filterObj(value, isNotEmptyPair)
}

if (Array.isArray(value)) {
return value.filter(isNotEmptyValue)
}

return value
}

const isNotEmptyPair = function (key, value) {
return isNotEmptyValue(value)
return exclude(object, '**', isEmptyValue)
}

const isNotEmptyValue = function (value) {
return value !== null && value !== undefined
const isEmptyValue = function (value) {
return value === null || value === undefined
}

0 comments on commit d05a005

Please sign in to comment.