Skip to content

feat(regex): add regex organizationAlias and uuid #2736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-breads-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scaleway/regex": minor
---

feat(regex): add regex organizationAlias and uuid
41 changes: 41 additions & 0 deletions packages/regex/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
ipv6Cidr,
macAddress,
nineDigitsCode,
organizationAlias,
password,
pathSegment,
phone,
Expand All @@ -51,6 +52,7 @@ import {
uppercaseBasicDomain,
uppercaseBasicSubdomain,
url,
uuid,
} from '..'

const alphanumDashDotsText = 'testwithdashdots-.'
Expand Down Expand Up @@ -104,6 +106,7 @@ const linuxPaths = {
],
GOOD: ['/var', '/var/test', '/var/test_', '/var_/test', '/'],
}
const uuidTest = '550e8400-e29b-41d4-a716-446655440000'

describe('@regex', () => {
describe('alpha', () => {
Expand Down Expand Up @@ -495,6 +498,24 @@ describe('@regex', () => {
})
})

describe('organizationAlias', () => {
test.each([
[asciiLetters, false],
[asciiLowercase, true],
[asciiUppercase, false],
[digitsTest, true],
[emailTest, false],
[octdigits, true],
[hexdigits, false],
[printable, false],
[punctuation, false],
[whitespace, false],
[cronTest, false],
])('should match regex %s to be %s', (string, expected) => {
expect(organizationAlias.test(string)).toBe(expected)
})
})

describe('ascii', () => {
test.each([
[asciiLetters, true],
Expand Down Expand Up @@ -1131,4 +1152,24 @@ describe('@regex', () => {
expect(password.test(string)).toBe(expected)
})
})

describe('uuid', () => {
test.each([
[asciiLetters, false],
[asciiLowercase, false],
[asciiUppercase, false],
[digitsTest, false],
[emailTest, false],
[octdigits, false],
[hexdigits, false],
[printable, false],
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
[uuidTest, true],
])('should match regex %s to be %s', (string, expected) => {
expect(uuid.test(string)).toBe(expected)
})
})
})
3 changes: 3 additions & 0 deletions packages/regex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const absoluteLinuxPath = /(^\/$|^(\/[a-zA-Z0-9_]+)*$)/

// eslint-disable-next-line no-control-regex
export const ascii = /^[\x00-\x7F]+$/
export const organizationAlias = /^[a-z0-9]{2,32}$/
export const backupKey = /^[A-Z0-9]{8}$|^[A-Z0-9]{32}$/
export const basicDomain = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+$/
export const uppercaseBasicDomain =
Expand Down Expand Up @@ -51,6 +52,8 @@ export const url =
/^http(s)?:\/\/?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/
export const hexadecimal = /^[0-9a-fA-F]+$/
export const s3BucketName = /^[a-z0-9][-.a-z0-9]{1,61}[a-z0-9]$/
export const uuid =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i

// Pasted from `ip-regex` package (https://github.com/sindresorhus/ip-regex/blob/main/index.js)
const v4 =
Expand Down
Loading