@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
76 lines (71 loc) • 3.82 kB
TypeScript
/***
* .88b d88. .d8b. db dD d88888b d888888b d8888b.
* 88'YbdP`88 d8' `8b 88 ,8P' 88' `88' 88 `8D
* 88 88 88 88ooo88 88,8P 88ooooo 88 88 88
* 88 88 88 88~~~88 88`8b 88~~~~~ 88 88 88
* 88 88 88 88 88 88 `88. 88. .88. 88 .8D
* YP YP YP YP YP YP YD Y88888P Y888888P Y8888D'
*
*
*/
export declare function makeid(length: number): string;
/***
* d888888b .d8888. d888b db db d888888b d8888b.
* `88' 88' YP 88' Y8b 88 88 `88' 88 `8D
* 88 `8bo. 88 88 88 88 88 88
* 88 `Y8b. 88 ooo 88 88 88 88 88
* .88. db 8D 88. ~8~ 88b d88 .88. 88 .8D
* Y888888P `8888Y' Y888P ~Y8888P' Y888888P Y8888D'
*
*
*/
/**
* Regex courtesy of: https://stackoverflow.com/a/13653180/4210807
*
* NOTES:
* ^ at the beginning denotes the test string must START with that: ^ asserts position at start of the string
* ^ at the beginning denotes the test string must END with that: $ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
* [0-9a-f]{8} - 8 characters between 0-9 and a-f
* [0-9a-f]{4} - 4 characters between 0-9 and a-f
* [1-5][0-9a-f]{3} - one character between 1-5 and 3 between 0-9 and a-f
* [1-5][0-9a-f]{3} - one character between 1-5 and 3 between 0-9 and a-f
* [0-9a-f]{12} - 12 characters between 0-9 and a-f
*
* Here are some notes comparing this to another function in getSourceListsAPI called isStringListGuid
Case-Insensitive (/i flag):
/^\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}?$/i;
The /i flag makes the regex case-insensitive, so it matches both uppercase (A-F) and lowercase (a-f) hexadecimal characters.
My regex achieved the same by explicitly listing [0-9a-fA-F].
Version Validation ([1-5]):
The third segment of a UUID starts with a digit from 1 to 5. This enforces the version of the UUID (e.g., time-based, DCE security, etc.).
My regex does not validate this, allowing any hexadecimal character in this position.
Variant Validation ([89ab]):
The first character in the fourth segment is restricted to 8, 9, a, or b. This enforces the variant (e.g., UUID as per RFC 4122).
My regex does not validate this, allowing any hexadecimal character in this position.
No Optional Braces ({}):
Your regex assumes the GUID is always in the "bare" format without curly braces, whereas my regex optionally allows {}.
*
*/
export declare const ValidGuidRegexExact: RegExp;
export declare const ValidGuidRegexStart: RegExp;
export declare const ValidGuidRegexEnd: RegExp;
export declare const ValidGuidRegexContains: RegExp;
export declare const ValidGuidRegexExactGlobal: RegExp;
export declare const ValidGuidRegexStartGlobal: RegExp;
export declare const ValidGuidRegexEndGlobal: RegExp;
export declare const ValidGuidRegexContainsGlobal: RegExp;
export type IIsGuidTestLocation = 'exact' | 'start' | 'end' | 'contains';
export declare function isGuid(input: any, compareType?: IIsGuidTestLocation): boolean;
/**
* getGuidsFromString is similar to isGuid except it returns the guid(s) found in the string
*
* https://regex101.com/
*
* Returns null if no guid is found.
* Returns array of string containing the first guid found in the string ( g modifier: global. All matches (don't return after first match) )
*
* @param testMe
* @param compareType
*/
export declare function getGuidsFromString(input: any, compareType?: IIsGuidTestLocation): string;
//# sourceMappingURL=guids.d.ts.map