Skip to content

Commit

Permalink
Refactor octal validation and add it to changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Dec 23, 2023
1 parent 9987d40 commit dcb6e25
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to the library will be documented in this file.

## vX.X.X (Month DD, YYYY)

- Add `creditCard`, `hash`, `hex` and `hexColor` validation function (pull request #292, #304, #307, #308)
- Add `creditCard`, `hash`, `hex`, `hexColor` and `octal` validation function (pull request #292, #304, #307, #308, #309)

## v0.24.1 (December 11, 2023)

Expand Down
10 changes: 5 additions & 5 deletions library/src/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export const MAC48_REGEX =
export const MAC64_REGEX =
/^(?:[\da-f]{2}:){7}[\da-f]{2}$|^(?:[\da-f]{2}-){7}[\da-f]{2}$|^(?:[\da-f]{4}\.){3}[\da-f]{4}$|^(?:[\da-f]{4}:){3}[\da-f]{4}$/iu;

/**
* [Octal](https://en.wikipedia.org/wiki/Octal) regex.
*/
export const OCTAL_REGEX = /^(0o)?[0-7]+$/iu;

/**
* [ULID](https://github.com/ulid/spec) regex.
*/
Expand All @@ -102,8 +107,3 @@ export const ULID_REGEX = /^[\da-hjkmnp-tv-z]{26}$/iu;
* [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) regex.
*/
export const UUID_REGEX = /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu;

/**
* [OCTAL](https://en.wikipedia.org/wiki/Octal) regex.
*/
export const OCTAL_REGEX = /^(0o)?[0-7]+$/iu;
10 changes: 3 additions & 7 deletions library/src/validations/octal/octal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@ import { octal } from './octal.ts';
describe('octal', () => {
test('should pass only valid strings', () => {
const validate = octal();

const value = '123';
expect(validate._parse(value).output).toBe(value);

const value2 = '001';
expect(validate._parse(value2).output).toBe(value2);

const value3 = '765';
expect(validate._parse(value3).output).toBe(value3);

const value4 = '000';
expect(validate._parse(value4).output).toBe(value4);

const value5 = '111';
expect(validate._parse(value5).output).toBe(value5);

const value6 = '020';
expect(validate._parse(value6).output).toBe(value6);

const value7 = '707';
expect(validate._parse(value7).output).toBe(value7);

const value8 = '00012345';
expect(validate._parse(value8).output).toBe(value8);
const value9 = '0o12345';
expect(validate._parse(value9).output).toBe(value9);

expect(validate._parse('').issues).toBeTruthy();
expect(validate._parse('8').issues).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions library/src/validations/octal/octal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export type OctalValidation<TInput extends string> = BaseValidation<TInput> & {
*/
type: 'octal';
/**
* The Octal regex.
* The octal regex.
*/
requirement: RegExp;
};

/**
* Creates a validation function that validates an [OCTAL](https://en.wikipedia.org/wiki/Octal) string.
* Creates a validation function that validates an [octal](https://en.wikipedia.org/wiki/Octal) string.
*
* @param message The error message.
*
Expand Down
1 change: 1 addition & 0 deletions website/src/routes/api/(schemas)/any/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ The following APIs can be combined with `any`.
'notLength',
'notSize',
'notValue',
'octal',
'regex',
'safeInteger',
'size',
Expand Down
1 change: 1 addition & 0 deletions website/src/routes/api/(schemas)/string/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ The following APIs can be combined with `string`.
'notBytes',
'notLength',
'notValue',
'octal',
'regex',
'startsWith',
'ulid',
Expand Down

0 comments on commit dcb6e25

Please sign in to comment.