Skip to content

unacy / detectMetadataKind

Function: detectMetadataKind()

ts
function detectMetadataKind(meta): "primitive" | "enum" | "class" | "tuple" | "record" | "unknown";

Defined in: packages/core/src/utils/validation.ts:434

Detect the kind of a metadata object by inspecting its type field.

Resolution priority: primitiveclasstuplerecordenum. Returns 'unknown' when the value is not a recognised metadata shape.

Parameters

ParameterTypeDescription
metaunknownMetadata object to categorise

Returns

"primitive" | "enum" | "class" | "tuple" | "record" | "unknown"

The detected kind string

Remarks

Resolution priority order: primitiveclasstuplerecordenumunknown. This ordering is important: a class constructor would otherwise match the object check, and a tuple schema (array) would match the record check, so the dispatcher checks the more specific types first.

Example

typescript
detectMetadataKind({ name: 'Celsius', type: 'number' }); // 'primitive'
detectMetadataKind({ name: 'Point', type: { x: 'number', y: 'number' } }); // 'record'
detectMetadataKind({ name: 'RGB', type: ['number', 'number', 'number'] }); // 'tuple'
detectMetadataKind({ name: 'Direction', type: Direction }); // 'enum' (if Direction is an enum)

Use When

You need to dynamically dispatch on the kind of a metadata object at runtime (e.g., in serialisers or schema generators built on top of unacy).

Released under the MIT License.