Created
August 5, 2015 16:21
-
-
Save marcusbesjes/4112fdaa9b1c758d0469 to your computer and use it in GitHub Desktop.
git-spy_match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pattern = { | |
'*': { | |
'*': { | |
'otherfile': true | |
}, | |
'master': { | |
'packagef.json': true | |
} | |
} | |
} | |
var output = { | |
'git-spy': { | |
master: { | |
'package.json0': true, | |
'package.json': true, | |
'package.json2': true | |
} | |
} | |
} | |
function match(output, pattern) { | |
console.log('\n\n---- match!') | |
console.log(output) | |
console.log('against') | |
console.log(pattern) | |
console.log('\n--- keys:') | |
if(!output || !pattern) { | |
return false | |
} | |
var result = false | |
for(var o in output) { | |
console.log('output has: ', o) | |
for( var p in pattern ) { | |
console.log('pattern has:', p) | |
if(p === o || p === '*') { | |
if(pattern[p] === true) { // pattern stops here >> match found! | |
return true | |
} else if(match(output[o], pattern[p])){ // look deeper | |
return true | |
} | |
} | |
} | |
} | |
return result | |
} | |
console.log('match dat!', match(output, pattern)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment