determineRegistryItemType
Detect the type of a registry item.
Detect the type of a registry item based on file paths and metadata.
Signature
function determineRegistryItemType(
item: RegistryItem
):
| "component"
| "block"
| "hook"
| "lib"
| "file"
| "style"
| "theme"
| "item"
| "unknown";Parameters
| Parameter | Type | Description |
|---|---|---|
item | object | Registry item object |
Item Properties
| Property | Type | Description |
|---|---|---|
name | string | Item name |
title | string | Item title |
description | string | Item description |
files | array | Array of file objects |
files[].path | string | File path |
Returns
Returns one of the following types:
| Type | Path Patterns | Description |
|---|---|---|
component | /ui/, /components/ | UI components |
block | /blocks/ | Full-page blocks |
hook | /hooks/ | React/Vue hooks |
lib | /lib/, /libs/ | Utility libraries |
file | (metadata only) | Standalone files |
style | /styles/ | CSS/Tailwind styles |
theme | /themes/ | Theme configurations |
item | (fallback) | Generic registry items |
Example
import { determineRegistryItemType } from "@insightcn/sdk";
const item = {
name: "button",
title: "Button",
description: "A clickable button",
files: [{ path: "/ui/button.tsx" }],
};
const type = determineRegistryItemType(item);
console.log(type); // "component"Detection Rules
The SDK uses the following rules to detect types:
- File Path Analysis — Checks if any file path contains known patterns
- Metadata Fallback — If no file paths match, checks item metadata
- Default Type — Returns
"item"if no type can be determined
Examples
// Component detection
determineRegistryItemType({
files: [{ path: "/ui/button.tsx" }],
});
// Returns: "component"
// Hook detection
determineRegistryItemType({
files: [{ path: "/hooks/use-form.ts" }],
});
// Returns: "hook"
// Library detection
determineRegistryItemType({
files: [{ path: "/lib/utils.ts" }],
});
// Returns: "lib"
// Block detection
determineRegistryItemType({
files: [{ path: "/blocks/hero.tsx" }],
});
// Returns: "block"