-
Notifications
You must be signed in to change notification settings - Fork 67
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
utils: Introduce validationUtils
namespace & character length validation logic
#1656
Conversation
…into mwf/validation-utils-1
* @property `lowerLimitIncl`: The minimum size of the range (inclusive) | ||
* @property `upperLimitIncl`: The maximum size of the range (inclusive) | ||
*/ | ||
export interface RangeConstraints { |
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.
Kept this named more generically because I was planning to reuse this interface again later for another validation method covering numeric range
validationUtils
namespace & character length validation logicvalidationUtils
namespace & character length validation logic
utils/src/utils/validationUtils.ts
Outdated
export function hasValidCharLength(value: string, rc?: RangeConstraints): boolean { | ||
const lowerLimitIncl = (!rc?.lowerLimitIncl || rc.lowerLimitIncl < 1) ? 1 : rc.lowerLimitIncl; | ||
const upperLimitIncl = (!rc?.upperLimitIncl || rc.upperLimitIncl > Number.MAX_SAFE_INTEGER) ? Number.MAX_SAFE_INTEGER : rc.upperLimitIncl; | ||
return lowerLimitIncl <= upperLimitIncl && value.length >= lowerLimitIncl && value.length <= upperLimitIncl; |
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.
I feel like that this should just throw an error: lowerLimitIncl <= upperLimitIncl
. If the upperLimit is lower than the lowerLimit, somebody created the RangeConstraints backwards and that'd be kind of difficult to understand what's going wrong.
Added a message condition for when the lower and upper limits are equal* |
5c15fb3
to
57c3b52
Compare
57c3b52
to
81fa32b
Compare
Beginning of a series of PRs to add a validation utility to simplify common input string validation scenarios for use in our Azure Wizard
inputBox
steps.Example of use:
See: microsoft/vscode-azurecontainerapps#582
Let me know if you think something like this would be useful :)