-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aba651b
commit 36fc997
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Meta } from '@storybook/blocks'; | ||
|
||
<Meta title="Hooks / useMediaQuery" /> | ||
|
||
# Regex Patterns | ||
|
||
Regular expressions (regex) are sequences of characters that form a search pattern. They can be used | ||
to check if a string contains the specified search pattern. This package contains commonly used | ||
patterns that can be used to check strings. | ||
|
||
## Usage | ||
|
||
### PascalCase | ||
|
||
PascalCase is a naming convention in which the first letter of each word is capitalized. It is often | ||
used in programming languages for class names and object constructors. | ||
|
||
```tsx | ||
pascalCaseRegex.test('MyComponent'); // Returns true | ||
pascalCaseRegex.test('MyComponent5'); // Returns true | ||
pascalCaseRegex.test('MyC0mp0nent'); // Returns true | ||
pascalCaseRegex.test('My00mponent'); // Returns true | ||
``` | ||
|
||
### camelCase | ||
|
||
camelCase is another naming convention in which the first letter of each word is capitalized except | ||
for the first word. It is often used in programming languages for variable and function names. | ||
|
||
```ts | ||
camelCaseRegex.test('camelCaseString'); // Returns true | ||
camelCaseRegex.test('helloW0rld'); // Returns true | ||
camelCaseRegex.test('g00M0rning'); // Returns true | ||
camelCaseRegex.test('happyC0ding'); // Returns true | ||
``` | ||
|
||
### kebab-case | ||
|
||
kebab-case is a naming convention in which words are separated by hyphens (-). It is often used in | ||
URL slugs and CSS class names. | ||
|
||
```ts | ||
kebabCaseRegex.test('my-component'); // Returns true | ||
kebabCaseRegex.test('my-component-5'); // Returns true | ||
kebabCaseRegex.test('my-c0mp0nent'); // Returns true | ||
kebabCaseRegex.test('c0ding1sfun'); // Returns true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { camelCaseRegex, kebabCaseRegex, pascalCaseRegex } from './regexPatterns.js'; | ||
|
||
describe('pascalCaseRegex', () => { | ||
it('should match string in the pascal case naming convention', () => { | ||
expect(pascalCaseRegex.test('MyComponent')).toBeTruthy(); | ||
expect(pascalCaseRegex.test('MyComponent5')).toBeTruthy(); | ||
expect(pascalCaseRegex.test('MyC0mp0nent')).toBeTruthy(); | ||
expect(pascalCaseRegex.test('My00mponent')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('camelCaseRegex', () => { | ||
it('should match string in the camel case naming convention', () => { | ||
expect(camelCaseRegex.test('camelCaseString')).toBeTruthy(); | ||
expect(camelCaseRegex.test('helloW0rld')).toBeTruthy(); | ||
expect(camelCaseRegex.test('g00M0rning')).toBeTruthy(); | ||
expect(camelCaseRegex.test('happyC0ding')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('kebabCaseRegex', () => { | ||
it('should match string in the kebab case naming convention', () => { | ||
expect(kebabCaseRegex.test('my-component')).toBeTruthy(); | ||
expect(kebabCaseRegex.test('my-component-5')).toBeTruthy(); | ||
expect(kebabCaseRegex.test('my-c0mp0nent')).toBeTruthy(); | ||
expect(kebabCaseRegex.test('c0ding1sfun')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* PascalCaseString | ||
* MyComponent | ||
* MyComponent5 | ||
* MyC0mp0nent | ||
* My00mponent | ||
*/ | ||
// eslint-disable-next-line unicorn/no-unsafe-regex | ||
export const pascalCaseRegex = /^(?:[A-Z][\da-z]+)+$/u; | ||
|
||
/** | ||
* @example | ||
* camelCaseString | ||
* helloW0rld | ||
* g00M0rning | ||
* happyC0ding | ||
*/ | ||
// eslint-disable-next-line unicorn/no-unsafe-regex | ||
export const camelCaseRegex = /^[\da-z]+(?:[A-Z][\da-z]+)*$/u; | ||
|
||
/** | ||
* @example | ||
* my-component | ||
* my-component-5 | ||
* my-c0mp0nent | ||
* c0ding1sfun | ||
*/ | ||
// eslint-disable-next-line unicorn/no-unsafe-regex | ||
export const kebabCaseRegex = /^[\da-z]+(?:-[\da-z]+)*$/u; |