Skip to content

Commit

Permalink
💪 Improve tests/docs/types of is module
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 2, 2024
1 parent 34770c0 commit e902b0a
Show file tree
Hide file tree
Showing 68 changed files with 752 additions and 704 deletions.
7 changes: 6 additions & 1 deletion _annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export type AsReadonly<T = unknown> = {
/**
* Annotation for predObj.
*/
export type WithPredObj<T extends Record<PropertyKey, Predicate<unknown>>> = {
export type IsPredObj<
T extends Record<PropertyKey, Predicate<unknown>> = Record<
PropertyKey,
Predicate<unknown>
>,
> = {
predObj: T;
};
5 changes: 0 additions & 5 deletions is/__snapshots__/array_of_test.ts.snap

This file was deleted.

5 changes: 0 additions & 5 deletions is/__snapshots__/instance_of_test.ts.snap

This file was deleted.

8 changes: 4 additions & 4 deletions is/__snapshots__/intersection_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const snapshot = {};

snapshot[`isIntersectionOf<T> > returns properly named function 1`] = `
snapshot[`isIntersectionOf<T> > returns properly named predicate function 1`] = `"isString"`;
snapshot[`isIntersectionOf<T> > returns properly named predicate function 2`] = `
"isObjectOf({
a: isNumber,
b: isString
})"
`;
snapshot[`isIntersectionOf<T> > returns properly named function 2`] = `"isString"`;
snapshot[`isIntersectionOf<T> > returns properly named function 3`] = `
snapshot[`isIntersectionOf<T> > returns properly named predicate function 3`] = `
"isIntersectionOf([
isFunction,
isObjectOf({b: isString})
Expand Down
15 changes: 0 additions & 15 deletions is/__snapshots__/literal_of_test.ts.snap

This file was deleted.

3 changes: 0 additions & 3 deletions is/__snapshots__/literal_one_of_test.ts.snap

This file was deleted.

9 changes: 0 additions & 9 deletions is/__snapshots__/map_of_test.ts.snap

This file was deleted.

6 changes: 3 additions & 3 deletions is/__snapshots__/object_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export const snapshot = {};

snapshot[`isObjectOf<T> > returns properly named function 1`] = `
snapshot[`isObjectOf<T> > returns properly named predicate function 1`] = `
"isObjectOf({
a: isNumber,
b: isString,
c: isBoolean
})"
`;
snapshot[`isObjectOf<T> > returns properly named function 2`] = `"isObjectOf({a: a})"`;
snapshot[`isObjectOf<T> > returns properly named predicate function 2`] = `"isObjectOf({a: a})"`;
snapshot[`isObjectOf<T> > returns properly named function 3`] = `
snapshot[`isObjectOf<T> > returns properly named predicate function 3`] = `
"isObjectOf({
a: isObjectOf({
b: isObjectOf({c: isBoolean})
Expand Down
4 changes: 2 additions & 2 deletions is/__snapshots__/omit_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const snapshot = {};

snapshot[`isOmitOf<T, K> > returns properly named function 1`] = `
snapshot[`isOmitOf<T, K> > returns properly named predicate function 1`] = `
"isObjectOf({
a: isNumber,
c: isBoolean
})"
`;

snapshot[`isOmitOf<T, K> > returns properly named function 2`] = `"isObjectOf({a: isNumber})"`;
snapshot[`isOmitOf<T, K> > returns properly named predicate function 2`] = `"isObjectOf({a: isNumber})"`;
16 changes: 8 additions & 8 deletions is/__snapshots__/parameters_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export const snapshot = {};

snapshot[`isParametersOf<T> > returns properly named function 1`] = `
snapshot[`isParametersOf<T> > returns properly named predicate function 1`] = `
"isParametersOf([
isNumber,
isString,
asOptional(isBoolean)
])"
`;
snapshot[`isParametersOf<T> > returns properly named function 2`] = `"isParametersOf([(anonymous)])"`;
snapshot[`isParametersOf<T> > returns properly named predicate function 2`] = `"isParametersOf([(anonymous)])"`;
snapshot[`isParametersOf<T> > returns properly named function 3`] = `"isParametersOf([])"`;
snapshot[`isParametersOf<T> > returns properly named predicate function 3`] = `"isParametersOf([])"`;
snapshot[`isParametersOf<T> > returns properly named function 4`] = `
snapshot[`isParametersOf<T> > returns properly named predicate function 4`] = `
"isParametersOf([
isParametersOf([
isParametersOf([
Expand All @@ -24,19 +24,19 @@ snapshot[`isParametersOf<T> > returns properly named function 4`] = `
])"
`;
snapshot[`isParametersOf<T, E> > returns properly named function 1`] = `
snapshot[`isParametersOf<T, E> > returns properly named predicate function 1`] = `
"isParametersOf([
isNumber,
isString,
asOptional(isBoolean)
], isArray)"
`;
snapshot[`isParametersOf<T, E> > returns properly named function 2`] = `"isParametersOf([(anonymous)], isArrayOf(isString))"`;
snapshot[`isParametersOf<T, E> > returns properly named predicate function 2`] = `"isParametersOf([(anonymous)], isArrayOf(isString))"`;
snapshot[`isParametersOf<T, E> > returns properly named function 3`] = `"isParametersOf([], isArrayOf(isString))"`;
snapshot[`isParametersOf<T, E> > returns properly named predicate function 3`] = `"isParametersOf([], isArrayOf(isString))"`;
snapshot[`isParametersOf<T, E> > returns properly named function 4`] = `
snapshot[`isParametersOf<T, E> > returns properly named predicate function 4`] = `
"isParametersOf([
isParametersOf([
isParametersOf([
Expand Down
4 changes: 2 additions & 2 deletions is/__snapshots__/partial_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const snapshot = {};

snapshot[`isPartialOf<T> > returns properly named function 1`] = `
snapshot[`isPartialOf<T> > returns properly named predicate function 1`] = `
"isObjectOf({
a: asOptional(isNumber),
b: asOptional(isUnionOf([
Expand All @@ -12,7 +12,7 @@ snapshot[`isPartialOf<T> > returns properly named function 1`] = `
})"
`;
snapshot[`isPartialOf<T> > returns properly named function 2`] = `
snapshot[`isPartialOf<T> > returns properly named predicate function 2`] = `
"isObjectOf({
a: asOptional(isNumber),
b: asOptional(isUnionOf([
Expand Down
4 changes: 2 additions & 2 deletions is/__snapshots__/pick_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const snapshot = {};

snapshot[`isPickOf<T, K> > returns properly named function 1`] = `
snapshot[`isPickOf<T, K> > returns properly named predicate function 1`] = `
"isObjectOf({
a: isNumber,
c: isBoolean
})"
`;

snapshot[`isPickOf<T, K> > returns properly named function 2`] = `"isObjectOf({a: isNumber})"`;
snapshot[`isPickOf<T, K> > returns properly named predicate function 2`] = `"isObjectOf({a: isNumber})"`;
16 changes: 8 additions & 8 deletions is/__snapshots__/readonly_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const snapshot = {};

snapshot[`isReadonlyOf<T> > with isRecord > returns properly named function 1`] = `"isReadonlyOf(isRecord)"`;
snapshot[`isReadonlyOf<T> > with isRecord > returns properly named predicate function 1`] = `"isReadonlyOf(isRecord)"`;
snapshot[`isReadonlyOf<T> > with isRecord > returns properly named function 2`] = `"isReadonlyOf(isRecord)"`;
snapshot[`isReadonlyOf<T> > with isRecord > returns properly named predicate function 2`] = `"isReadonlyOf(isRecord)"`;
snapshot[`isReadonlyOf<T> > with isObjectOf > returns properly named function 1`] = `
snapshot[`isReadonlyOf<T> > with isObjectOf > returns properly named predicate function 1`] = `
"isReadonlyOf(isObjectOf({
a: isNumber,
b: isUnionOf([
Expand All @@ -15,7 +15,7 @@ snapshot[`isReadonlyOf<T> > with isObjectOf > returns properly named function 1`
}))"
`;
snapshot[`isReadonlyOf<T> > with isObjectOf > returns properly named function 2`] = `
snapshot[`isReadonlyOf<T> > with isObjectOf > returns properly named predicate function 2`] = `
"isReadonlyOf(isObjectOf({
a: isNumber,
b: isUnionOf([
Expand All @@ -26,22 +26,22 @@ snapshot[`isReadonlyOf<T> > with isObjectOf > returns properly named function 2`
}))"
`;
snapshot[`isReadonlyOf<T> > with isTupleOf > returns properly named function 1`] = `
snapshot[`isReadonlyOf<T> > with isTupleOf > returns properly named predicate function 1`] = `
"isReadonlyOf(isTupleOf([
isNumber,
isString,
asReadonly(isBoolean)
]))"
`;
snapshot[`isReadonlyOf<T> > with isTupleOf > returns properly named function 2`] = `
snapshot[`isReadonlyOf<T> > with isTupleOf > returns properly named predicate function 2`] = `
"isReadonlyOf(isTupleOf([
isNumber,
isString,
asReadonly(isBoolean)
]))"
`;
snapshot[`isReadonlyOf<T> > with isUniformTupleOf > returns properly named function 1`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
snapshot[`isReadonlyOf<T> > with isUniformTupleOf > returns properly named predicate function 1`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
snapshot[`isReadonlyOf<T> > with isUniformTupleOf > returns properly named function 2`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
snapshot[`isReadonlyOf<T> > with isUniformTupleOf > returns properly named predicate function 2`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
8 changes: 4 additions & 4 deletions is/__snapshots__/record_object_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const snapshot = {};

snapshot[`isRecordObjectOf<T> > returns properly named function 1`] = `"isRecordObjectOf(isNumber, undefined)"`;
snapshot[`isRecordObjectOf<T> > returns properly named predicate function 1`] = `"isRecordObjectOf(isNumber, undefined)"`;
snapshot[`isRecordObjectOf<T> > returns properly named function 2`] = `"isRecordObjectOf((anonymous), undefined)"`;
snapshot[`isRecordObjectOf<T> > returns properly named predicate function 2`] = `"isRecordObjectOf((anonymous), undefined)"`;
snapshot[`isRecordObjectOf<T, K> > returns properly named function 1`] = `"isRecordObjectOf(isNumber, isString)"`;
snapshot[`isRecordObjectOf<T, K> > returns properly named predicate function 1`] = `"isRecordObjectOf(isNumber, isString)"`;
snapshot[`isRecordObjectOf<T, K> > returns properly named function 2`] = `"isRecordObjectOf((anonymous), isString)"`;
snapshot[`isRecordObjectOf<T, K> > returns properly named predicate function 2`] = `"isRecordObjectOf((anonymous), isString)"`;
8 changes: 4 additions & 4 deletions is/__snapshots__/record_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const snapshot = {};

snapshot[`isRecordOf<T> > returns properly named function 1`] = `"isRecordOf(isNumber, undefined)"`;
snapshot[`isRecordOf<T> > returns properly named predicate function 1`] = `"isRecordOf(isNumber, undefined)"`;
snapshot[`isRecordOf<T> > returns properly named function 2`] = `"isRecordOf((anonymous), undefined)"`;
snapshot[`isRecordOf<T> > returns properly named predicate function 2`] = `"isRecordOf((anonymous), undefined)"`;
snapshot[`isRecordOf<T, K> > returns properly named function 1`] = `"isRecordOf(isNumber, isString)"`;
snapshot[`isRecordOf<T, K> > returns properly named predicate function 1`] = `"isRecordOf(isNumber, isString)"`;
snapshot[`isRecordOf<T, K> > returns properly named function 2`] = `"isRecordOf((anonymous), isString)"`;
snapshot[`isRecordOf<T, K> > returns properly named predicate function 2`] = `"isRecordOf((anonymous), isString)"`;
4 changes: 2 additions & 2 deletions is/__snapshots__/required_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const snapshot = {};

snapshot[`isRequiredOf<T> > returns properly named function 1`] = `
snapshot[`isRequiredOf<T> > returns properly named predicate function 1`] = `
"isObjectOf({
a: isNumber,
b: isUnionOf([
Expand All @@ -12,7 +12,7 @@ snapshot[`isRequiredOf<T> > returns properly named function 1`] = `
})"
`;
snapshot[`isRequiredOf<T> > returns properly named function 2`] = `
snapshot[`isRequiredOf<T> > returns properly named predicate function 2`] = `
"isObjectOf({
a: isNumber,
b: isUnionOf([
Expand Down
4 changes: 2 additions & 2 deletions is/__snapshots__/set_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const snapshot = {};

snapshot[`isSetOf<T> > returns properly named function 1`] = `"isSetOf(isNumber)"`;
snapshot[`isSetOf<T> > returns properly named predicate function 1`] = `"isSetOf(isNumber)"`;
snapshot[`isSetOf<T> > returns properly named function 2`] = `"isSetOf((anonymous))"`;
snapshot[`isSetOf<T> > returns properly named predicate function 2`] = `"isSetOf((anonymous))"`;
6 changes: 3 additions & 3 deletions is/__snapshots__/strict_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export const snapshot = {};

snapshot[`isStrictOf<T> > returns properly named function 1`] = `
snapshot[`isStrictOf<T> > returns properly named predicate function 1`] = `
"isStrictOf(isObjectOf({
a: isNumber,
b: isString,
c: isBoolean
}))"
`;
snapshot[`isStrictOf<T> > returns properly named function 2`] = `"isStrictOf(isObjectOf({a: a}))"`;
snapshot[`isStrictOf<T> > returns properly named predicate function 2`] = `"isStrictOf(isObjectOf({a: a}))"`;
snapshot[`isStrictOf<T> > returns properly named function 3`] = `
snapshot[`isStrictOf<T> > returns properly named predicate function 3`] = `
"isStrictOf(isObjectOf({
a: isStrictOf(isObjectOf({
b: isStrictOf(isObjectOf({c: isBoolean}))
Expand Down
12 changes: 6 additions & 6 deletions is/__snapshots__/tuple_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export const snapshot = {};

snapshot[`isTupleOf<T> > returns properly named function 1`] = `
snapshot[`isTupleOf<T> > returns properly named predicate function 1`] = `
"isTupleOf([
isNumber,
isString,
isBoolean
])"
`;
snapshot[`isTupleOf<T> > returns properly named function 2`] = `"isTupleOf([(anonymous)])"`;
snapshot[`isTupleOf<T> > returns properly named predicate function 2`] = `"isTupleOf([(anonymous)])"`;
snapshot[`isTupleOf<T> > returns properly named function 3`] = `
snapshot[`isTupleOf<T> > returns properly named predicate function 3`] = `
"isTupleOf([
isTupleOf([
isTupleOf([
Expand All @@ -22,17 +22,17 @@ snapshot[`isTupleOf<T> > returns properly named function 3`] = `
])"
`;
snapshot[`isTupleOf<T, E> > returns properly named function 1`] = `
snapshot[`isTupleOf<T, E> > returns properly named predicate function 1`] = `
"isTupleOf([
isNumber,
isString,
isBoolean
], isArray)"
`;
snapshot[`isTupleOf<T, E> > returns properly named function 2`] = `"isTupleOf([(anonymous)], isArrayOf(isString))"`;
snapshot[`isTupleOf<T, E> > returns properly named predicate function 2`] = `"isTupleOf([(anonymous)], isArrayOf(isString))"`;
snapshot[`isTupleOf<T, E> > returns properly named function 3`] = `
snapshot[`isTupleOf<T, E> > returns properly named predicate function 3`] = `
"isTupleOf([
isTupleOf([
isTupleOf([
Expand Down
6 changes: 3 additions & 3 deletions is/__snapshots__/uniform_tuple_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const snapshot = {};

snapshot[`isUniformTupleOf<T> > returns properly named function 1`] = `"isUniformTupleOf(3, undefined)"`;
snapshot[`isUniformTupleOf<T> > returns properly named predicate function 1`] = `"isUniformTupleOf(3, undefined)"`;
snapshot[`isUniformTupleOf<T> > returns properly named function 2`] = `"isUniformTupleOf(3, isNumber)"`;
snapshot[`isUniformTupleOf<T> > returns properly named predicate function 2`] = `"isUniformTupleOf(3, isNumber)"`;
snapshot[`isUniformTupleOf<T> > returns properly named function 3`] = `"isUniformTupleOf(3, (anonymous))"`;
snapshot[`isUniformTupleOf<T> > returns properly named predicate function 3`] = `"isUniformTupleOf(3, (anonymous))"`;
2 changes: 1 addition & 1 deletion is/__snapshots__/union_of_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const snapshot = {};

snapshot[`isUnionOf<T> > returns properly named function 1`] = `
snapshot[`isUnionOf<T> > returns properly named predicate function 1`] = `
"isUnionOf([
isNumber,
isString,
Expand Down
2 changes: 2 additions & 0 deletions is/any.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Assume `x is `any` and always return `true` regardless of the type of `x`.
*
* Use {@linkcode isUnknown} to assume that a value is `unknown`.
*
* ```ts
* import { is } from "@core/unknownutil";
*
Expand Down
2 changes: 2 additions & 0 deletions is/array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Return `true` if the type of `x` is `unknown[]`.
*
* Use {@linkcode isArrayOf} to check if the type of `x` is an array of `T`.
*
* ```ts
* import { is } from "@core/unknownutil";
*
Expand Down
2 changes: 2 additions & 0 deletions is/array_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { isArray } from "./array.ts";
/**
* Return a type predicate function that returns `true` if the type of `x` is `T[]`.
*
* Use {@linkcode isArray} to check if the type of `x` is an array of `unknown`.
*
* To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.
*
* ```ts
Expand Down
Loading

0 comments on commit e902b0a

Please sign in to comment.