mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
24ce141815
* refactor: Clear unused ESLint directives from nodes-base (no-changelog) * removed unused disable directives --------- Co-authored-by: Marcus <marcus@n8n.io>
27 lines
903 B
TypeScript
27 lines
903 B
TypeScript
import type { IDataObject } from 'n8n-workflow';
|
|
import type { IValueData, Cheerio } from './types';
|
|
|
|
// The extraction functions
|
|
const extractFunctions: {
|
|
[key: string]: ($: Cheerio, valueData: IValueData) => string | undefined;
|
|
} = {
|
|
attribute: ($: Cheerio, valueData: IValueData): string | undefined =>
|
|
$.attr(valueData.attribute!),
|
|
|
|
html: ($: Cheerio, _valueData: IValueData): string | undefined => $.html() || undefined,
|
|
text: ($: Cheerio, _valueData: IValueData): string | undefined => $.text(),
|
|
value: ($: Cheerio, _valueData: IValueData): string | undefined => $.val(),
|
|
};
|
|
|
|
/**
|
|
* Simple helper function which applies options
|
|
*/
|
|
export function getValue($: Cheerio, valueData: IValueData, options: IDataObject) {
|
|
const value = extractFunctions[valueData.returnValue]($, valueData);
|
|
if (options.trimValues === false || value === undefined) {
|
|
return value;
|
|
}
|
|
|
|
return value.trim();
|
|
}
|