new parse (v5)

Revision 5 of this benchmark created on


Setup

window.parseRequestInfoOld = function(requestPath) {
  const matches =
    requestPath.match(
      /[/]?(@[-_a-z-A-Z0-9.]+\/[-_a-z-A-Z0-9.]+|[a-zA-Z-0-9.]+)(@([-_a-zA-Z-0-9.]+))?(\/v([0-9.]+))?(\/(bundled|unbundled))?(\/[-_/a-zA-Z0-9.+]+)?/,
    ) || [];

  const packageName = matches[1] || '';
  const version = matches[3] || '';
  const bundled = (matches.length > 8 && matches[7]) === 'bundled';
  const filePath = (matches.length > 8 && matches[8]) || '';

  return {
    packageName,
    version,
    bundled,
    filePath,
  };
}

window.parseRequestInfoNew = function(requestPath) {
  const matches =
    requestPath.match(
      //   1 package name              2 version  refresh            3 bundled            4 file path   end or query
      /^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/v[\d.]+)?(?:\/(bundled|unbundled))?(\/[-\w.+/]+)?(?:\?|$)/,
    ) || [];

  return {
    packageName: matches[1] || '',
    version: matches[2] || '',
    bundled: matches[3] === 'bundled',
    filePath: matches[4] || '',
  };
}

Test runner

Ready to run.

Testing in
TestOps/sec
Test old
parseRequestInfoOld('@foo/bar@1.1.1/bundled/a/b/c')
ready
Test new
parseRequestInfoNew('@foo/bar@1.1.1/bundled/a/b/c')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.