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

add ltValue action #985

Merged
merged 6 commits into from
Feb 16, 2025
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
1 change: 1 addition & 0 deletions library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to the library will be documented in this file.
- Add `words`, `maxWords`, `minWords` and `notWords` action
- Add `args` and `returns` action to transform functions (issue #243)
- Add `rfcEmail` action to validate RFC 5322 email addresses (pull request #912)
- Add `ltValue` action for less than validation (pull request #985)
- Add new overload signature to `pipe` and `pipeAync` method to support unlimited pipe items of same input and output type (issue #852)
- Add `@__NO_SIDE_EFFECTS__` notation to improve tree shaking (pull request #995)
- Add `exactOptional` and `exactOptionalAsync` schema (PR #1013)
Expand Down
1 change: 1 addition & 0 deletions library/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export * from './isoTimeSecond/index.ts';
export * from './isoTimestamp/index.ts';
export * from './isoWeek/index.ts';
export * from './length/index.ts';
export * from './ltValue/index.ts';
export * from './mac/index.ts';
export * from './mac48/index.ts';
export * from './mac64/index.ts';
Expand Down
1 change: 1 addition & 0 deletions library/src/actions/ltValue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ltValue.ts';
45 changes: 45 additions & 0 deletions library/src/actions/ltValue/ltValue.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expectTypeOf, test } from 'vitest';
import type { InferInput, InferIssue, InferOutput } from '../../types/index.ts';
import { ltValue, type LtValueAction, type LtValueIssue } from './ltValue.ts';

describe('ltValue', () => {
describe('should return action object', () => {
test('with undefined message', () => {
type Action = LtValueAction<number, 10, undefined>;
expectTypeOf(ltValue<number, 10>(10)).toEqualTypeOf<Action>();
expectTypeOf(
ltValue<number, 10, undefined>(10, undefined)
).toEqualTypeOf<Action>();
});

test('with string message', () => {
expectTypeOf(ltValue<number, 10, 'message'>(10, 'message')).toEqualTypeOf<
LtValueAction<number, 10, 'message'>
>();
});

test('with function message', () => {
expectTypeOf(
ltValue<number, 10, () => string>(10, () => 'message')
).toEqualTypeOf<LtValueAction<number, 10, () => string>>();
});
});

describe('should infer correct types', () => {
type Action = LtValueAction<number, 10, undefined>;

test('of input', () => {
expectTypeOf<InferInput<Action>>().toEqualTypeOf<number>();
});

test('of output', () => {
expectTypeOf<InferOutput<Action>>().toEqualTypeOf<number>();
});

test('of issue', () => {
expectTypeOf<InferIssue<Action>>().toEqualTypeOf<
LtValueIssue<number, 10>
>();
});
});
});
Loading