Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

60 lines
1.5 KiB
TypeScript

import { convert } from 'html-to-text';
import type { IDataObject } from 'n8n-workflow';
import type { IValueData, Cheerio } from './types';
// The extraction functions
const extractFunctions: {
[key: string]: ($: Cheerio, valueData: IValueData, nodeVersion: number) => string | undefined;
} = {
attribute: ($: Cheerio, valueData: IValueData): string | undefined =>
$.attr(valueData.attribute!),
html: ($: Cheerio, _valueData: IValueData): string | undefined => $.html() || undefined,
text: ($: Cheerio, _valueData: IValueData, nodeVersion: number): string | undefined => {
if (nodeVersion <= 1.1) return $.text() || undefined;
const html = $.html() || '';
let options;
if (_valueData.skipSelectors) {
options = {
selectors: _valueData.skipSelectors.split(',').map((s) => ({
selector: s.trim(),
format: 'skip',
})),
};
}
return convert(html, options);
},
value: ($: Cheerio, _valueData: IValueData): string | undefined => $.val(),
};
/**
* Simple helper function which applies options
*/
export function getValue(
$: Cheerio,
valueData: IValueData,
options: IDataObject,
nodeVersion: number,
) {
let value = extractFunctions[valueData.returnValue]($, valueData, nodeVersion);
if (value === undefined) {
return value;
}
if (options.trimValues) {
value = value.trim();
}
if (options.cleanUpText) {
value = value
.replace(/^\s+|\s+$/g, '')
.replace(/(\r\n|\n|\r)/gm, '')
.replace(/\s+/g, ' ');
}
return value;
}