A type-validation that checks if a value is an empty object.
Value to validate
Type: unknown
Optional callback that would be called with validation rejection reasons.
- When validation succeeds -
rejectionReasonswould not be invoked. - When validation fails -
rejectionReasonswould be invoked at least once and may be invoked multiple times.
A description of the validated type
Type: string
Returns a predicate (no second argument) for the specified validator.
Returns a type-guard predicate (no second argument) for the specified validator.
import { isEmptyObject, typeValidatorType } from '@altostra/type-validations'
console.log(isEmptyObject[typeValidatorType]) // {}
console.log(isEmptyObject({}, console.log)) // true
console.log(isEmptyObject([], console.log)) // true
console.log(isEmptyObject('A', console.log)) /* {
path: [],
reason: "Value <'A'> is not an object",
propertyType: '{}'
}
false */
console.log(isEmptyObject({ prop: undefined }, console.log)) /* {
path: [],
reason: 'Object <{ prop: undefined }> is not empty',
propertyType: '{}'
}
false */
console.log(isEmptyObject([0], console.log)) /* { path: [], reason: 'Object <[ 0 ]> is not empty', propertyType: '{}' }
false */
const incognito: unknown = {}
if (isEmptyObject(incognito)) {
Object.keys(incognito) // []
}