-
Notifications
You must be signed in to change notification settings - Fork 23
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
isShape validator and better documentation generation #183
base: master
Are you sure you want to change the base?
Conversation
Added extra arguments to the wrapper function to be able to describe what is required and can't be empty along with a helper for formatting that information.
This makes processResult work better with isShape.
*/ | ||
export default function writeInfoInline(type, canBeEmpty, required) { | ||
const empty = canBeEmpty ? '?' : ''; | ||
return type && `${required ? `<${empty}${type}>` : `[${empty}${type}]`}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to force this to always return a string? Right now it'll return a falsy value or a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that type
will only ever be the empty string, and because of that we will return the empty string. Could be discussed if it would be better to not have such implicit assumptions.
key: `${key}`, | ||
value: input[key], | ||
message: result, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be any way to create a composed validation error of all properties that failed to validate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to both fail early and to not overwhelm the user with error messages.
Adds a new validator that can be used most specifically for Hook validation.
This PR also improves the information in the documentation generation for
isArray
,isObject
andoneOf
validators giving information about the types that they wrap.This through a new syntax for the documentation generation when describing wrapped validators.
[TYPE]
means that the type is optional,<TYPE>
means that it is required. A question mark in front of the type,?TYPE
means that it can be empty.Array(<String>)
means thatnull
andundefined
are allowed as values but not empty strings as an example.