Skip to content

Instantly share code, notes, and snippets.

@ianjennings
Created June 4, 2020 22:24
Show Gist options
  • Save ianjennings/33d40530f104fa3cb9f2606599d8c671 to your computer and use it in GitHub Desktop.
Save ianjennings/33d40530f104fa3cb9f2606599d8c671 to your computer and use it in GitHub Desktop.
import { IExecuteFunctions } from 'n8n-core';
import {
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
export class Gravatar implements INodeType {
description: INodeTypeDescription = {
displayName: 'Gravatar',
name: 'gravatar',
group: ['transform'],
version: 1,
description: 'Blah blah blah',
defaults: {
name: 'Gravatar',
color: '#772244',
},
inputs: ['main'],
outputs: ['main'],
properties: [
// Node properties which the user gets displayed and
// can change on the node.
{
displayName: 'Email',
name: 'myString',
type: 'string',
default: '',
placeholder: 'Placeholder value',
description: 'The description text',
}
]
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
let item: INodeExecutionData;
let myString: string;
// Itterates over all input items and add the key "myString" with the
// value the parameter "myString" resolves to.
// (This could be a different value for each item in case it contains an expression)
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
myString = this.getNodeParameter('myString', itemIndex, '') as string;
item = items[itemIndex];
// gravatar
myString = myString.replace('a', 'b');
item.json['email'] = myString;
}
return this.prepareOutputData(items);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment