Skip to content

Commit

Permalink
refactor: checking string lengths now working under better logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Wiebe committed Jan 14, 2020
1 parent 73f2acf commit 4663fbb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,14 @@ export function areSameAddress(a: string, b: string) {
export function checkStringLength(
value: string,
variableName: string,
opts?: { minLength: number | undefined; maxLength: number }
opts: { minLength?: number; maxLength: number } = { maxLength: 32 }
) {
const minLength = opts && opts.minLength != undefined ? opts.minLength : 0;
const maxLength = opts ? opts.maxLength : 32;
const { minLength = 0, maxLength } = opts;
if (value.length < minLength || value.length > maxLength) {
throw new PolymathError({
code: ErrorCode.ProcedureValidationError,
message: `You must provide a valid ${variableName} ${
opts && opts.minLength != undefined
? `between ${minLength} and ${maxLength}`
: `up to ${maxLength}`
opts.minLength != undefined ? `between ${minLength} and ${maxLength}` : `up to ${maxLength}`
} characters long`,
});
}
Expand Down

0 comments on commit 4663fbb

Please sign in to comment.