mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
20 lines
621 B
TypeScript
20 lines
621 B
TypeScript
// The isValidOrgSlug function should match the behaviour of this regular expression:
|
|
// ^(?![0-9]+$)[a-zA-Z0-9][a-zA-Z0-9-]*(?<!-)$
|
|
|
|
// See: https://bugs.webkit.org/show_bug.cgi?id=174931
|
|
//
|
|
// The ^(?![0-9]+$)[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$ regex should almost match the above regex.
|
|
const ORG_SLUG_REGEX = new RegExp('^(?![0-9]+$)[a-zA-Z0-9][a-zA-Z0-9-]*$');
|
|
|
|
function isValidOrgSlug(orgSlug: string): boolean {
|
|
return (
|
|
orgSlug.length > 0 &&
|
|
!orgSlug.startsWith('-') &&
|
|
!orgSlug.endsWith('-') &&
|
|
!orgSlug.includes('_') &&
|
|
ORG_SLUG_REGEX.test(orgSlug)
|
|
);
|
|
}
|
|
|
|
export default isValidOrgSlug;
|