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

Function assertProp

static/vuejs/vue.runtime.common.js:1336–1384  ·  view source on GitHub ↗

* Assert whether a prop is valid.

(
  prop,
  name,
  value,
  vm,
  absent
)

Source from the content-addressed store, hash-verified

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