UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

38 lines 1.92 kB
/** * https://github.com/mikezimm/drilldown7/issues/501 * Parses a full name string using a custom delimiter and returns either the first or last part. * * - If the delimiter is found, it splits and returns based on order (e.g., "Last, First"). * - If the delimiter is not found, it splits by whitespace and uses fallback logic: * - If the selected word is 3 characters or less, it attempts to return 2 words * to avoid edge cases like "Mr.", "Sr.", "I", "II", etc. * * @param name - The full name string (e.g., "LastName, FirstName" or "John Smith"). * @param delimiter - The delimiter to split on (e.g., ",", "|", "/"). * @param part - "First" or "Last" to specify which part to return. * @param onError - 'Empty' | 'Original' = 'Original' return either empty string or the original * @returns The parsed first or last name as a string. * * @example * parseName("Doe, John", ",", "First") // Returns "John" * parseName("Doe, John", ",", "Last") // Returns "Doe" * * @example * parseName("John Smith", ",", "First") // Returns "John" * parseName("John Smith", ",", "Last") // Returns "Smith" * * @example * parseName("Mr. John Smith", ",", "First") // Returns "John" * parseName("Sr. Alex", ",", "Last") // Returns "Alex" * * @example * parseName("I Smith", ",", "First") // Returns "I Smith" (because "I" is <= 3 characters) * parseName("J Smith", ",", "Last") // Returns "J Smith" * * @example * parseName('Doe, John'); // "Doe" (default 'Last', default delimiter) * parseName('John Smith', 'First'); // "John" (uses default delimiter, even though it's not present) * parseName('John | Smith', 'Last', '|'); // "Smith" */ export declare function parseDisplayName(name: string, part?: 'First' | 'Last', delimiter?: string, onError?: 'Empty' | 'Original'): string; //# sourceMappingURL=parseDisplayName.d.ts.map