UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

57 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = void 0; exports.execute = execute; const utilities_1 = require("../../../../../utils/utilities"); const properties = [ { displayName: 'Max Items', name: 'maxItems', type: 'number', typeOptions: { minValue: 1, }, default: 1, description: 'If there are more items than this number, some are removed', }, { displayName: 'Keep', name: 'keep', type: 'options', options: [ { name: 'First Items', value: 'firstItems', }, { name: 'Last Items', value: 'lastItems', }, ], default: 'firstItems', description: 'When removing items, whether to keep the ones at the start or the ending', }, ]; const displayOptions = { show: { resource: ['itemList'], operation: ['limit'], }, }; exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, properties); async function execute(items) { let returnData = items; const maxItems = this.getNodeParameter('maxItems', 0); const keep = this.getNodeParameter('keep', 0); if (maxItems > items.length) { return returnData; } if (keep === 'firstItems') { returnData = items.slice(0, maxItems); } else { returnData = items.slice(items.length - maxItems, items.length); } return returnData; } //# sourceMappingURL=limit.operation.js.map