| 2495 | }; |
| 2496 | |
| 2497 | function validate_builder_default(name, value, entity) { |
| 2498 | |
| 2499 | var type = typeof(value); |
| 2500 | |
| 2501 | if (entity.type === 12) |
| 2502 | return value != null && type === 'object' && !(value instanceof Array); |
| 2503 | |
| 2504 | if (entity.type === 11) |
| 2505 | return type === 'number'; |
| 2506 | |
| 2507 | // Enum + KeyValue + Custom (8+9+10) |
| 2508 | if (entity.type > 7) |
| 2509 | return value !== undefined; |
| 2510 | |
| 2511 | switch (entity.subtype) { |
| 2512 | case 'uid': |
| 2513 | return value.isUID(); |
| 2514 | case 'zip': |
| 2515 | return value.isZIP(); |
| 2516 | case 'email': |
| 2517 | return value.isEmail(); |
| 2518 | case 'json': |
| 2519 | return value.isJSON(); |
| 2520 | case 'url': |
| 2521 | return value.isURL(); |
| 2522 | case 'phone': |
| 2523 | return value.isPhone(); |
| 2524 | case 'base64': |
| 2525 | return value.isBase64(); |
| 2526 | } |
| 2527 | |
| 2528 | if (type === 'number') |
| 2529 | return value > 0; |
| 2530 | |
| 2531 | if (type === 'string' || value instanceof Array) |
| 2532 | return value.length > 0; |
| 2533 | |
| 2534 | if (type === 'boolean') |
| 2535 | return value === true; |
| 2536 | |
| 2537 | if (value == null) |
| 2538 | return false; |
| 2539 | |
| 2540 | if (value instanceof Date) |
| 2541 | return value.toString()[0] !== 'I'; // Invalid Date |
| 2542 | |
| 2543 | return true; |
| 2544 | } |
| 2545 | |
| 2546 | exports.validate_builder = function(model, error, schema, path, index, fields, pluspath) { |
| 2547 | |