GitHub

@@ -83,6 +83,43 @@ export function compare<T>(value?: T, currentValue?: T, comparator?: string | ((

8383

return isEqual(value, currentValue)

8484

}

858586+

export function isEmpty(value: unknown): boolean {

87+

if (value == null) {

88+

return true

89+

}

90+91+

if (typeof value === 'boolean' || typeof value === 'number') {

92+

return false

93+

}

94+95+

if (typeof value === 'string') {

96+

return value.trim().length === 0

97+

}

98+99+

if (Array.isArray(value)) {

100+

return value.length === 0

101+

}

102+103+

if (value instanceof Map || value instanceof Set) {

104+

return value.size === 0

105+

}

106+107+

if (value instanceof Date || value instanceof RegExp || typeof value === 'function') {

108+

return false

109+

}

110+111+

if (typeof value === 'object') {

112+

for (const _ in value as object) {

113+

if (Object.prototype.hasOwnProperty.call(value, _)) {

114+

return false

115+

}

116+

}

117+

return true

118+

}

119+120+

return false

121+

}

122+86123

export function getDisplayValue<T, V>(

87124

items: T[],

88125

value: V | undefined | null,

@@ -93,7 +130,7 @@ export function getDisplayValue<T, V>(

93130

): string | undefined {

94131

const { valueKey, labelKey } = options

9513296-

if (value === null || value === undefined) {

133+

if (isEmpty(value)) {

97134

return undefined

98135

}

99136

Read the original on github.com ↗