Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 1x 13x 13x 13x 13x 13x 1x 6x 6x 6x 6x 6x 4x 4x 6x 4x 4x 4x 4x 6x 6x 1x 6x 6x 6x 6x 4x 4x 4x 4x 1x 100x | /**
* Parses a comma-separated string into an array of trimmed strings.
*
* @param input - A comma-separated string (e.g., "a,b,c"). Can be undefined.
* @returns An array of trimmed non-empty strings. Returns an empty array if input is empty or undefined.
*/
export const parseCommaSeparated = (input?: string): string[] => {
return (input || '')
.split(',')
.map((s) => s.trim())
.filter(Boolean);
};
/**
* Checks whether the given email is allowed based on a list of allowed domains
* and/or a list of explicitly allowed email addresses.
*
* @param email - The email address to validate. Can be null or undefined.
* @param domains - A comma-separated list of allowed domains (e.g., "@example.com,@test.org"). Optional.
* @param allowedEmails - A comma-separated list of explicitly allowed email addresses (e.g., "user1@example.com,user2@test.org"). Optional.
* @returns True if the email matches any of the allowed domains or is in the allowed email list, otherwise false.
*/
export const checkValidEmail = (
email: string | null | undefined,
domains?: string,
allowedEmails?: string,
): boolean => {
if (!email) return false;
const normalizedEmail = email.toLowerCase();
const domainMatch = parseCommaSeparated(domains).some((d) =>
normalizedEmail.endsWith(d.toLowerCase()),
);
const emailMatch = parseCommaSeparated(allowedEmails).some(
(e) => e.toLowerCase() === normalizedEmail,
);
return domainMatch || emailMatch;
};
/**
* Compare two arrays of strings for equality, ignoring order.
*
* @param preArr - The first array of strings.
* @param nextArr - The second array of strings.
* @returns `true` if both arrays contain the same strings (regardless of order), otherwise `false`.
*/
export const compareStringArrays = (
preArr: string[],
nextArr: string[],
): boolean => {
if (preArr.length !== nextArr.length) return false;
const sortedPreArr = [...preArr].sort();
const sortedNextArr = [...nextArr].sort();
return sortedPreArr.every((value, index) => value === sortedNextArr[index]);
};
export const isTruthy = <T>(value: T | null | undefined): value is T =>
value !== null && value !== undefined;
|