wildcard
Advanced tools
Comparing version 0.1.5 to 1.0.0
@@ -5,3 +5,3 @@ { | ||
"description": "Wildcard matching tools", | ||
"version": "0.1.5", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "wildcard", |
13
index.js
/* jshint node: true */ | ||
'use strict'; | ||
var reSep = /[\/\.]/; | ||
/** | ||
@@ -33,4 +31,5 @@ # wildcard | ||
function WildcardMatcher(text) { | ||
this.parts = (text || '').split(reSep); | ||
function WildcardMatcher(text, separator) { | ||
this.separator = separator; | ||
this.parts = (text || '').split(separator); | ||
} | ||
@@ -46,3 +45,3 @@ | ||
if (typeof input == 'string' || input instanceof String) { | ||
testParts = (input || '').split(reSep); | ||
testParts = (input || '').split(this.separator); | ||
for (ii = 0; matches && ii < partsCount; ii++) { | ||
@@ -74,4 +73,4 @@ matches = parts[ii] === '*' || parts[ii] === testParts[ii]; | ||
module.exports = function(text, test) { | ||
var matcher = new WildcardMatcher(text); | ||
module.exports = function(text, test, separator) { | ||
var matcher = new WildcardMatcher(text, separator || /[\/\.]/); | ||
if (typeof test != 'undefined') { | ||
@@ -78,0 +77,0 @@ return matcher.match(test); |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.1.5", | ||
"version": "1.0.0", | ||
"dependencies": {}, | ||
@@ -12,0 +12,0 @@ "devDependencies": { |
@@ -8,2 +8,8 @@ var test = require('tape'), | ||
'a.b.d' | ||
], | ||
testdataSep = [ | ||
'a:b:c', | ||
'a:b', | ||
'a', | ||
'a:b:d' | ||
]; | ||
@@ -18,2 +24,11 @@ | ||
t.equal(wildcard('b.*.d', testdata).length, 0); | ||
}); | ||
}); | ||
test('array result with separator matching tests', function(t) { | ||
t.plan(4); | ||
t.equal(wildcard('a:*', testdataSep, ':').length, 4, '4 matches found'); | ||
t.equal(wildcard('a:b:*', testdataSep, ':').length, 3, '3 matches found'); | ||
t.equal(wildcard('a:*:c', testdataSep, ':').length, 1); | ||
t.equal(wildcard('b:*:d', testdataSep, ':').length, 0); | ||
}); |
@@ -8,4 +8,10 @@ var wildcard = require('../'), | ||
'a.b.d' : {} | ||
}, | ||
testdataSep = { | ||
'a:b:c' : {}, | ||
'a:b' : {}, | ||
'a' : {}, | ||
'a:b:d' : {} | ||
}; | ||
test('object result matching tests', function(t) { | ||
@@ -23,2 +29,13 @@ t.test('should return 4 matches for a.*', function(t) { | ||
t.test('should return 4 matches for a:*', function(t) { | ||
var matches = wildcard('a:*', testdataSep, ':'); | ||
t.plan(4); | ||
t.ok(matches['a:b:c']); | ||
t.ok(matches['a:b']); | ||
t.ok(matches['a']); | ||
t.ok(matches['a:b:d']); | ||
t.end(); | ||
}); | ||
t.test('should return 3 matches for a.b.*', function(t) { | ||
@@ -35,5 +52,16 @@ var matches = wildcard('a.b.*', testdata); | ||
t.test('should return 3 matches for a:b:*', function(t) { | ||
var matches = wildcard('a:b:*', testdataSep, ':'); | ||
t.plan(4); | ||
t.ok(matches['a:b:c']); | ||
t.ok(matches['a:b']); | ||
t.notOk(matches['a']); | ||
t.ok(matches['a:b:d']); | ||
t.end(); | ||
}); | ||
t.test('should return 1 matches for a.*.c', function(t) { | ||
var matches = wildcard('a.*.c', testdata); | ||
t.plan(4); | ||
@@ -46,6 +74,17 @@ t.ok(matches['a.b.c']); | ||
}); | ||
t.test('should return 1 matches for a:*:c', function(t) { | ||
var matches = wildcard('a:*:c', testdataSep, ':'); | ||
t.plan(4); | ||
t.ok(matches['a:b:c']); | ||
t.notOk(matches['a:b']); | ||
t.notOk(matches['a']); | ||
t.notOk(matches['a:b:d']); | ||
t.end(); | ||
}); | ||
t.test('should return 0 matches for b.*.d', function(t) { | ||
var matches = wildcard('b.*.d', testdata); | ||
t.plan(4); | ||
@@ -59,3 +98,14 @@ t.notOk(matches['a.b.c']); | ||
t.test('should return 0 matches for b:*:d', function(t) { | ||
var matches = wildcard('b:*:d', testdataSep, ':'); | ||
t.plan(4); | ||
t.notOk(matches['a:b:c']); | ||
t.notOk(matches['a:b']); | ||
t.notOk(matches['a']); | ||
t.notOk(matches['a:b:d']); | ||
t.end(); | ||
}); | ||
t.end(); | ||
}); | ||
}); |
var test = require('tape'), | ||
wildcard = require('../'); | ||
test('general wild card matching tests', function(t) { | ||
@@ -12,2 +12,12 @@ | ||
t.notOk(wildcard('a.*.c', 'a.b'), 'a.*.c should not match a.b'); | ||
}); | ||
}); | ||
test('general wild card with separator matching tests', function(t) { | ||
t.plan(5); | ||
t.ok(wildcard('foo:*', 'foo:bar', ':'), 'foo:* should match foo:bar'); | ||
t.ok(wildcard('foo:*', 'foo', ':'), 'foo:* should match foo'); | ||
t.notOk(wildcard('foo:*', 'bar', ':'), 'foo:* should not match bar'); | ||
t.ok(wildcard('a:*:c', 'a:b:c', ':'), 'a:*:c should match a:b:c'); | ||
t.notOk(wildcard('a:*:c', 'a:b', ':'), 'a:*:c should not match a:b'); | ||
}); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10568
241
0