Skip to content

Commit

Permalink
Format function docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelLefkowitz committed Jul 14, 2024
1 parent 285e7ff commit 94bd481
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/factories/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export const either =
* };
*
* @typeParam T - The validated type
* @param first - The validator
* @param first - The validator
*/
export const optional = <T>(validator: Validator<T>): Validator<T | undefined> =>
either(validator, isUndefined);
export const optional = <T>(
validator: Validator<T>,
): Validator<T | undefined> => either(validator, isUndefined);
10 changes: 8 additions & 2 deletions src/factories/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ describe("validateWith", () => {
expect(validator({ a: "1" }).parsed).toEqual({ a: "1", b: undefined });

expect(validator({ a: "1", b: undefined }).valid).toBe(true);
expect(validator({ a: "1", b: undefined }).parsed).toEqual({ a: "1", b: undefined });
expect(validator({ a: "1", b: undefined }).parsed).toEqual({
a: "1",
b: undefined,
});

expect(validator({ a: "1", b: 1 }).error).toEqual({ b: "Not a string: 1" });
expect(validator({ a: "1", b: "1" }).parsed).toEqual({ a: "1", b: 1 });
Expand Down Expand Up @@ -144,7 +147,10 @@ describe("validateWithAtLeast", () => {
expect(validator({ a: "1" }).parsed).toEqual({ a: "1", b: undefined });

expect(validator({ a: "1", b: undefined }).valid).toBe(true);
expect(validator({ a: "1", b: undefined }).parsed).toEqual({ a: "1", b: undefined });
expect(validator({ a: "1", b: undefined }).parsed).toEqual({
a: "1",
b: undefined,
});

expect(validator({ a: "1", b: 1 }).error).toEqual({ b: "Not a string: 1" });
expect(validator({ a: "1", b: "1" }).parsed).toEqual({ a: "1", b: 1 });
Expand Down

0 comments on commit 94bd481

Please sign in to comment.