Skip to content
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

feat: add mac address regex #67

Merged
merged 1 commit into from
Mar 12, 2021
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
44 changes: 44 additions & 0 deletions packages/regex/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
digits,
email,
fourDigitsCode,
macAddress,
phone,
sixDigitsCode,
spaces,
Expand All @@ -44,6 +45,7 @@ const sixDigitsCodeTest = '123456'
const url1 = 'http://console.scaleway.com'
const url2 = 'https://www.scaleway.com'
const whitespace = ' \t\n\r\x0b\x0c'
const macAddress1 = '1F:B5:FA:47:CD:C4'

describe('@regex', () => {
describe('alpha', () => {
Expand All @@ -61,6 +63,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alpha.test(string)).toBe(result)),
Expand All @@ -82,6 +85,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanum.test(string)).toBe(result)),
Expand All @@ -103,6 +107,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdash.test(string)).toBe(result)),
Expand All @@ -124,6 +129,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdashdots.test(string)).toBe(result)),
Expand All @@ -145,6 +151,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdashdotsorempty.test(string)).toBe(result)),
Expand All @@ -166,6 +173,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, true],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdashdotsspaces.test(string)).toBe(result)),
Expand All @@ -187,6 +195,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdashorempty.test(string)).toBe(result)),
Expand All @@ -208,6 +217,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, true],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdashspaces.test(string)).toBe(result)),
Expand All @@ -229,6 +239,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumdots.test(string)).toBe(result)),
Expand All @@ -248,6 +259,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumLowercase.test(string)).toBe(result)),
Expand All @@ -267,6 +279,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, true],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumSpacesDotsUnderscoreDash.test(string)).toBe(result)),
Expand All @@ -286,6 +299,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumUnderscoreDash.test(string)).toBe(result)),
Expand All @@ -305,6 +319,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(alphanumUnderscoreDollarDash.test(string)).toBe(result)),
Expand Down Expand Up @@ -344,6 +359,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(backupKey.test(string)).toBe(result)),
Expand Down Expand Up @@ -382,6 +398,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(digits.test(string)).toBe(result)),
Expand All @@ -401,6 +418,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(email.test(string)).toBe(result)),
Expand All @@ -421,12 +439,34 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(fourDigitsCode.test(string)).toBe(result)),
)
})

describe('macAddress', () => {
;[
[asciiLetters, false],
[asciiLowercase, false],
[asciiUppercase, false],
[digitsTest, false],
[emailTest, false],
[octdigits, false],
[fourDigitsTest, false],
[hexdigits, false],
[printable, false],
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, true],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(macAddress.test(string)).toBe(result)),
)
})

describe('phone', () => {
;[
[asciiLetters, false],
Expand All @@ -442,6 +482,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(phone.test(string)).toBe(result)),
Expand All @@ -463,6 +504,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, true],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(spaces.test(string)).toBe(result)),
Expand All @@ -485,6 +527,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
].forEach(([string, result]) =>
it(`should match regex ${string} to be ${result}`, () =>
expect(sixDigitsCode.test(string)).toBe(result)),
Expand All @@ -507,6 +550,7 @@ describe('@regex', () => {
[punctuation, false],
[whitespace, false],
[cronTest, false],
[macAddress1, false],
[url1, true],
[url2, true],
].forEach(([string, result]) =>
Expand Down
1 change: 1 addition & 0 deletions packages/regex/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const ascii = /^[\x00-\x7F]+$/
export const backupKey = /^[A-Z0-9]{32}$/
export const cron = /^[0-9,/*-]+$/
export const digits = /^[0-9]*$/
export const macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/
DorianMaliszewski marked this conversation as resolved.
Show resolved Hide resolved
// Used by W3C
export const email = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
export const fourDigitsCode = /^[0-9]{4}$/
Expand Down