HEX
Server: LiteSpeed
System: Linux CentOS-79-64-minimal 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: vishn3436 (5293)
PHP: 8.0.15
Disabled: NONE
Upload Files
File: //data/wpp-docker/node_modules/conventional-commits-parser/lib/regex.js
'use strict'

const reNomatch = /(?!.*)/

function join (array, joiner) {
  return array
    .map(function (val) {
      return val.trim()
    })
    .filter(function (val) {
      return val.length
    })
    .join(joiner)
}

function getNotesRegex (noteKeywords, notesPattern) {
  if (!noteKeywords) {
    return reNomatch
  }

  const noteKeywordsSelection = join(noteKeywords, '|')

  if (!notesPattern) {
    return new RegExp('^[\\s|*]*(' + noteKeywordsSelection + ')[:\\s]+(.*)', 'i')
  }

  return notesPattern(noteKeywordsSelection)
}

function getReferencePartsRegex (issuePrefixes, issuePrefixesCaseSensitive) {
  if (!issuePrefixes) {
    return reNomatch
  }

  const flags = issuePrefixesCaseSensitive ? 'g' : 'gi'
  return new RegExp('(?:.*?)??\\s*([\\w-\\.\\/]*?)??(' + join(issuePrefixes, '|') + ')([\\w-]*\\d+)', flags)
}

function getReferencesRegex (referenceActions) {
  if (!referenceActions) {
    // matches everything
    return /()(.+)/gi
  }

  const joinedKeywords = join(referenceActions, '|')
  return new RegExp('(' + joinedKeywords + ')(?:\\s+(.*?))(?=(?:' + joinedKeywords + ')|$)', 'gi')
}

module.exports = function (options) {
  options = options || {}
  const reNotes = getNotesRegex(options.noteKeywords, options.notesPattern)
  const reReferenceParts = getReferencePartsRegex(options.issuePrefixes, options.issuePrefixesCaseSensitive)
  const reReferences = getReferencesRegex(options.referenceActions)

  return {
    notes: reNotes,
    referenceParts: reReferenceParts,
    references: reReferences,
    mentions: /@([\w-]+)/g
  }
}