import type { ScanConfigSchema } from '@/scripts/op-config' import type { PluginConfigScanResultItem } from '@/types' export const findMatchedConfigApis = ( scanResults: PluginConfigScanResultItem[], scanConfig: ScanConfigSchema, ) => { const { apis = [], patternFragment } = scanConfig const apisStr = apis.map((api) => api.trim()).join('\n') scanResults.forEach((item) => { const { correspondingApis = [] } = item const { pre, placeholder, post } = patternFragment correspondingApis.forEach((triggerApi) => { if (!item.matched) { item.matched = [] } const pattern = new RegExp( `${pre}${triggerApi.replaceAll('{placeholder}', placeholder).trim()}${post}`, 'ig', ) item.matched.push(...(apisStr.match(pattern) || [])) }) }) return scanResults }