mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-17 10:04:08 -08:00
28 lines
782 B
TypeScript
28 lines
782 B
TypeScript
|
import {
|
||
|
IDataObject,
|
||
|
INodeExecutionData,
|
||
|
} from 'n8n-workflow';
|
||
|
|
||
|
/**
|
||
|
* Returns of copy of the items which only contains the json data and
|
||
|
* of that only the define properties
|
||
|
*
|
||
|
* @param {INodeExecutionData[]} items The items to copy
|
||
|
* @param {string[]} properties The properties it should include
|
||
|
* @returns
|
||
|
*/
|
||
|
export function copyInputItems(items: INodeExecutionData[], properties: string[]): IDataObject[] {
|
||
|
// Prepare the data to insert and copy it to be returned
|
||
|
let newItem: IDataObject;
|
||
|
return items.map((item) => {
|
||
|
newItem = {};
|
||
|
for (const property of properties) {
|
||
|
if (item.json[property] === undefined) {
|
||
|
newItem[property] = null;
|
||
|
} else {
|
||
|
newItem[property] = JSON.parse(JSON.stringify(item.json[property]));
|
||
|
}
|
||
|
}
|
||
|
return newItem;
|
||
|
});
|
||
|
}
|