refactor: standardize runtime guard patterns with lodash-es (#154)
* refactor(ui): replace runtime type guards with lodash-es predicates * refactor(runtime): migrate typeof checks to lodash-es in core modules * refactor(ipc): standardize runtime guards with lodash-es * test(refactor): align runtime guard checks with lodash-es * docs(agents): add lodash-es runtime guard skill summary
This commit is contained in:
33 files changed
+303
-208
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import { isEmpty, isString } from 'lodash-es';
|
||||
|
||||
export type RequestHeaderValue = string | string[] | undefined;
|
||||
|
||||
export type RequestHeaders = Record<string, RequestHeaderValue>;
|
||||
|
||||
export function hasConfiguredApiKey(apiKey: string | undefined): apiKey is string {
|
||||
return typeof apiKey === 'string' && apiKey.trim() !== '';
|
||||
return isString(apiKey) && !isEmpty(apiKey.trim());
|
||||
}
|
||||
|
||||
export function extractApiKeyToken(headers: RequestHeaders): string | null {
|
||||
@@ -29,16 +31,16 @@ export function extractApiKeyToken(headers: RequestHeaders): string | null {
|
||||
}
|
||||
|
||||
function readHeaderValue(headerValue: RequestHeaderValue): string | null {
|
||||
if (typeof headerValue === 'string') {
|
||||
if (isString(headerValue)) {
|
||||
const trimmedValue = headerValue.trim();
|
||||
return trimmedValue !== '' ? trimmedValue : null;
|
||||
return !isEmpty(trimmedValue) ? trimmedValue : null;
|
||||
}
|
||||
|
||||
if (Array.isArray(headerValue)) {
|
||||
for (const value of headerValue) {
|
||||
if (typeof value === 'string') {
|
||||
if (isString(value)) {
|
||||
const trimmedValue = value.trim();
|
||||
if (trimmedValue !== '') {
|
||||
if (!isEmpty(trimmedValue)) {
|
||||
return trimmedValue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user