Insightcn

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

ParameterTypeDescription
itemobjectRegistry item object

Item Properties

PropertyTypeDescription
namestringItem name
titlestringItem title
descriptionstringItem description
filesarrayArray of file objects
files[].pathstringFile path

Returns

Returns one of the following types:

TypePath PatternsDescription
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:

  1. File Path Analysis — Checks if any file path contains known patterns
  2. Metadata Fallback — If no file paths match, checks item metadata
  3. 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"

On this page