Skip to content

Commit 592fc23

Browse files
committed
feat(regex): add regex organizationAlias and uuid
1 parent 6529250 commit 592fc23

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

.changeset/many-breads-cover.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@scaleway/regex": minor
33
---
44

5-
feat(regex): add regex alias
5+
feat(regex): add regex organizationAlias and uuid

packages/regex/src/__tests__/index.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
absolutePath,
55
accessKeyRegex,
66
advancedDomainName,
7-
alias,
87
alpha,
98
alphaDashes,
109
alphaLowercase,
@@ -41,6 +40,7 @@ import {
4140
ipv6Cidr,
4241
macAddress,
4342
nineDigitsCode,
43+
organizationAlias,
4444
password,
4545
pathSegment,
4646
phone,
@@ -52,6 +52,7 @@ import {
5252
uppercaseBasicDomain,
5353
uppercaseBasicSubdomain,
5454
url,
55+
uuid,
5556
} from '..'
5657

5758
const alphanumDashDotsText = 'testwithdashdots-.'
@@ -105,6 +106,7 @@ const linuxPaths = {
105106
],
106107
GOOD: ['/var', '/var/test', '/var/test_', '/var_/test', '/'],
107108
}
109+
const uuidTest = '550e8400-e29b-41d4-a716-446655440000'
108110

109111
describe('@regex', () => {
110112
describe('alpha', () => {
@@ -496,7 +498,7 @@ describe('@regex', () => {
496498
})
497499
})
498500

499-
describe('alias', () => {
501+
describe('organizationAlias', () => {
500502
test.each([
501503
[asciiLetters, false],
502504
[asciiLowercase, true],
@@ -510,7 +512,7 @@ describe('@regex', () => {
510512
[whitespace, false],
511513
[cronTest, false],
512514
])('should match regex %s to be %s', (string, expected) => {
513-
expect(alias.test(string)).toBe(expected)
515+
expect(organizationAlias.test(string)).toBe(expected)
514516
})
515517
})
516518

@@ -1150,4 +1152,24 @@ describe('@regex', () => {
11501152
expect(password.test(string)).toBe(expected)
11511153
})
11521154
})
1155+
1156+
describe('uuid', () => {
1157+
test.each([
1158+
[asciiLetters, false],
1159+
[asciiLowercase, false],
1160+
[asciiUppercase, false],
1161+
[digitsTest, false],
1162+
[emailTest, false],
1163+
[octdigits, false],
1164+
[hexdigits, false],
1165+
[printable, false],
1166+
[punctuation, false],
1167+
[whitespace, false],
1168+
[cronTest, false],
1169+
[macAddress1, false],
1170+
[uuidTest, true],
1171+
])('should match regex %s to be %s', (string, expected) => {
1172+
expect(uuid.test(string)).toBe(expected)
1173+
})
1174+
})
11531175
})

packages/regex/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const absoluteLinuxPath = /(^\/$|^(\/[a-zA-Z0-9_]+)*$)/
2424

2525
// eslint-disable-next-line no-control-regex
2626
export const ascii = /^[\x00-\x7F]+$/
27-
export const alias = /^[a-z0-9]{2,32}$/
27+
export const organizationAlias = /^[a-z0-9]{2,32}$/
2828
export const backupKey = /^[A-Z0-9]{8}$|^[A-Z0-9]{32}$/
2929
export const basicDomain = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+$/
3030
export const uppercaseBasicDomain =
@@ -52,6 +52,8 @@ export const url =
5252
/^http(s)?:\/\/?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/
5353
export const hexadecimal = /^[0-9a-fA-F]+$/
5454
export const s3BucketName = /^[a-z0-9][-.a-z0-9]{1,61}[a-z0-9]$/
55+
export const uuid =
56+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
5557

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

0 commit comments

Comments
 (0)