Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
feat: stringField support undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
hanayashiki committed Mar 8, 2022
1 parent 70695f7 commit f9ae67d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "https://github.com/MonoidDev/reform"
},
"private": false,
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down
24 changes: 21 additions & 3 deletions src/fields/stringField.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { string } from '../types/BasicTypes';
import { any } from '../types/BasicTypes';
import { Either, makeLeft, makeRight } from '../types/Either';
import { ErrorMessage } from '../types/ErrorMessage';

export const stringField = () => {
const stringType = string<string>();
export interface StringFieldOptions {
message: string;
}

export const stringField = (
options: StringFieldOptions = { message: 'Invalid value supplied to string' },
) => {
const { message } = options;

const stringType = any().refine((input) => {
if (input == null) {
return makeRight('');
}

if (typeof input === 'string') {
return makeRight(input);
}

return makeLeft({ message });
});

return {
...stringType,
Expand Down

1 comment on commit f9ae67d

@vercel
Copy link

@vercel vercel bot commented on f9ae67d Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

The most recent charge for your active payment method has failed. Please update it here: https://vercel.com/teams/monoid-dev/settings/billing.

Please sign in to comment.