Skip to content

Commit 9019322

Browse files
authored
feat(regex): add regex organizationAlias and uuid (#2736)
* feat(regex): add regex alias * feat(regex): add regex organizationAlias and uuid * feat(regex): add case insensitive
1 parent 5528f29 commit 9019322

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

.changeset/many-breads-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scaleway/regex": minor
3+
---
4+
5+
feat(regex): add regex organizationAlias and uuid

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
ipv6Cidr,
4141
macAddress,
4242
nineDigitsCode,
43+
organizationAlias,
4344
password,
4445
pathSegment,
4546
phone,
@@ -51,6 +52,7 @@ import {
5152
uppercaseBasicDomain,
5253
uppercaseBasicSubdomain,
5354
url,
55+
uuid,
5456
} from '..'
5557

5658
const alphanumDashDotsText = 'testwithdashdots-.'
@@ -104,6 +106,7 @@ const linuxPaths = {
104106
],
105107
GOOD: ['/var', '/var/test', '/var/test_', '/var_/test', '/'],
106108
}
109+
const uuidTest = '550e8400-e29b-41d4-a716-446655440000'
107110

108111
describe('@regex', () => {
109112
describe('alpha', () => {
@@ -495,6 +498,24 @@ describe('@regex', () => {
495498
})
496499
})
497500

501+
describe('organizationAlias', () => {
502+
test.each([
503+
[asciiLetters, false],
504+
[asciiLowercase, true],
505+
[asciiUppercase, false],
506+
[digitsTest, true],
507+
[emailTest, false],
508+
[octdigits, true],
509+
[hexdigits, false],
510+
[printable, false],
511+
[punctuation, false],
512+
[whitespace, false],
513+
[cronTest, false],
514+
])('should match regex %s to be %s', (string, expected) => {
515+
expect(organizationAlias.test(string)).toBe(expected)
516+
})
517+
})
518+
498519
describe('ascii', () => {
499520
test.each([
500521
[asciiLetters, true],
@@ -1131,4 +1152,24 @@ describe('@regex', () => {
11311152
expect(password.test(string)).toBe(expected)
11321153
})
11331154
})
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+
})
11341175
})

packages/regex/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +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 organizationAlias = /^[a-z0-9]{2,32}$/
2728
export const backupKey = /^[A-Z0-9]{8}$|^[A-Z0-9]{32}$/
2829
export const basicDomain = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+$/
2930
export const uppercaseBasicDomain =
@@ -51,6 +52,8 @@ export const url =
5152
/^http(s)?:\/\/?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/
5253
export const hexadecimal = /^[0-9a-fA-F]+$/
5354
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}$/i
5457

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

0 commit comments

Comments
 (0)