Skip to content

Commit

Permalink
only test type against meta keys that exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestopcontinues committed Aug 30, 2014
1 parent 60f6aef commit 0c2b094
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.1.1 - August 30, 2014
-----------------------
* only test type against meta keys that exist

0.1.0 - August 30, 2014
-----------------------
* works on files matching pattern
Expand Down
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ function plugin(matchers) {
return false;
}

if (!(key in data)) {
return true;
}

if ('type' in validator && validator.type.indexOf(typeof data[key]) === -1) {
var valid = false;

Expand All @@ -90,7 +94,7 @@ function plugin(matchers) {
}
}

if ('pattern' in validator && key in data && ((typeof validator.pattern === 'function' && !validator.pattern(data[key])) || !data[key].match(validator.pattern))) {
if ('pattern' in validator && ((typeof validator.pattern === 'function' && !validator.pattern(data[key])) || !data[key].match(validator.pattern))) {
err = new Error('File "' + file + '" value "' + key + '" does not match ' + validator.pattern + '.');
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "metalsmith-validate",
"description": "A Metalsmith plugin that allows you to easily validate file metadata, checking existence, type, and regex pattern.",
"repository": "git://github.com/mikestopcontinues/metalsmith-validate.git",
"version": "0.1.0",
"version": "0.1.1",
"author": "Mike Stop Continues <mikestopcontinues@gmail.com>",
"license": "MIT",
"main": "lib/index.js",
Expand Down

0 comments on commit 0c2b094

Please sign in to comment.