UNPKG

n8n-nodes-html-validation

Version:
80 lines 4.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HtmlValidationV1 = void 0; const n8n_workflow_1 = require("n8n-workflow"); const versionDescription_1 = require("./actions/versionDescription"); const html_validate_1 = require("html-validate"); const htmlvalidate = new html_validate_1.HtmlValidate(); class HtmlValidationV1 { constructor(baseDescription) { this.description = { ...baseDescription, ...versionDescription_1.versionDescription }; } async execute() { var _a, _b; const items = this.getInputData(); const returnData = []; const resource = 'validator'; const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { let itemData = {}; switch (resource) { case 'validator': switch (operation) { case 'Validate HTML': { const html = this.getNodeParameter('html', i); if (html === undefined || html === null) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'HTML content is required for validation!', { itemIndex: i, }); } const additionalFields = this.getNodeParameter('additionalFields', i, {}); const rejectEmptyString = (_a = additionalFields.rejectEmptyString) !== null && _a !== void 0 ? _a : false; const requireAtLeastOneTag = (_b = additionalFields.requireAtLeastOneTag) !== null && _b !== void 0 ? _b : false; const customRules = additionalFields.customRules; if (rejectEmptyString && html.trim() === '') { itemData = { ok: false, error: 'HTML content cannot be an empty string or consist only of spaces!', content: html }; } else if (requireAtLeastOneTag && !/<[^>]+>/.test(html)) { itemData = { ok: false, error: 'HTML content must contain at least one tag!', content: html }; } else { const validationReport = customRules ? await new html_validate_1.HtmlValidate(JSON.parse(customRules)).validateString(html) : await htmlvalidate.validateString(html); itemData = { ok: validationReport.valid === true, rejectEmptyString, report: validationReport, content: html }; } break; } default: { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "${resource}"!`); } } break; default: { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resource "${resource}" is not supported!`); } } returnData.push({ json: { itemIndex: i, ...itemData } }); } return [this.helpers.returnJsonArray(returnData)]; } } exports.HtmlValidationV1 = HtmlValidationV1; //# sourceMappingURL=HtmlValidationV1.node.js.map