UNPKG

browser-extension-url-match

Version:

Browser extension URL pattern matching

38 lines (37 loc) 815 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPatternSegments = getPatternSegments; var _fancyRegex = require("fancy-regex"); var _constants = require("./constants"); const patternRegex = (0, _fancyRegex.regex)()` ^ (\*|\w+) # scheme :// ( \* | # Any host [^/\#]* # Only the given host (optional only if scheme is file) ) (/[^\r\n\#]*) # path $ `; function getPatternSegments(pattern) { if (pattern === _constants.ALL_URLS) { return { pattern, scheme: '*', rawHost: '*', rawPathAndQuery: '/*' }; } const m = pattern.match(patternRegex); if (!m) return null; const [, /* fullMatch */scheme, rawHost, rawPathAndQuery] = m; return { pattern, scheme, rawHost, rawPathAndQuery }; }