mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
34 lines
894 B
TypeScript
34 lines
894 B
TypeScript
// Splits a project name into first name, last name, and email when it is in the format "First Last <email@domain.com>"
|
|
export const splitName = (
|
|
projectName: string,
|
|
): {
|
|
firstName: string;
|
|
lastName?: string;
|
|
email?: string;
|
|
} => {
|
|
const regex = /^(.+)?\s?<([^>]+)>$/;
|
|
const match = projectName.match(regex);
|
|
|
|
if (match) {
|
|
const [_, fullName, email] = match;
|
|
const nameParts = fullName?.trim().split(/\s+/);
|
|
const lastName = nameParts?.pop();
|
|
const firstName = nameParts?.join(' ');
|
|
return { firstName, lastName, email };
|
|
} else {
|
|
const nameParts = projectName.split(/\s+/) ?? [];
|
|
if (nameParts.length < 2) {
|
|
return { firstName: projectName };
|
|
} else {
|
|
const lastName = nameParts.pop();
|
|
const firstName = nameParts.join(' ');
|
|
return { firstName, lastName };
|
|
}
|
|
}
|
|
};
|
|
|
|
export const enum ResourceType {
|
|
Credential = 'credential',
|
|
Workflow = 'workflow',
|
|
}
|