Permalink
Browse files

Stop using instanceof Array, in favor of Array.isArray

  • Loading branch information...
1 parent f9e609a commit df9016ac84e5e855ea1bf62d32d83a4dc04cf3b1 @tdegrunt committed Jun 20, 2016
Showing with 13 additions and 13 deletions.
  1. +13 −13 lib/attribute.js
View
26 lib/attribute.js
@@ -44,7 +44,7 @@ validators.type = function validateType (instance, schema, options, ctx) {
return null;
}
var result = new ValidatorResult(instance, schema, options, ctx);
- var types = (schema.type instanceof Array) ? schema.type : [schema.type];
+ var types = Array.isArray(schema.type) ? schema.type : [schema.type];
if (!types.some(this.testType.bind(this, instance, schema, options, ctx))) {
var list = types.map(function (v) {
return v.id && ('<' + v.id + '>') || (v+'');
@@ -76,7 +76,7 @@ validators.anyOf = function validateAnyOf (instance, schema, options, ctx) {
return null;
}
var result = new ValidatorResult(instance, schema, options, ctx);
- if (!(schema.anyOf instanceof Array)){
+ if (!Array.isArray(schema.anyOf)){
throw new SchemaError("anyOf must be an array");
}
if (!schema.anyOf.some(testSchema.bind(this, instance, options, ctx))) {
@@ -105,7 +105,7 @@ validators.allOf = function validateAllOf (instance, schema, options, ctx) {
if (instance === undefined) {
return null;
}
- if (!(schema.allOf instanceof Array)){
+ if (!Array.isArray(schema.allOf)){
throw new SchemaError("allOf must be an array");
}
var result = new ValidatorResult(instance, schema, options, ctx);
@@ -138,7 +138,7 @@ validators.oneOf = function validateOneOf (instance, schema, options, ctx) {
if (instance === undefined) {
return null;
}
- if (!(schema.oneOf instanceof Array)){
+ if (!Array.isArray(schema.oneOf)){
throw new SchemaError("oneOf must be an array");
}
var result = new ValidatorResult(instance, schema, options, ctx);
@@ -311,7 +311,7 @@ validators.maxProperties = function validateMaxProperties (instance, schema, opt
* @return {String|null|ValidatorResult}
*/
validators.items = function validateItems (instance, schema, options, ctx) {
- if (!(instance instanceof Array)) {
+ if (!Array.isArray(instance)) {
return null;
}
var self = this;
@@ -320,7 +320,7 @@ validators.items = function validateItems (instance, schema, options, ctx) {
return result;
}
instance.every(function (value, i) {
- var items = (schema.items instanceof Array) ? (schema.items[i] || schema.additionalItems) : schema.items;
+ var items = Array.isArray(schema.items) ? (schema.items[i] || schema.additionalItems) : schema.items;
if (items === undefined) {
return true;
}
@@ -579,7 +579,7 @@ validators.maxLength = function validateMaxLength (instance, schema, options, ct
* @return {String|null}
*/
validators.minItems = function validateMinItems (instance, schema, options, ctx) {
- if (!(instance instanceof Array)) {
+ if (!Array.isArray(instance)) {
return null;
}
var result = new ValidatorResult(instance, schema, options, ctx);
@@ -600,7 +600,7 @@ validators.minItems = function validateMinItems (instance, schema, options, ctx)
* @return {String|null}
*/
validators.maxItems = function validateMaxItems (instance, schema, options, ctx) {
- if (!(instance instanceof Array)) {
+ if (!Array.isArray(instance)) {
return null;
}
var result = new ValidatorResult(instance, schema, options, ctx);
@@ -624,7 +624,7 @@ validators.maxItems = function validateMaxItems (instance, schema, options, ctx)
*/
validators.uniqueItems = function validateUniqueItems (instance, schema, options, ctx) {
var result = new ValidatorResult(instance, schema, options, ctx);
- if (!(instance instanceof Array)) {
+ if (!Array.isArray(instance)) {
return result;
}
function testArrays (v, i, a) {
@@ -666,7 +666,7 @@ function testArrays (v, i, a) {
* @return {String|null}
*/
validators.uniqueItems = function validateUniqueItems (instance, schema, options, ctx) {
- if (!(instance instanceof Array)) {
+ if (!Array.isArray(instance)) {
return null;
}
var result = new ValidatorResult(instance, schema, options, ctx);
@@ -701,7 +701,7 @@ validators.dependencies = function validateDependencies (instance, schema, optio
if (typeof dep == 'string') {
dep = [dep];
}
- if (dep instanceof Array) {
+ if (Array.isArray(dep)) {
dep.forEach(function (prop) {
if (instance[prop] === undefined) {
result.addError({
@@ -737,7 +737,7 @@ validators.dependencies = function validateDependencies (instance, schema, optio
* @return {ValidatorResult|null}
*/
validators['enum'] = function validateEnum (instance, schema, options, ctx) {
- if (!(schema['enum'] instanceof Array)) {
+ if (!Array.isArray(schema['enum'])) {
throw new SchemaError("enum expects an array", schema);
}
if (instance === undefined) {
@@ -768,7 +768,7 @@ validators.not = validators.disallow = function validateNot (instance, schema, o
var result = new ValidatorResult(instance, schema, options, ctx);
var notTypes = schema.not || schema.disallow;
if(!notTypes) return null;
- if(!(notTypes instanceof Array)) notTypes=[notTypes];
+ if(!Array.isArray(notTypes)) notTypes=[notTypes];
notTypes.forEach(function (type) {
if (self.testType(instance, schema, options, ctx, type)) {
var schemaId = type && type.id && ('<' + type.id + '>') || type;

0 comments on commit df9016a

Please sign in to comment.