Skip to content

Commit

Permalink
fix: added missing language passthrough for messages regarding a fiel…
Browse files Browse the repository at this point in the history
…ds optionality
  • Loading branch information
BlvckBytes committed Dec 25, 2021
1 parent 8aeb403 commit d1b3aad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ctor-ensure",
"author": "BlvckBytes",
"version": "1.0.17",
"version": "1.0.18",
"license": "GPL-3.0",
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions src/ctor-ensure.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const META_KEY_BLOCKED_FIELDS = 'CTOR_ENSURE:BLOCKED_FIELDS';
* Check wheter or not a value is conforming to it's optionality state
* @param value Value to check
* @param optionality Optionality-level to check against
* @param templateLang Language to be used for messages
* @returns The error description if any, null if it passed and a
* boolean, whether or not further validation is necessary
*/
const checkOptionality = (value: any, optionality: Optionality): [string | null, boolean] => {
const checkOptionality = (value: any, optionality: Optionality, templateLang: string): [string | null, boolean] => {
// Account for optionality
switch (optionality) {
case Optionality.NULLABLE:
Expand Down Expand Up @@ -59,7 +60,7 @@ const checkOptionality = (value: any, optionality: Optionality): [string | null,
const omittable = optionality === Optionality.OMITTABLE;
return [template('OPTIONALITY', {
nonNull: !nullable, nonOmit: !omittable, both: !nullable && !omittable,
}), false];
}, {}, templateLang), false];
};

/**
Expand Down Expand Up @@ -95,7 +96,7 @@ const validateCtorArgs = (
const currArg = args[currControl.ctorInd];

// Check optionality
const [optErr, needsValidation] = checkOptionality(currArg, currControl.optional);
const [optErr, needsValidation] = checkOptionality(currArg, currControl.optional, templateLang);

// Didn't pass optionality, raise error and continue
// to next validated arg
Expand Down

0 comments on commit d1b3aad

Please sign in to comment.