-
Notifications
You must be signed in to change notification settings - Fork 0
/
ror.ts
29 lines (27 loc) · 878 Bytes
/
ror.ts
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
export const rorPrefix = "https://ror.org/";
export const RORPattern =
"^https:\\/\\/ror\\.org\\/0[a-hj-km-np-tv-z|0-9]{6}[0-9]{2}$|^0[a-hj-km-np-tv-z|0-9]{6}[0-9]{2}$";
export const reROR = new RegExp(RORPattern, "i");
//;
/**
* normalizeROR takes a string and returns a normalized vesion of the ROR
* @param ror
* @returns string
*/
export function normalizeROR(ror: string): string {
let bareROR = ror.trim().toLowerCase();
if (bareROR.startsWith(rorPrefix)) {
return bareROR;
}
return `${rorPrefix}${bareROR}`;
}
/**
* validateROR takes a string and return true if it is a valid ROR and false otherwise.
* The ROR will be normalized before validation.
* @param ror
* @returns true if a valid ROR, false otherwise
*/
export function validateROR(ror: string): boolean {
const normalizedROR = normalizeROR(ror);
return reROR.test(normalizedROR);
}