alexa-ssml
Version:
JSX for Alexa Skills Kit SSML
50 lines (35 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = validateProps;
var _tv = require('tv4');
var _tv2 = _interopRequireDefault(_tv);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
/**
* Validates properties against a schema
* @param {Object} props
* @param {Object} schema
* @return {Object} validated props
*/
function validateProps(props, schema) {
var _ref = props || {};
var children = _ref.children;
var itemProps = _objectWithoutProperties(_ref, ['children']); // TODO add child count validation too?
var _tv4$validateResult = _tv2.default.validateResult(itemProps, schema, false, true);
var error = _tv4$validateResult.error;
if (error) {
var dataPath = error.dataPath;
var srcPath = error.srcPath;
var message = error.message;
if (dataPath) {
throw new Error('Unknown property: ' + dataPath.slice(1));
}
if (srcPath) {
throw new Error('Invalid value for property ' + srcPath.slice(1) + ': ' + message);
}
throw new Error(message);
}
return itemProps;
}