domain-without-suffix.ts 459 B

1234567891011121314
  1. /**
  2. * Return the part of domain without suffix.
  3. *
  4. * Example: for domain 'foo.com', the result would be 'foo'.
  5. */
  6. export default function getDomainWithoutSuffix(
  7. domain: string,
  8. suffix: string,
  9. ): string {
  10. // Note: here `domain` and `suffix` cannot have the same length because in
  11. // this case we set `domain` to `null` instead. It is thus safe to assume
  12. // that `suffix` is shorter than `domain`.
  13. return domain.slice(0, -suffix.length - 1);
  14. }