json-schema-defaults
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "json-schema-defaults", | ||
"main": "index.js", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"authors": [ | ||
@@ -6,0 +6,0 @@ "Chute <hello@getchute.com>" |
@@ -0,1 +1,7 @@ | ||
<a name="0.2.0"></a> | ||
## 0.2.0 (2016-08-05) | ||
* array defaults ([7d98ffb6](https://github.com/chute/json-schema-defaults/commit/7d98ffb634507816bc70dd9551785cae7e32ef4f)) | ||
<a name="0.1.1"></a> | ||
@@ -2,0 +8,0 @@ ### 0.1.1 (2015-03-17) |
@@ -168,4 +168,33 @@ (function(root, factory) { | ||
if (!schema.items) { return []; } | ||
return [defaults(schema.items, definitions)]; | ||
// minimum item count | ||
var ct = schema.minItems || 0; | ||
// tuple-typed arrays | ||
if (schema.items.constructor === Array) { | ||
var values = schema.items.map(function (item) { | ||
return defaults(item, definitions); | ||
}); | ||
// remove undefined items at the end (unless required by minItems) | ||
for (var i = values.length - 1; i >= 0; i--) { | ||
if (typeof values[i] !== 'undefined') { | ||
break; | ||
} | ||
if (i + 1 > ct) { | ||
values.pop(); | ||
} | ||
} | ||
return values; | ||
} | ||
// object-typed arrays | ||
var value = defaults(schema.items, definitions); | ||
if (typeof value === 'undefined') { | ||
return []; | ||
} else { | ||
var values = []; | ||
for (var i = 0; i < Math.max(1, ct); i++) { | ||
values.push(value); | ||
} | ||
return values; | ||
} | ||
} | ||
@@ -172,0 +201,0 @@ |
{ | ||
"name": "json-schema-defaults", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Generate JSON object from default values in JSON Schema", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/chute/grunt-json-schema-defaults", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14175
296