**feat(utils): add type utility functions and examples for runtime type management**

- Introduced `getNounTypes`, `getVerbTypes`, `getNounTypeMap`, and `getVerbTypeMap` utilities for managing noun and verb types at runtime.
- Added comprehensive unit tests (`type-utils.test.ts`) to ensure correctness of type utility functions.
- Created new example files (`type-utils-example.js`, `type-utils-example.ts`) to demonstrate the use of type utilities in JavaScript and TypeScript environments.
- Updated `README.md` with detailed documentation and usage examples for the new type utilities.
- Enhanced `index.ts` to export the new utility functions, making them accessible throughout the library.

**Purpose**: Facilitate easy access, validation, and manipulation of noun and verb types in client applications, providing better runtime type management.
This commit is contained in:
David Snelling 2025-07-31 14:24:16 -07:00
parent 927dc94edb
commit 17bd7ab42d
6 changed files with 392 additions and 1 deletions

44
src/utils/typeUtils.ts Normal file
View file

@ -0,0 +1,44 @@
/**
* Type Utilities
*
* This module provides utility functions for working with the Brainy type system,
* particularly for accessing lists of noun and verb types.
*/
import { NounType, VerbType } from '../types/graphTypes.js'
/**
* Returns an array of all available noun types
*
* @returns {string[]} Array of all noun type values
*/
export function getNounTypes(): string[] {
return Object.values(NounType)
}
/**
* Returns an array of all available verb types
*
* @returns {string[]} Array of all verb type values
*/
export function getVerbTypes(): string[] {
return Object.values(VerbType)
}
/**
* Returns a map of noun type keys to their string values
*
* @returns {Record<string, string>} Map of noun type keys to values
*/
export function getNounTypeMap(): Record<string, string> {
return { ...NounType }
}
/**
* Returns a map of verb type keys to their string values
*
* @returns {Record<string, string>} Map of verb type keys to values
*/
export function getVerbTypeMap(): Record<string, string> {
return { ...VerbType }
}