mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
Move getInputString, getInputStringAny, and truncate functions from individual ToolCard components into a dedicated toolInputUtils module to eliminate duplication across PermissionFooter, ToolCard, and knownTools components.
21 lines
616 B
TypeScript
21 lines
616 B
TypeScript
import { isObject } from '@hapi/protocol'
|
|
|
|
export function getInputString(input: unknown, key: string): string | null {
|
|
if (!isObject(input)) return null
|
|
const value = input[key]
|
|
return typeof value === 'string' ? value : null
|
|
}
|
|
|
|
export function getInputStringAny(input: unknown, keys: string[]): string | null {
|
|
for (const key of keys) {
|
|
const value = getInputString(input, key)
|
|
if (value) return value
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function truncate(text: string, maxLen: number): string {
|
|
if (text.length <= maxLen) return text
|
|
return text.slice(0, maxLen - 3) + '...'
|
|
}
|