Email Organization Name Suggester (src/onboarding-org-suggestion.ts)

superlog · apps/api/src/onboarding-org-suggestion.ts · typescript · Apache-2.0
automation, email, lang:typescript, tag:onboarding, tag:utility

Suggests a company organization name derived from a user's email domain, filtering out consumer domains. Reuse during user registration and onboarding.

// Source: https://github.com/superloglabs/superlog | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
const CONSUMER_EMAIL_DOMAINS = new Set(["gmail.com", "googlemail.com"]);

export function suggestOrgNameFromEmail(email: string): string | null {
  const [, domain, ...extra] = email.trim().toLowerCase().split("@");
  if (!domain || extra.length > 0 || CONSUMER_EMAIL_DOMAINS.has(domain)) return null;

  const domainLabel = domain.split(".")[0];
  if (!domainLabel) return null;
  return domainLabel.charAt(0).toUpperCase() + domainLabel.slice(1);
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key