@orion-js/schema
Advanced tools
Comparing version 0.19.0 to 0.19.2
@@ -7,39 +7,8 @@ 'use strict'; | ||
exports.default = function (schema, path) { | ||
if ((0, _isNil2.default)(schema)) { | ||
throw new Error('You need to pass a schema'); | ||
} | ||
return dotGet({ type: schema }, path); | ||
}; | ||
var _dotGetSchema = require('./validateKey/dotGetSchema'); | ||
var _isPlainObject = require('lodash/isPlainObject'); | ||
var _dotGetSchema2 = _interopRequireDefault(_dotGetSchema); | ||
var _isPlainObject2 = _interopRequireDefault(_isPlainObject); | ||
var _isNil = require('lodash/isNil'); | ||
var _isNil2 = _interopRequireDefault(_isNil); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var dotGet = function dotGet(object, path) { | ||
if (path === '') return object; | ||
var pathParts = path.split('.'); | ||
var first = pathParts.shift(); | ||
var remainingPath = pathParts.join('.'); | ||
var levelObject = object.type; | ||
if (first === '$' || /^[0-9]+$/.test(first)) { | ||
return dotGet({ type: levelObject[0] }, remainingPath); | ||
} else if ((0, _isPlainObject2.default)(levelObject[first])) { | ||
return dotGet(levelObject[first], remainingPath); | ||
} | ||
if (levelObject === 'blackbox') { | ||
return { type: 'blackbox', optional: true }; | ||
} | ||
return null; | ||
}; | ||
exports.default = _dotGetSchema2.default; |
@@ -33,2 +33,3 @@ 'use strict'; | ||
test('return no error when the value is correct', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { | ||
var info; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
@@ -38,6 +39,8 @@ while (1) { | ||
case 0: | ||
expect(_string2.default.validate('')).toBeFalsy(); | ||
info = { currentSchema: { optional: true } }; | ||
expect(_string2.default.validate('', info)).toBeFalsy(); | ||
expect(_string2.default.validate('Nicolás')).toBeFalsy(); | ||
case 2: | ||
case 3: | ||
case 'end': | ||
@@ -44,0 +47,0 @@ return _context2.stop(); |
@@ -46,3 +46,3 @@ 'use strict'; | ||
error: 'validationError', | ||
message: message, | ||
message: 'Validation Error', | ||
validationErrors: validationErrors | ||
@@ -49,0 +49,0 @@ }; |
{ | ||
"name": "@orion-js/schema", | ||
"version": "0.19.0", | ||
"version": "0.19.2", | ||
"main": "index.js", | ||
@@ -27,3 +27,3 @@ "author": "nicolaslopezj", | ||
}, | ||
"gitHead": "60cee769637a982f7b0a95554befeff79def9b26" | ||
"gitHead": "b87ae98c03c9748afa682876871718f30028a198" | ||
} |
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
195203
54
4974