Skip to content
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
28 changes: 28 additions & 0 deletions packages/regex/src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
phone,
sixDigitsCode,
spaces,
uppercaseBasicDomain,
url,
} from '..'

Expand All @@ -44,6 +45,8 @@ const asciiUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
const backupKeyTest = '123456789ABCEDFGHIJIKLMNOPQRSTUV'
const domain = 'another-example.com'
const subDomain = 'sub.another-example.com'
const dashStartDomain = '-sub.another-example.com'
const uppercaseDomain = 'SUB.another-example.com'
const longTldDomain = 'sub.another-example.verylongtld'
const cronTest = '0/15*-'
const digitsTest = '0123456789'
Expand Down Expand Up @@ -461,6 +464,31 @@ describe('@regex', () => {
expect(basicDomain.test(string)).toBe(expected)
})
})
describe('uppercaseBasicDomain', () => {
test.each([
[asciiLetters, false],
[asciiLowercase, false],
[asciiUppercase, false],
[backupKeyTest, false],
[domain, true],
[subDomain, true],
[dashStartDomain, false],
[uppercaseDomain, true],
[longTldDomain, true],
[digitsTest, false],
[emailTest, false],
[octdigits, false],
[hexdigits, false],
[printable, false],
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
...(urls.map(urlString => [urlString, false]) as [string, boolean][]),
])('should match regex %s to be %s', (string, expected) => {
expect(uppercaseBasicDomain.test(string)).toBe(expected)
})
})

describe('cron', () => {
test.each([
Expand Down
3 changes: 3 additions & 0 deletions packages/regex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const absoluteLinuxPath = /(^\/$|^(\/[a-zA-Z0-9_]+)*$)/
export const ascii = /^[\x00-\x7F]+$/
export const backupKey = /^[A-Z0-9]{32}$/
export const basicDomain = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+$/
export const uppercaseBasicDomain =
/^(?![-])+[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,63})+$/

export const cron = /^[0-9,/*-]+$/
export const digits = /^[0-9]*$/
export const macAddress =
Expand Down