|
1 | | -/** @license | xtypejs v0.6.1 | (c) 2015, Lucas Ononiwu | MIT license, xtype.js.org/license.txt |
| 1 | +/** @license | xtypejs v0.7.0 | (c) 2015, Lucas Ononiwu | MIT license, xtype.js.org/license.txt |
2 | 2 | */ |
3 | 3 |
|
4 | 4 | /** |
|
34 | 34 | */ |
35 | 35 |
|
36 | 36 | var LIB_NAME = 'xtype', |
37 | | - LIB_VERSION = '0.6.1', |
| 37 | + LIB_VERSION = '0.7.0', |
38 | 38 |
|
39 | 39 | TYPE_DELIMITER_DEFAULT_PATTERN = '[|, ]', |
40 | 40 | NAME_SCHEME_DEFAULT_OPTION_VALUE = 'default', |
|
502 | 502 | clearTypeListStringCache(); |
503 | 503 | } |
504 | 504 |
|
| 505 | + function defineInterfacePackagesAndMethods(hostObj) { |
| 506 | + hostObj.not = newObj(); |
| 507 | + hostObj.any = newObj(); |
| 508 | + hostObj.all = newObj(); |
| 509 | + hostObj.some = newObj(); |
| 510 | + hostObj.none = newObj(); |
| 511 | + |
| 512 | + hostObj.not.is = function(value, types) { |
| 513 | + return !isType(value, types); |
| 514 | + }; |
| 515 | + |
| 516 | + hostObj.any.is = getInterfaceFunction(isType, true, true, undefined, true); |
| 517 | + hostObj.all.is = getInterfaceFunction(isType, true, undefined, true, false); |
| 518 | + hostObj.some.is = getInterfaceFunction(isType, true, true, true, true); |
| 519 | + hostObj.none.is = getInterfaceFunction(isType, true, true, undefined, false); |
| 520 | + } |
| 521 | + |
505 | 522 | /** |
506 | 523 | * Defines the typeId property and associated type check |
507 | 524 | * and interface methods for the specified type. |
|
530 | 547 |
|
531 | 548 | hostObj[typeMethodName] = typeCheckFunction; |
532 | 549 |
|
533 | | - hostObj.not = (hostObj.not || newObj()); |
534 | 550 | hostObj.not[typeMethodName] = function(value) { |
535 | 551 | return !typeCheckFunction(value); |
536 | 552 | }; |
537 | 553 |
|
538 | | - hostObj.any = (hostObj.any || newObj()); |
539 | | - hostObj.any[typeMethodName] = getInterfaceFunction(typeCheckFunction, true, undefined, true); |
540 | | - |
541 | | - hostObj.all = (hostObj.all || newObj()); |
542 | | - hostObj.all[typeMethodName] = getInterfaceFunction(typeCheckFunction, undefined, true, false); |
543 | | - |
544 | | - hostObj.some = (hostObj.some || newObj()); |
545 | | - hostObj.some[typeMethodName] = getInterfaceFunction(typeCheckFunction, true, true, true); |
546 | | - |
547 | | - hostObj.none = (hostObj.none || newObj()); |
548 | | - hostObj.none[typeMethodName] = getInterfaceFunction(typeCheckFunction, true, undefined, false); |
| 554 | + hostObj.any[typeMethodName] = getInterfaceFunction(typeCheckFunction, false, true, undefined, true); |
| 555 | + hostObj.all[typeMethodName] = getInterfaceFunction(typeCheckFunction, false, undefined, true, false); |
| 556 | + hostObj.some[typeMethodName] = getInterfaceFunction(typeCheckFunction, false, true, true, true); |
| 557 | + hostObj.none[typeMethodName] = getInterfaceFunction(typeCheckFunction, false, true, undefined, false); |
549 | 558 | } |
550 | 559 |
|
551 | 560 | /** |
|
570 | 579 | /** |
571 | 580 | * Creates an interface function using the specified parameters. |
572 | 581 | */ |
573 | | - function getInterfaceFunction(delegateFunction, trueCondition, falseCondition, terminationResult) { |
574 | | - return function(values) { |
575 | | - values = (arguments.length > 1 ? arraySlice.call(arguments) |
| 582 | + function getInterfaceFunction(delegateFunction, withTypes, trueCondition, falseCondition, terminationResult) { |
| 583 | + return function(values, types) { |
| 584 | + values = (!withTypes && arguments.length > 1 ? arraySlice.call(arguments) |
576 | 585 | : isArray(values) ? values |
577 | 586 | : [values]); |
578 | 587 |
|
|
581 | 590 | valueIndex; |
582 | 591 |
|
583 | 592 | for (valueIndex = 0; valueIndex < values.length; valueIndex++) { |
584 | | - if (delegateFunction(values[valueIndex])) { |
| 593 | + if (delegateFunction(values[valueIndex], types)) { |
585 | 594 | trueResult = true; |
586 | 595 | } else { |
587 | 596 | falseResult = true; |
|
820 | 829 | objToStringToNameMapping['[object ' + objectType + ']'] = objectType.toLowerCase(); |
821 | 830 | }); |
822 | 831 |
|
| 832 | + defineInterfacePackagesAndMethods(moduleExport); |
| 833 | + |
823 | 834 | objKeys(TYPE_VALUE_MAPPING).forEach(function(typeName) { |
824 | 835 | defineType(typeName, TYPE_VALUE_MAPPING[typeName], moduleExport); |
825 | 836 | }); |
|
0 commit comments