export function _extractParams()

in src/main.ts [306:325]


export function _extractParams(
  wildcardTriggerPath: string,
  dataPath: string
): EventContext['params'] {
  // Trim start and end / and split into path components
  const wildcardPaths = wildcardTriggerPath
    .replace(/^\/?(.*?)\/?$/, '$1')
    .split('/');
  const dataPaths = dataPath.replace(/^\/?(.*?)\/?$/, '$1').split('/');
  const params = {};
  if (wildcardPaths.length === dataPaths.length) {
    for (let idx = 0; idx < wildcardPaths.length; idx++) {
      const wildcardPath = wildcardPaths[idx];
      const name = wildcardPath.replace(/^{([^/{}]*)}$/, '$1');
      if (name !== wildcardPath) {
        // Wildcard parameter
        params[name] = dataPaths[idx];
      }
    }
  }