Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.59 KB

File metadata and controls

64 lines (45 loc) · 1.59 KB

isEmptyObject

A type-validation that checks if a value is an empty object.

Parameters

value

Value to validate

Type: unknown

rejectionReasons

Optional callback that would be called with validation rejection reasons.

  • When validation succeeds - rejectionReasons would not be invoked.
  • When validation fails - rejectionReasons would be invoked at least once and may be invoked multiple times.

Properties

Symbol: [typeValidatorType]

A description of the validated type

Type: string

Methods

asPredicate(): (value: unknown) => boolean

Returns a predicate (no second argument) for the specified validator.

asPredicate(): (value: unknown) => value is Record<never, unknown>

Returns a type-guard predicate (no second argument) for the specified validator.

Example

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) // []
}