@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
39 lines • 2.25 kB
TypeScript
/**
* https://github.com/mikezimm/drilldown7/issues/499
* Extracts the first occurrence of a digit sequence of a specified length from a given string,
* optionally allowing a trailing suffix of letters.
*
* @param input - The input string to search.
* @param digitCount - The exact number of digits to look for (e.g., 5 for ZIP code).
* @param trailingCharacters - Optional. Number of trailing characters to allow (default = 0).
* @param onlyCAPS - Optional. If true, only allows trailing characters if all are uppercase (default = false).
*
* @returns The matched digit sequence (with or without suffix depending on parameters), or an empty string if no match is found.
*
* ✅ Examples:
* getDigitSequence("Zip: 48226", 5) → "48226"
* getDigitSequence("CostCenter-12345A", 5) → "" (suffix not allowed)
* getDigitSequence("Dept: 12345A", 5, 1) → "12345A"
* getDigitSequence("Region: 12345ab", 5, 2) → "12345ab"
* getDigitSequence("Region: 12345ab", 5, 2, true) → "" (suffix not all caps)
* getDigitSequence("Region: 12345AB", 5, 2, true) → "12345AB"
* getDigitSequence("ID: 1234A", 4, 2) → "1234A"
*
* ❗ Notes:
* - Uses negative lookbehind (`(?<!\\d)`) to ensure the match is not part of a longer number.
* - Uses negative lookahead (`(?!\\w)`) to prevent the match from being part of a larger word.
* - Underscores `_` and dashes `-` are considered non-word characters, so they count as boundaries.
* - `|` and `/` are also boundary-friendly in this regex, as they are not word characters.
*/
export declare function getDigitSequence(input: string, digitCount: number, trailingCharacters?: number, onlyCAPS?: boolean): string;
/**
* https://github.com/mikezimm/drilldown7/issues/499
* Use this option to get the number sequence based on extra characters but only include the number part
* @param input
* @param digitCount
* @param trailingCharacters
* @param onlyCAPS
* @returns
*/
export declare function getDigitSequenceTrimmed(input: string, digitCount: number, trailingCharacters?: number, onlyCAPS?: boolean): string;
//# sourceMappingURL=getDigitSequence.d.ts.map