Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git-spy_match
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
You can’t perform that action at this time.