After 2 longs days of searching and dispair, your library seems to save me. Thank you.
I am a bit worried about the viability, though, seeing your previous responses. Is this a dead project for you, or would you still consider taking PRs, and releasing new versions?
Context
I am in need to determine whether a first pattern raa is covered by another ram.
Interesting references I found are:
The approach that I found referenced was
- create
ram|raa, the pattern that expresses that a string must match ram or raa
- derive DFA(
ram|raa) and DFA(ram), and minimize them
- if the 2 resulting minimized DFAs are isomorph,
raa is covered by ram
Indeed, ram|raa (ram or raa) allows more strings to match than ram alone. If however ram|raa turns out to match exactly the same set of strings as ram alone, it means that all the strings that are matched by raa are already in the set of strings matched by ram, i.e., raa is covered by ram.
Alternatively, we can determine the intersection of raa and ram:
- create
ram&raa, the pattern that expresses that a string must match both ram and raa
- derive DFA(
ram&raa) and DFA(raa), and minimize them
- if the 2 resulting minimized [DFA]s are isomorph,
raa is covered by ram
Indeed, ram&raa (ram and raa) allows less strings to match than raa alone. If however ram&raa turns out to match exactly the same set of strings as raa alone, it means that there are no strings that are matched by raa that are not matched by ram, i.e., raa is covered by ram.
This now seems to be realised trivially by your library:
const intersect = require('glob-intersection')
function minimize (pattern) {
return intersect(pattern, pattern)
}
function covered (raaPattern, ramPattern) {
let intersection = intersect(raaPattern, ramPattern)
console.log(`${raaPattern} ∩ ${ramPattern} = ${intersection}`)
const result = typeof intersection === 'string' && intersection === minimize(raaPattern)
console.log(`${raaPattern} ⊆ ${ramPattern} ? ${result}`)
return result
}
covered('/I/*/p523564.faa.bar.baz/**', '/I/**')
covered('/I/**', '/I/*/p523564.faa.bar.baz/**')
covered('/I/*/p523564.faa.bar.baz/**', '/I/*')
covered('/I/*/p523564.faa.bar.baz/service/instance', '/I/host/p523564.faa.bar.baz/**')
covered('{GET,PUT,DELETE}', '*')
covered('*', '{GET,PUT,DELETE}')
covered('PUT', 'DELETE')
covered('PUT', '{GET,DELETE}')
covered('{GET,PUT}', '{GET,PUT,DELETE}') // requires minimisation of raaPattern
After 2 longs days of searching and dispair, your library seems to save me. Thank you.
I am a bit worried about the viability, though, seeing your previous responses. Is this a dead project for you, or would you still consider taking PRs, and releasing new versions?
Context
I am in need to determine whether a first pattern
raais covered by anotherram.Interesting references I found are:
The approach that I found referenced was
ram|raa, the pattern that expresses that a string must matchramorraaram|raa) and DFA(ram), and minimize themraais covered byramIndeed,
ram|raa(ramorraa) allows more strings to match thanramalone. If howeverram|raaturns out to match exactly the same set of strings asramalone, it means that all the strings that are matched byraaare already in the set of strings matched byram, i.e.,raais covered byram.Alternatively, we can determine the intersection of
raaandram:ram&raa, the pattern that expresses that a string must match bothramandraaram&raa) and DFA(raa), and minimize themraais covered byramIndeed,
ram&raa(ramandraa) allows less strings to match thanraaalone. If howeverram&raaturns out to match exactly the same set of strings asraaalone, it means that there are no strings that are matched byraathat are not matched byram, i.e.,raais covered byram.This now seems to be realised trivially by your library: