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

Function assertProp

static/vuejs/vue.esm.js:1338–1386  ·  view source on GitHub ↗

* Assert whether a prop is valid.

(
  prop,
  name,
  value,
  vm,
  absent
)

Source from the content-addressed store, hash-verified

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