Skip to content

Commit 8a73b3a

Browse files
authored
Merge pull request #13 from lucono/interface_methods_for_is_api
Interface methods for `is` API (issue #12).
2 parents 3e04cd9 + 30dcdb0 commit 8a73b3a

6 files changed

Lines changed: 62 additions & 40 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: node_js
22
node_js:
33
- "0.10"
44
- "0.12"
5-
- "node"
5+
- "6.9.2"
66
before_script:
77
- export CHROME_BIN=chromium-browser
88
- npm install -g grunt-cli

project/xtypejs/dist/xtype.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22
*/
33

44
/**
@@ -34,7 +34,7 @@
3434
*/
3535

3636
var LIB_NAME = 'xtype',
37-
LIB_VERSION = '0.6.1',
37+
LIB_VERSION = '0.7.0',
3838

3939
TYPE_DELIMITER_DEFAULT_PATTERN = '[|, ]',
4040
NAME_SCHEME_DEFAULT_OPTION_VALUE = 'default',
@@ -502,6 +502,23 @@
502502
clearTypeListStringCache();
503503
}
504504

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+
505522
/**
506523
* Defines the typeId property and associated type check
507524
* and interface methods for the specified type.
@@ -530,22 +547,14 @@
530547

531548
hostObj[typeMethodName] = typeCheckFunction;
532549

533-
hostObj.not = (hostObj.not || newObj());
534550
hostObj.not[typeMethodName] = function(value) {
535551
return !typeCheckFunction(value);
536552
};
537553

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);
549558
}
550559

551560
/**
@@ -570,9 +579,9 @@
570579
/**
571580
* Creates an interface function using the specified parameters.
572581
*/
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)
576585
: isArray(values) ? values
577586
: [values]);
578587

@@ -581,7 +590,7 @@
581590
valueIndex;
582591

583592
for (valueIndex = 0; valueIndex < values.length; valueIndex++) {
584-
if (delegateFunction(values[valueIndex])) {
593+
if (delegateFunction(values[valueIndex], types)) {
585594
trueResult = true;
586595
} else {
587596
falseResult = true;
@@ -820,6 +829,8 @@
820829
objToStringToNameMapping['[object ' + objectType + ']'] = objectType.toLowerCase();
821830
});
822831

832+
defineInterfacePackagesAndMethods(moduleExport);
833+
823834
objKeys(TYPE_VALUE_MAPPING).forEach(function(typeName) {
824835
defineType(typeName, TYPE_VALUE_MAPPING[typeName], moduleExport);
825836
});

project/xtypejs/dist/xtype.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project/xtypejs/dist/xtype.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project/xtypejs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "xtypejs",
3-
"version": "0.6.1",
3+
"version": "0.7.0",
44
"description": "Elegant, highly efficient data validation for JavaScript.",
5-
"main": "dist/xtype",
5+
"main": "dist/xtype.js",
66
"keywords": [
77
"type",
88
"xtype",

0 commit comments

Comments
 (0)