Type Detection
Automatically detect component types from file paths.
Insightcn automatically detects the type of registry items based on file paths and metadata. This helps you categorize and analyze your registry components.
Supported 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 |
Usage
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"