globject
Advanced tools
Comparing version 0.1.3 to 1.0.0
19
index.js
@@ -1,19 +0,20 @@ | ||
var match = require('minimatch'); | ||
var minimatch = require('minimatch'); | ||
var globject = function (obj) { | ||
obj = obj || {}; | ||
var globject = function (map) { | ||
map = map || {}; | ||
return function (val) { | ||
var keys = Object.keys(obj); | ||
var keys = Object.keys(map); | ||
var len = keys.length; | ||
var i = 0; | ||
var globKey; | ||
var key; | ||
for(i; i < len; i += 1) { | ||
for(var i = 0; i < len; i += 1) { | ||
key = keys[i]; | ||
if (match(val, key)){ | ||
globKey = obj[key]; | ||
break; | ||
if (minimatch(val, key)){ | ||
globKey = map[key]; | ||
break;g | ||
} | ||
@@ -20,0 +21,0 @@ } |
{ | ||
"name": "globject", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"description": "Get values by glob-like keys", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test/index.js | node_modules/.bin/tspec" | ||
"test": "node test/index.js | tap-spec" | ||
}, | ||
@@ -25,8 +25,8 @@ "repository": { | ||
"devDependencies": { | ||
"tape": "~2.3.2", | ||
"tap-spec": "~0.1.3" | ||
"tap-spec": "^1.0.1", | ||
"tape": "^3.0.3" | ||
}, | ||
"dependencies": { | ||
"minimatch": "~0.2.14" | ||
"minimatch": "^1.0.0" | ||
} | ||
} |
var globject = require('../'); | ||
var test = require('tape'); | ||
var obj = globject({ | ||
@@ -9,2 +10,3 @@ '**value': 'value', | ||
test('it partially applies the globbing function', function (t) { | ||
t.equal(typeof obj, 'function', 'applied'); | ||
@@ -15,2 +17,3 @@ t.end(); | ||
test('it gets a value from the object of globs', function (t) { | ||
t.equal(obj('value'), 'value', 'got value for value'); | ||
@@ -22,2 +25,3 @@ t.equal(obj('/index.html'), 'about.html', 'got value for index.html'); | ||
test('returns undefined if no matches found', function (t) { | ||
t.equal(obj('nothing'), undefined, 'no match for nothing'); | ||
@@ -28,5 +32,52 @@ t.end(); | ||
test('undefined routes object', function (t) { | ||
var obj = globject(); | ||
t.equal(obj('nothing'), undefined, 'no match with no routes'); | ||
t.end(); | ||
}); | ||
test('matches values with negation', function (t) { | ||
var obj1 = globject({ | ||
'!/something/**': 'not something', | ||
}); | ||
t.equal(obj1('/anything-else'), 'not something', 'matched negate single-depth route'); | ||
t.equal(obj1('/something/content'), undefined, 'does not match negate single-depth route'); | ||
var obj2 = globject({ | ||
'!/nested/*.html': 'not html', | ||
}); | ||
t.equal(obj2('/nested/image.jpg'), 'not html', 'matched negate single-depth route by extension'); | ||
t.equal(obj2('/nested/index.html'), undefined, 'no match for negated value'); | ||
t.end(); | ||
}); | ||
test('matches all routes with extension', function (t) { | ||
var routes = globject({ | ||
'**/*.html': 'index.html', | ||
'**/*.jpg': 'default.jpg' | ||
}); | ||
test('files', function (t) { | ||
t.equal(routes('some/dir/about.html'), 'index.html', 'sub directory mapped to index.html'); | ||
t.equal(routes('/some/dir/about.html'), 'index.html', 'sub directory with leading slash mapped to index.html'); | ||
t.equal(routes('/about.html'), 'index.html', 'file with leading slash mapped to index.html'); | ||
t.equal(routes('about.html'), 'index.html', 'file mapped to index.html'); | ||
t.end(); | ||
}); | ||
test('images', function (t) { | ||
t.notEqual(routes('/image.jpg'), 'index.html', 'image matching'); | ||
t.notEqual(routes('sub/dir/image.jpg'), 'index.html', 'image matching in sub directory'); | ||
t.equal(routes('/image.jpg'), 'default.jpg', 'maps any image'); | ||
t.end(); | ||
}); | ||
t.end(); | ||
}); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3839
74
0
+ Addedminimatch@1.0.0(transitive)
- Removedminimatch@0.2.14(transitive)
Updatedminimatch@^1.0.0