Skip to content

Commit

Permalink
Merge pull request #2 from kou/regist-to-register
Browse files Browse the repository at this point in the history
regist -> register
  • Loading branch information
tricknotes committed Jul 26, 2012
2 parents 03a87ee + c63241b commit 1ef778a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/json_matcher.js
Expand Up @@ -29,35 +29,35 @@ JsonMatcher.prototype.match = function(target, query) {

JsonMatcher.advancedQueries = Object.create(null);

JsonMatcher.regist = function(name, matcher) {
JsonMatcher.register = function(name, matcher) {
return this.advancedQueries[name] = matcher;
};

JsonMatcher.regist('match', JsonMatcher.prototype.match);
JsonMatcher.register('match', JsonMatcher.prototype.match);

JsonMatcher.regist('in', function(target, query) {
JsonMatcher.register('in', function(target, query) {
if (!Array.isArray(query)) {
return false;
}
return query.indexOf(target) >= 0;
});

JsonMatcher.regist('exists', function(target, query) {
JsonMatcher.register('exists', function(target, query) {
return (target != null) ^ !query;
});

JsonMatcher.regist('ne', function(target, query) {
JsonMatcher.register('ne', function(target, query) {
return target !== query;
});

JsonMatcher.regist('nin', function(target, query) {
JsonMatcher.register('nin', function(target, query) {
if (!Array.isArray(query)) {
return false;
}
return !this.in(target, query);
});

JsonMatcher.regist('contains', function(target, query) {
JsonMatcher.register('contains', function(target, query) {
var index;
if (!target || 'function' !== typeof target.indexOf) {
return false;
Expand All @@ -80,7 +80,7 @@ JsonMatcher.regist('contains', function(target, query) {
}
});

JsonMatcher.regist('regexp', function() {
JsonMatcher.register('regexp', function() {
var cache;
var initializeCache = function() {
cache = Object.create(null);
Expand All @@ -95,7 +95,7 @@ JsonMatcher.regist('regexp', function() {
};
}());

JsonMatcher.regist('or', function(target, query) {
JsonMatcher.register('or', function(target, query) {
var i, length;
for (i = 0, length = query.length; i < length; i++) {
if (this.match(target, query[i])) {
Expand All @@ -105,7 +105,7 @@ JsonMatcher.regist('or', function(target, query) {
return false;
});

JsonMatcher.regist('and', function(target, query) {
JsonMatcher.register('and', function(target, query) {
var i, length;
for (i = 0, length = query.length; i < length; i++) {
if (!this.match(target, query[i])) {
Expand All @@ -118,7 +118,7 @@ JsonMatcher.regist('and', function(target, query) {
/*
Example for adding custom matcher.
> // 'function' === typeof matcher
> JsonMatcher.regist('custom', matcher);
> JsonMatcher.register('custom', matcher);
*/

module.exports = JsonMatcher;

0 comments on commit 1ef778a

Please sign in to comment.