Skip to content

Commit

Permalink
fix: 'json' param type validator to support array-structured values a…
Browse files Browse the repository at this point in the history
…s well.
  • Loading branch information
tmilar committed Mar 27, 2020
1 parent 5a9a249 commit bd43dfb
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,20 @@ export const json: ArgumentType<any> = {
},
/**
* Check if argument value is of type "json"
* "json" validation succeeds if it is of "object" map-like {} type
* - this excludes 'null', function, date, regexp, etc./
* "json" validation succeeds if it is of "object map"-like structure or of "array" structure
* ie. this excludes 'null', function, numbers, date, regexp, etc.
*
* @param argName {string} argument's name - used for context in case of error.
* @param value {any} argument's value to validate.
*
* @throws BDLR301 if value is not of type "json"
*/
validate: (argName: string, value: any): void => {
const valueTypeString = Object.prototype.toString.call(value);

const isJsonValue =
Object.prototype.toString.call(value) === "[object Object]";
valueTypeString === "[object Object]" ||
valueTypeString === "[object Array]";

if (!isJsonValue) {
throw new BuidlerError(ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, {
Expand Down

0 comments on commit bd43dfb

Please sign in to comment.