parent
c6eb5553d0
commit
b9f2668cea
4 changed files with 52 additions and 2 deletions
@ -0,0 +1,6 @@ |
||||
const fromWildcard = (pattern) => { |
||||
let regexStr = '^' + pattern.replace(/\*/g, '.*') + '$'; |
||||
return new RegExp(regexStr); |
||||
}; |
||||
|
||||
export { fromWildcard }; |
@ -0,0 +1,20 @@ |
||||
import { expect } from 'chai'; |
||||
import * as re from 'shared/utils/re'; |
||||
|
||||
describe("re util", () => { |
||||
it('matches by pattern', () => { |
||||
let regex = re.fromWildcard('*.example.com/*'); |
||||
expect('foo.example.com/bar').to.match(regex); |
||||
expect('foo.example.com').not.to.match(regex); |
||||
expect('example.com/bar').not.to.match(regex); |
||||
|
||||
regex = re.fromWildcard('example.com/*') |
||||
expect('example.com/foo').to.match(regex); |
||||
expect('example.com/').to.match(regex); |
||||
|
||||
regex = re.fromWildcard('example.com/*bar') |
||||
expect('example.com/foobar').to.match(regex); |
||||
expect('example.com/bar').to.match(regex); |
||||
expect('example.com/foobarfoo').not.to.match(regex); |
||||
}) |
||||
}); |
Reference in new issue