leaf-converter
Advanced tools
Comparing version 1.9.0 to 1.9.1
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="1.9.1"></a> | ||
## [1.9.1](https://github.com/forsigner/leaf-converter/compare/v1.9.0...v1.9.1) (2018-02-01) | ||
<a name="1.9.0"></a> | ||
@@ -7,0 +12,0 @@ # [1.9.0](https://github.com/forsigner/leaf-converter/compare/v1.8.2...v1.9.0) (2018-02-01) |
'use strict'; | ||
/** | ||
* JS Object to JSON Schema | ||
*/ | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var keywords = ['maxLength', 'minLength', 'pattern', 'enum', 'minimum', 'maximum', 'required', 'maxProperties', 'minProperties', 'additionalProperties', 'minItems', 'maxItems', 'uniqueItems']; | ||
var _ = require('lodash'); | ||
var _ = require('lodash'); | ||
var _require = require('../constant'), | ||
keywords = _require.keywords, | ||
numKeywords = _require.numKeywords; | ||
module.exports = objectToSchema; | ||
@@ -260,4 +260,3 @@ | ||
function isNumKeyword(keyword) { | ||
var numKeywords = ['maxLength', 'minLength', 'minimum', 'maximum', 'maxProperties', 'minProperties', 'minItems', 'maxItems']; | ||
return numKeywords.indexOf(keyword) > -1; | ||
} |
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _require = require('./constant'), | ||
keywords = _require.keywords; | ||
function clone(source) { | ||
@@ -11,30 +16,52 @@ return JSON.parse(JSON.stringify(source)); | ||
} else if (schema.type === 'object') { | ||
var properties = schema.properties; | ||
var _ret = function () { | ||
var properties = schema.properties; | ||
if (!properties) { | ||
return {}; | ||
} | ||
if (!properties) { | ||
return { | ||
v: {} | ||
}; | ||
} | ||
for (var key in properties) { | ||
if (!properties.hasOwnProperty(key)) continue; | ||
var _loop = function _loop(key) { | ||
if (!properties.hasOwnProperty(key)) return 'continue'; | ||
if (comment) { | ||
var _comment = [null, null]; | ||
if (properties[key].description) { | ||
_comment[1] = ['// ' + properties[key].description]; | ||
if (comment) { | ||
var _comment = [null, null]; | ||
if (properties[key].description) { | ||
_comment[1] = ['// ' + properties[key].description]; | ||
} | ||
var tmp = ['`/**']; | ||
keywords.forEach(function (word) { | ||
if (!properties[key][word]) return; | ||
tmp.push('* @' + word + ' ' + properties[key][word]); | ||
}); | ||
tmp.push('*/`'); | ||
if (tmp.length > 2) { | ||
_comment[0] = [tmp.join('\n')]; | ||
} | ||
properties['// ' + key] = _comment; | ||
} | ||
if (properties[key].maxLength) { | ||
_comment[0] = ['/**\n * @maxLength ' + properties[key].maxLength + '\n */']; | ||
properties[key] = convert(properties[key], comment); | ||
if (typeof properties[key] === 'undefined') { | ||
delete properties[key]; | ||
} | ||
properties['// ' + key] = _comment; | ||
} | ||
}; | ||
properties[key] = convert(properties[key], comment); | ||
if (typeof properties[key] === 'undefined') { | ||
delete properties[key]; | ||
for (var key in properties) { | ||
var _ret2 = _loop(key); | ||
if (_ret2 === 'continue') continue; | ||
} | ||
} | ||
return properties; | ||
return { | ||
v: properties | ||
}; | ||
}(); | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} else if (schema.type === 'array') { | ||
@@ -41,0 +68,0 @@ if (!schema.items) { |
{ | ||
"name": "leaf-converter", | ||
"description": "", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "author": { |
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
35609
27
862