Files
hapi/shared/src/utils.ts
T
weishu 9922588c6f refactor: consolidate utility functions into shared package
Move duplicate isObject, asString, asNumber, and safeStringify functions from multiple modules into a centralized shared/src/utils.ts module and update imports across cli, server, and web packages. This eliminates code duplication and improves maintainability.
2026-01-23 16:04:37 +08:00

22 lines
688 B
TypeScript

export function isObject(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === 'object'
}
export function asString(value: unknown): string | null {
return typeof value === 'string' ? value : null
}
export function asNumber(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) ? value : null
}
export function safeStringify(value: unknown): string {
if (typeof value === 'string') return value
try {
const stringified = JSON.stringify(value, null, 2)
return typeof stringified === 'string' ? stringified : String(value)
} catch {
return String(value)
}
}