const { parse } = require('url')
const UrlPattern = require('url-pattern')

const patternOpts = {
  segmentNameCharset: 'a-zA-Z0-9_-',
}

const isPattern = pattern => pattern instanceof UrlPattern

const getParamsAndQuery = (pattern, url) => {
  const { query, pathname } = parse(url, true)
  const route = isPattern(pattern)
    ? pattern
    : new UrlPattern(pattern, patternOpts)
  const params = route.match(pathname)

  return { query, params }
}

module.exports = {
  getParamsAndQuery,
  isPattern,
  patternOpts,
}

const { parse } = require('url')
const UrlPattern = require('url-pattern')

const patternOpts = {
  segmentNameCharset: 'a-zA-Z0-9_-',,
  segmentValueCharset: 'a-zA-Z0-9@\.\+\-\_'
}

const isPattern = pattern => pattern instanceof UrlPattern

const getParamsAndQuery = (pattern, url) => {
  const { query, pathname } = parse(url, true)
  const route = isPattern(pattern)
    ? pattern
    : new UrlPattern(pattern, patternOpts)
  const params = route.match(pathname)

  return { query, params }
}

module.exports = {
  getParamsAndQuery,
  isPattern,
  patternOpts,
}

Allow some more chars in url as pattern value
Allow some more chars in url as pattern value

Allow character @, dot, +, _ and - as url pattern value, so email address can be passed as url parameter.