Files
wehub-resource-sync 3cd11ababe
Check Markdown links / linkChecker (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:38:56 +08:00

52 lines
1.4 KiB
TypeScript

import {
HookEventType,
PluginContext,
PluginHandler,
PluginParameters,
} from '../types';
import { getCurrentContentPart } from '../utils';
export const handler: PluginHandler = async (
context: PluginContext,
parameters: PluginParameters,
eventType: HookEventType
) => {
let error = null;
let verdict = false;
let data: any = null;
try {
const not = parameters.not || false;
const { content, textArray } = getCurrentContentPart(context, eventType);
// Check if content is null, undefined, or empty
const isNull =
content === null ||
content === undefined ||
(typeof content === 'string' && content.trim() === '') ||
(Array.isArray(content) && content.length === 0) ||
textArray.every((text) => !text || text.trim() === '');
// By default, verdict is true if content is NOT null (i.e., content exists)
verdict = not ? isNull : !isNull;
data = {
isNull,
contentType: content === null ? 'null' : typeof content,
textArrayLength: textArray.length,
explanation: isNull
? 'Content is null, undefined, or empty.'
: 'Content exists and is not null.',
verdict: verdict ? 'passed' : 'failed',
};
} catch (e: any) {
error = e;
data = {
explanation: 'An error occurred while checking for null content.',
error: e.message,
};
}
return { error, verdict, data };
};