MCPcopy Create free account
hub / github.com/TruthHun/BookStack / assertProp

Function assertProp

static/vuejs/vue.runtime.js:1340–1388  ·  view source on GitHub ↗

* Assert whether a prop is valid.

(
  prop,
  name,
  value,
  vm,
  absent
)

Source from the content-addressed store, hash-verified

1338 * Assert whether a prop is valid.
1339 */
1340function assertProp (
1341 prop,
1342 name,
1343 value,
1344 vm,
1345 absent
1346) {
1347 if (prop.required && absent) {
1348 warn(
1349 'Missing required prop: "' + name + '"',
1350 vm
1351 );
1352 return
1353 }
1354 if (value == null && !prop.required) {
1355 return
1356 }
1357 var type = prop.type;
1358 var valid = !type || type === true;
1359 var expectedTypes = [];
1360 if (type) {
1361 if (!Array.isArray(type)) {
1362 type = [type];
1363 }
1364 for (var i = 0; i < type.length && !valid; i++) {
1365 var assertedType = assertType(value, type[i]);
1366 expectedTypes.push(assertedType.expectedType || '');
1367 valid = assertedType.valid;
1368 }
1369 }
1370 if (!valid) {
1371 warn(
1372 'Invalid prop: type check failed for prop "' + name + '".' +
1373 ' Expected ' + expectedTypes.map(capitalize).join(', ') +
1374 ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.',
1375 vm
1376 );
1377 return
1378 }
1379 var validator = prop.validator;
1380 if (validator) {
1381 if (!validator(value)) {
1382 warn(
1383 'Invalid prop: custom validator check failed for prop "' + name + '".',
1384 vm
1385 );
1386 }
1387 }
1388}
1389
1390/**
1391 * Assert the type of a value

Callers 1

validatePropFunction · 0.70

Calls 3

validatorFunction · 0.85
assertTypeFunction · 0.70
warnFunction · 0.50

Tested by

no test coverage detected