-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
4 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |