feat(Send Email Node): Overhaul

This commit is contained in:
Michael Kret
2023-01-24 12:32:31 +02:00
committed by GitHub
parent a86c9a628b
commit 832fb87954
8 changed files with 633 additions and 230 deletions

View File

@@ -29,5 +29,6 @@
},
"subcategories": {
"Core Nodes": ["Helpers"]
}
},
"alias": ["SMTP"]
}

View File

@@ -1,234 +1,24 @@
import { IExecuteFunctions } from 'n8n-core';
import { IDataObject, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
import { INodeTypeBaseDescription, IVersionedNodeType, VersionedNodeType } from 'n8n-workflow';
import { createTransport } from 'nodemailer';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { EmailSendV1 } from './v1/EmailSendV1.node';
import { EmailSendV2 } from './v2/EmailSendV2.node';
export class EmailSend implements INodeType {
description: INodeTypeDescription = {
displayName: 'Send Email',
name: 'emailSend',
icon: 'fa:envelope',
group: ['output'],
version: 1,
description: 'Sends an Email',
defaults: {
name: 'Send Email',
color: '#00bb88',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'smtp',
required: true,
},
],
properties: [
// TODO: Add choice for text as text or html (maybe also from name)
{
displayName: 'From Email',
name: 'fromEmail',
type: 'string',
default: '',
required: true,
placeholder: 'admin@example.com',
description: 'Email address of the sender optional with name',
},
{
displayName: 'To Email',
name: 'toEmail',
type: 'string',
default: '',
required: true,
placeholder: 'info@example.com',
description: 'Email address of the recipient',
},
{
displayName: 'CC Email',
name: 'ccEmail',
type: 'string',
default: '',
placeholder: 'cc@example.com',
description: 'Email address of CC recipient',
},
{
displayName: 'BCC Email',
name: 'bccEmail',
type: 'string',
default: '',
placeholder: 'bcc@example.com',
description: 'Email address of BCC recipient',
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
placeholder: 'My subject line',
description: 'Subject line of the email',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'Plain text message of email',
},
{
displayName: 'HTML',
name: 'html',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'HTML text message of email',
},
{
displayName: 'Attachments',
name: 'attachments',
type: 'string',
default: '',
description:
'Name of the binary properties that contain data to add to email as attachment. Multiple ones can be comma-separated.',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Whether to connect even if SSL certificate validation is not possible',
},
{
displayName: 'Reply To',
name: 'replyTo',
type: 'string',
default: '',
placeholder: 'info@example.com',
description: 'The email address to send the reply to',
},
],
},
],
};
export class EmailSend extends VersionedNodeType {
constructor() {
const baseDescription: INodeTypeBaseDescription = {
displayName: 'Send Email',
name: 'emailSend',
icon: 'fa:envelope',
group: ['output'],
defaultVersion: 2,
description: 'Sends an email using SMTP protocol',
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
1: new EmailSendV1(baseDescription),
2: new EmailSendV2(baseDescription),
};
const returnData: INodeExecutionData[] = [];
const length = items.length;
let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
try {
item = items[itemIndex];
const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string;
const toEmail = this.getNodeParameter('toEmail', itemIndex) as string;
const ccEmail = this.getNodeParameter('ccEmail', itemIndex) as string;
const bccEmail = this.getNodeParameter('bccEmail', itemIndex) as string;
const subject = this.getNodeParameter('subject', itemIndex) as string;
const text = this.getNodeParameter('text', itemIndex) as string;
const html = this.getNodeParameter('html', itemIndex) as string;
const attachmentPropertyString = this.getNodeParameter('attachments', itemIndex) as string;
const options = this.getNodeParameter('options', itemIndex, {});
const credentials = await this.getCredentials('smtp');
const connectionOptions: SMTPTransport.Options = {
host: credentials.host as string,
port: credentials.port as number,
secure: credentials.secure as boolean,
};
if (credentials.user || credentials.password) {
// @ts-ignore
connectionOptions.auth = {
user: credentials.user as string,
pass: credentials.password as string,
};
}
if (options.allowUnauthorizedCerts === true) {
connectionOptions.tls = {
rejectUnauthorized: false,
};
}
const transporter = createTransport(connectionOptions);
// setup email data with unicode symbols
const mailOptions = {
from: fromEmail,
to: toEmail,
cc: ccEmail,
bcc: bccEmail,
subject,
text,
html,
replyTo: options.replyTo as string | undefined,
};
if (attachmentPropertyString && item.binary) {
const attachments = [];
const attachmentProperties: string[] = attachmentPropertyString
.split(',')
.map((propertyName) => {
return propertyName.trim();
});
for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) {
continue;
}
attachments.push({
filename: item.binary[propertyName].fileName || 'unknown',
content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName),
});
}
if (attachments.length) {
// @ts-ignore
mailOptions.attachments = attachments;
}
}
// Send the email
const info = await transporter.sendMail(mailOptions);
returnData.push({
json: info as unknown as IDataObject,
pairedItem: {
item: itemIndex,
},
});
} catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
pairedItem: {
item: itemIndex,
},
});
continue;
}
throw error;
}
}
return this.prepareOutputData(returnData);
super(nodeVersions, baseDescription);
}
}

View File

@@ -0,0 +1,255 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import { IExecuteFunctions } from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
} from 'n8n-workflow';
import { createTransport } from 'nodemailer';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
const versionDescription: INodeTypeDescription = {
displayName: 'Send Email',
name: 'emailSend',
icon: 'fa:envelope',
group: ['output'],
version: 1,
description: 'Sends an Email',
defaults: {
name: 'Send Email',
color: '#00bb88',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'smtp',
required: true,
},
],
properties: [
{
displayName: 'Version 1',
name: 'notice',
type: 'notice',
default: '',
},
// TODO: Add choice for text as text or html (maybe also from name)
{
displayName: 'From Email',
name: 'fromEmail',
type: 'string',
default: '',
required: true,
placeholder: 'admin@example.com',
description: 'Email address of the sender optional with name',
},
{
displayName: 'To Email',
name: 'toEmail',
type: 'string',
default: '',
required: true,
placeholder: 'info@example.com',
description: 'Email address of the recipient',
},
{
displayName: 'CC Email',
name: 'ccEmail',
type: 'string',
default: '',
placeholder: 'cc@example.com',
description: 'Email address of CC recipient',
},
{
displayName: 'BCC Email',
name: 'bccEmail',
type: 'string',
default: '',
placeholder: 'bcc@example.com',
description: 'Email address of BCC recipient',
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
placeholder: 'My subject line',
description: 'Subject line of the email',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'Plain text message of email',
},
{
displayName: 'HTML',
name: 'html',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'HTML text message of email',
},
{
displayName: 'Attachments',
name: 'attachments',
type: 'string',
default: '',
description:
'Name of the binary properties that contain data to add to email as attachment. Multiple ones can be comma-separated.',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Whether to connect even if SSL certificate validation is not possible',
},
{
displayName: 'Reply To',
name: 'replyTo',
type: 'string',
default: '',
placeholder: 'info@example.com',
description: 'The email address to send the reply to',
},
],
},
],
};
export class EmailSendV1 implements INodeType {
description: INodeTypeDescription;
constructor(baseDescription: INodeTypeBaseDescription) {
this.description = {
...baseDescription,
...versionDescription,
};
}
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
try {
item = items[itemIndex];
const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string;
const toEmail = this.getNodeParameter('toEmail', itemIndex) as string;
const ccEmail = this.getNodeParameter('ccEmail', itemIndex) as string;
const bccEmail = this.getNodeParameter('bccEmail', itemIndex) as string;
const subject = this.getNodeParameter('subject', itemIndex) as string;
const text = this.getNodeParameter('text', itemIndex) as string;
const html = this.getNodeParameter('html', itemIndex) as string;
const attachmentPropertyString = this.getNodeParameter('attachments', itemIndex) as string;
const options = this.getNodeParameter('options', itemIndex, {});
const credentials = await this.getCredentials('smtp');
const connectionOptions: SMTPTransport.Options = {
host: credentials.host as string,
port: credentials.port as number,
secure: credentials.secure as boolean,
};
if (credentials.user || credentials.password) {
connectionOptions.auth = {
user: credentials.user as string,
pass: credentials.password as string,
};
}
if (options.allowUnauthorizedCerts === true) {
connectionOptions.tls = {
rejectUnauthorized: false,
};
}
const transporter = createTransport(connectionOptions);
// setup email data with unicode symbols
const mailOptions: IDataObject = {
from: fromEmail,
to: toEmail,
cc: ccEmail,
bcc: bccEmail,
subject,
text,
html,
replyTo: options.replyTo as string | undefined,
};
if (attachmentPropertyString && item.binary) {
const attachments = [];
const attachmentProperties: string[] = attachmentPropertyString
.split(',')
.map((propertyName) => {
return propertyName.trim();
});
for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) {
continue;
}
attachments.push({
filename: item.binary[propertyName].fileName || 'unknown',
content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName),
});
}
if (attachments.length) {
mailOptions.attachments = attachments;
}
}
// Send the email
const info = await transporter.sendMail(mailOptions);
returnData.push({
json: info as unknown as IDataObject,
pairedItem: {
item: itemIndex,
},
});
} catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
pairedItem: {
item: itemIndex,
},
});
continue;
}
throw error;
}
}
return this.prepareOutputData(returnData);
}
}

View File

@@ -0,0 +1,81 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import { IExecuteFunctions } from 'n8n-core';
import {
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
} from 'n8n-workflow';
import * as send from './send.operation';
// eslint-disable-next-line n8n-nodes-base/node-class-description-missing-subtitle
const versionDescription: INodeTypeDescription = {
displayName: 'Send Email',
name: 'emailSend',
icon: 'fa:envelope',
group: ['output'],
version: 2,
description: 'Sends an email using SMTP protocol',
defaults: {
name: 'Send Email',
color: '#00bb88',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'smtp',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'hidden',
noDataExpression: true,
default: 'email',
options: [
{
name: 'Email',
value: 'email',
},
],
},
{
displayName: 'Operation',
name: 'operation',
type: 'hidden',
noDataExpression: true,
default: 'send',
options: [
{
name: 'Send',
value: 'send',
},
],
},
...send.description,
],
};
export class EmailSendV2 implements INodeType {
description: INodeTypeDescription;
constructor(baseDescription: INodeTypeBaseDescription) {
this.description = {
...baseDescription,
...versionDescription,
};
}
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
let returnData: INodeExecutionData[][] = [];
returnData = await send.execute.call(this);
return returnData;
}
}

View File

@@ -0,0 +1,260 @@
import { IDataObject, IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { createTransport } from 'nodemailer';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { updateDisplayOptions } from '../../../utils/utilities';
const properties: INodeProperties[] = [
// TODO: Add choice for text as text or html (maybe also from name)
{
displayName: 'From Email',
name: 'fromEmail',
type: 'string',
default: '',
required: true,
placeholder: 'admin@example.com',
description:
'Email address of the sender. You can also specify a name: Nathan Doe &lt;nate@n8n.io&gt;.',
},
{
displayName: 'To Email',
name: 'toEmail',
type: 'string',
default: '',
required: true,
placeholder: 'info@example.com',
description:
'Email address of the recipient. You can also specify a name: Nathan Doe &lt;nate@n8n.io&gt;.',
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
default: '',
placeholder: 'My subject line',
description: 'Subject line of the email',
},
{
displayName: 'Email Format',
name: 'emailFormat',
type: 'options',
options: [
{
name: 'Text',
value: 'text',
},
{
name: 'HTML',
value: 'html',
},
],
default: 'text',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'Plain text message of email',
displayOptions: {
show: {
emailFormat: ['text'],
},
},
},
{
displayName: 'HTML',
name: 'html',
type: 'string',
typeOptions: {
rows: 5,
},
default: '',
description: 'HTML text message of email',
displayOptions: {
show: {
emailFormat: ['html'],
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Attachments',
name: 'attachments',
type: 'string',
default: '',
description:
'Name of the binary properties that contain data to add to email as attachment. Multiple ones can be comma-separated.',
},
{
displayName: 'CC Email',
name: 'ccEmail',
type: 'string',
default: '',
placeholder: 'cc@example.com',
description: 'Email address of CC recipient',
},
{
displayName: 'BCC Email',
name: 'bccEmail',
type: 'string',
default: '',
placeholder: 'bcc@example.com',
description: 'Email address of BCC recipient',
},
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Whether to connect even if SSL certificate validation is not possible',
},
{
displayName: 'Reply To',
name: 'replyTo',
type: 'string',
default: '',
placeholder: 'info@example.com',
description: 'The email address to send the reply to',
},
],
},
];
const displayOptions = {
show: {
resource: ['email'],
operation: ['send'],
},
};
export const description = updateDisplayOptions(displayOptions, properties);
type EmailSendOptions = {
allowUnauthorizedCerts?: boolean;
attachments?: string;
ccEmail?: string;
bccEmail?: string;
replyTo?: string;
};
function configureTransport(credentials: IDataObject, options: EmailSendOptions) {
const connectionOptions: SMTPTransport.Options = {
host: credentials.host as string,
port: credentials.port as number,
secure: credentials.secure as boolean,
};
if (credentials.user || credentials.password) {
connectionOptions.auth = {
user: credentials.user as string,
pass: credentials.password as string,
};
}
if (options.allowUnauthorizedCerts === true) {
connectionOptions.tls = {
rejectUnauthorized: false,
};
}
return createTransport(connectionOptions);
}
export async function execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
item = items[itemIndex];
const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string;
const toEmail = this.getNodeParameter('toEmail', itemIndex) as string;
const subject = this.getNodeParameter('subject', itemIndex) as string;
const emailFormat = this.getNodeParameter('emailFormat', itemIndex) as string;
const options = this.getNodeParameter('options', itemIndex, {}) as EmailSendOptions;
const credentials = await this.getCredentials('smtp');
const transporter = configureTransport(credentials, options);
const mailOptions: IDataObject = {
from: fromEmail,
to: toEmail,
cc: options.ccEmail,
bcc: options.bccEmail,
subject,
replyTo: options.replyTo,
};
if (emailFormat === 'text') {
mailOptions.text = this.getNodeParameter('text', itemIndex, '');
}
if (emailFormat === 'html') {
mailOptions.html = this.getNodeParameter('html', itemIndex, '');
}
if (options.attachments && item.binary) {
const attachments = [];
const attachmentProperties: string[] = options.attachments
.split(',')
.map((propertyName) => {
return propertyName.trim();
});
for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) {
continue;
}
attachments.push({
filename: item.binary[propertyName].fileName || 'unknown',
content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName),
});
}
if (attachments.length) {
mailOptions.attachments = attachments;
}
}
const info = await transporter.sendMail(mailOptions);
returnData.push({
json: info as unknown as IDataObject,
pairedItem: {
item: itemIndex,
},
});
} catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
pairedItem: {
item: itemIndex,
},
});
continue;
}
throw error;
}
}
return this.prepareOutputData(returnData);
}

View File

@@ -12,7 +12,7 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import { chunk, flatten } from '../../utils/utilities';
import { chunk, flatten } from '../../../utils/utilities';
import mssql from 'mssql';

View File

@@ -1,173 +0,0 @@
export const allCurrencies = [
{ name: 'Euro', value: 'eur' },
{ name: 'United States Dollar', value: 'usd' },
{ name: 'British Pound Sterling', value: 'gbp' },
{ name: 'Swiss Franc', value: 'chf' },
{ name: 'Renminbi', value: 'cny' },
{ name: '--------', value: '' },
{ name: 'United Arab Emirates Dirham', value: 'aed' },
{ name: 'Afghan Afghani', value: 'afn' },
{ name: 'Albanian Lek', value: 'all' },
{ name: 'Armenian Dram', value: 'amd' },
{ name: 'Netherlands Antillean Guilder', value: 'ang' },
{ name: 'Angolan Kwanza', value: 'aoa' },
{ name: 'Argentine Peso', value: 'ars' },
{ name: 'Australian Dollar', value: 'aud' },
{ name: 'Aruban Florin', value: 'awg' },
{ name: 'Azerbaijani Manat', value: 'azn' },
{ name: 'Bosnia-Herzegovina Convertible Mark', value: 'bam' },
{ name: 'Barbadian Dollar', value: 'bbd' },
{ name: 'Bangladeshi Taka', value: 'bdt' },
{ name: 'Bulgarian Lev', value: 'bgn' },
{ name: 'Bahraini Dinar', value: 'bhd' },
{ name: 'Burundian Franc', value: 'bif' },
{ name: 'Bermudan Dollar', value: 'bmd' },
{ name: 'Brunei Dollar', value: 'bnd' },
{ name: 'Bolivian Boliviano', value: 'bob' },
{ name: 'Brazilian Real', value: 'brl' },
{ name: 'Bahamian Dollar', value: 'bsd' },
{ name: 'Bitcoin', value: 'btc' },
{ name: 'Bhutanese Ngultrum', value: 'btn' },
{ name: 'Botswanan Pula', value: 'bwp' },
{ name: 'Belarusian Ruble', value: 'byn' },
{ name: 'Belize Dollar', value: 'bzd' },
{ name: 'Canadian Dollar', value: 'cad' },
{ name: 'Congolese Franc', value: 'cdf' },
{ name: 'Chilean Unit of Account (UF)', value: 'clf' },
{ name: 'Chilean Peso', value: 'clp' },
{ name: 'Chinese Yuan (Offshore)', value: 'cnh' },
{ name: 'Colombian Peso', value: 'cop' },
{ name: 'Costa Rican Colón', value: 'crc' },
{ name: 'Cuban Convertible Peso', value: 'cuc' },
{ name: 'Cuban Peso', value: 'cup' },
{ name: 'Cape Verdean Escudo', value: 'cve' },
{ name: 'Czech Republic Koruna', value: 'czk' },
{ name: 'Djiboutian Franc', value: 'djf' },
{ name: 'Danish Krone', value: 'dkk' },
{ name: 'Dominican Peso', value: 'dop' },
{ name: 'Algerian Dinar', value: 'dzd' },
{ name: 'Egyptian Pound', value: 'egp' },
{ name: 'Eritrean Nakfa', value: 'ern' },
{ name: 'Ethiopian Birr', value: 'etb' },
{ name: 'Fijian Dollar', value: 'fjd' },
{ name: 'Falkland Islands Pound', value: 'fkp' },
{ name: 'Georgian Lari', value: 'gel' },
{ name: 'Guernsey Pound', value: 'ggp' },
{ name: 'Ghanaian Cedi', value: 'ghs' },
{ name: 'Gibraltar Pound', value: 'gip' },
{ name: 'Gambian Dalasi', value: 'gmd' },
{ name: 'Guinean Franc', value: 'gnf' },
{ name: 'Guatemalan Quetzal', value: 'gtq' },
{ name: 'Guyanaese Dollar', value: 'gyd' },
{ name: 'Hong Kong Dollar', value: 'hkd' },
{ name: 'Honduran Lempira', value: 'hnl' },
{ name: 'Croatian Kuna', value: 'hrk' },
{ name: 'Haitian Gourde', value: 'htg' },
{ name: 'Hungarian Forint', value: 'huf' },
{ name: 'Indonesian Rupiah', value: 'idr' },
{ name: 'Israeli New Sheqel', value: 'ils' },
{ name: 'Manx Pound', value: 'imp' },
{ name: 'Indian Rupee', value: 'inr' },
{ name: 'Iraqi Dinar', value: 'iqd' },
{ name: 'Iranian Rial', value: 'irr' },
{ name: 'Icelandic Króna', value: 'isk' },
{ name: 'Jersey Pound', value: 'jep' },
{ name: 'Jamaican Dollar', value: 'jmd' },
{ name: 'Jordanian Dinar', value: 'jod' },
{ name: 'Japanese Yen', value: 'jpy' },
{ name: 'Kenyan Shilling', value: 'kes' },
{ name: 'Kyrgystani Som', value: 'kgs' },
{ name: 'Cambodian Riel', value: 'khr' },
{ name: 'Comorian Franc', value: 'kmf' },
{ name: 'North Korean Won', value: 'kpw' },
{ name: 'South Korean Won', value: 'krw' },
{ name: 'Kuwaiti Dinar', value: 'kwd' },
{ name: 'Cayman Islands Dollar', value: 'kyd' },
{ name: 'Kazakhstani Tenge', value: 'kzt' },
{ name: 'Laotian Kip', value: 'lak' },
{ name: 'Lebanese Pound', value: 'lbp' },
{ name: 'Sri Lankan Rupee', value: 'lkr' },
{ name: 'Liberian Dollar', value: 'lrd' },
{ name: 'Lesotho Loti', value: 'lsl' },
{ name: 'Libyan Dinar', value: 'lyd' },
{ name: 'Moroccan Dirham', value: 'mad' },
{ name: 'Moldovan Leu', value: 'mdl' },
{ name: 'Malagasy Ariary', value: 'mga' },
{ name: 'Macedonian Denar', value: 'mkd' },
{ name: 'Myanma Kyat', value: 'mmk' },
{ name: 'Mongolian Tugrik', value: 'mnt' },
{ name: 'Macanese Pataca', value: 'mop' },
{ name: 'Mauritanian Ouguiya (Pre-2018)', value: 'mro' },
{ name: 'Mauritanian Ouguiya', value: 'mru' },
{ name: 'Mauritian Rupee', value: 'mur' },
{ name: 'Maldivian Rufiyaa', value: 'mvr' },
{ name: 'Malawian Kwacha', value: 'mwk' },
{ name: 'Mexican Peso', value: 'mxn' },
{ name: 'Malaysian Ringgit', value: 'myr' },
{ name: 'Mozambican Metical', value: 'mzn' },
{ name: 'Namibian Dollar', value: 'nad' },
{ name: 'Nigerian Naira', value: 'ngn' },
{ name: 'Nicaraguan Córdoba', value: 'nio' },
{ name: 'Norwegian Krone', value: 'nok' },
{ name: 'Nepalese Rupee', value: 'npr' },
{ name: 'New Zealand Dollar', value: 'nzd' },
{ name: 'Omani Rial', value: 'omr' },
{ name: 'Panamanian Balboa', value: 'pab' },
{ name: 'Peruvian Nuevo Sol', value: 'pen' },
{ name: 'Papua New Guinean Kina', value: 'pgk' },
{ name: 'Philippine Peso', value: 'php' },
{ name: 'Pakistani Rupee', value: 'pkr' },
{ name: 'Polish Zloty', value: 'pln' },
{ name: 'Paraguayan Guarani', value: 'pyg' },
{ name: 'Qatari Rial', value: 'qar' },
{ name: 'Romanian Leu', value: 'ron' },
{ name: 'Serbian Dinar', value: 'rsd' },
{ name: 'Russian Ruble', value: 'rub' },
{ name: 'Rwandan Franc', value: 'rwf' },
{ name: 'Saudi Riyal', value: 'sar' },
{ name: 'Solomon Islands Dollar', value: 'sbd' },
{ name: 'Seychellois Rupee', value: 'scr' },
{ name: 'Sudanese Pound', value: 'sdg' },
{ name: 'Swedish Krona', value: 'sek' },
{ name: 'Singapore Dollar', value: 'sgd' },
{ name: 'Saint Helena Pound', value: 'shp' },
{ name: 'Sierra Leonean Leone', value: 'sll' },
{ name: 'Somali Shilling', value: 'sos' },
{ name: 'Surinamese Dollar', value: 'srd' },
{ name: 'South Sudanese Pound', value: 'ssp' },
{ name: 'São Tomé and Príncipe Dobra (Pre-2018)', value: 'std' },
{ name: 'São Tomé and Príncipe Dobra', value: 'stn' },
{ name: 'Salvadoran Colón', value: 'svc' },
{ name: 'Syrian Pound', value: 'syp' },
{ name: 'Swazi Lilangeni', value: 'szl' },
{ name: 'Thai Baht', value: 'thb' },
{ name: 'Tajikistani Somoni', value: 'tjs' },
{ name: 'Turkmenistani Manat', value: 'tmt' },
{ name: 'Tunisian Dinar', value: 'tnd' },
{ name: "Tongan Pa'anga", value: 'top' },
{ name: 'Turkish Lira', value: 'try' },
{ name: 'Trinidad and Tobago Dollar', value: 'ttd' },
{ name: 'New Taiwan Dollar', value: 'twd' },
{ name: 'Tanzanian Shilling', value: 'tzs' },
{ name: 'Ukrainian Hryvnia', value: 'uah' },
{ name: 'Ugandan Shilling', value: 'ugx' },
{ name: 'Uruguayan Peso', value: 'uyu' },
{ name: 'Uzbekistan Som', value: 'uzs' },
{ name: 'Venezuelan Bolívar Fuerte', value: 'vef' },
{ name: 'Vietnamese Dong', value: 'vnd' },
{ name: 'Vanuatu Vatu', value: 'vuv' },
{ name: 'Samoan Tala', value: 'wst' },
{ name: 'CFA Franc BEAC', value: 'xaf' },
{ name: 'Silver Ounce', value: 'xag' },
{ name: 'Gold Ounce', value: 'xau' },
{ name: 'East Caribbean Dollar', value: 'xcd' },
{ name: 'Special Drawing Rights', value: 'xdr' },
{ name: 'CFA Franc BCEAO', value: 'xof' },
{ name: 'Palladium Ounce', value: 'xpd' },
{ name: 'CFP Franc', value: 'xpf' },
{ name: 'Platinum Ounce', value: 'xpt' },
{ name: 'Yemeni Rial', value: 'yer' },
{ name: 'South African Rand', value: 'zar' },
{ name: 'Zambian Kwacha', value: 'zmw' },
{ name: 'Zimbabwean Dollar', value: 'zwl' },
];

View File

@@ -1,57 +0,0 @@
/**
* Creates an array of elements split into groups the length of `size`.
* If `array` can't be split evenly, the final chunk will be the remaining
* elements.
*
* @param {Array} array The array to process.
* @param {number} [size=1] The length of each chunk
* @example
*
* chunk(['a', 'b', 'c', 'd'], 2)
* // => [['a', 'b'], ['c', 'd']]
*
* chunk(['a', 'b', 'c', 'd'], 3)
* // => [['a', 'b', 'c'], ['d']]
*/
export function chunk(array: any[], size = 1) {
const length = array == null ? 0 : array.length;
if (!length || size < 1) {
return [];
}
let index = 0;
let resIndex = 0;
const result = new Array(Math.ceil(length / size));
while (index < length) {
result[resIndex++] = array.slice(index, (index += size));
}
return result;
}
/**
* Takes a multidimensional array and converts it to a one-dimensional array.
*
* @param {Array} nestedArray The array to be flattened.
* @example
*
* flatten([['a', 'b'], ['c', 'd']])
* // => ['a', 'b', 'c', 'd']
*
*/
export function flatten(nestedArray: any[][]) {
const result = [];
(function loop(array: any[]) {
for (let i = 0; i < array.length; i++) {
if (Array.isArray(array[i])) {
loop(array[i]);
} else {
result.push(array[i]);
}
}
})(nestedArray);
return result;
}