mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 01:37:24 +00:00
36 lines
941 B
TypeScript
36 lines
941 B
TypeScript
import { regEx } from '../../../util/regex.ts';
|
|
|
|
// Extract Ruby string value (handles both quote styles)
|
|
export function extractRubyString(
|
|
content: string,
|
|
keyword: string,
|
|
): string | null {
|
|
const regex = regEx(
|
|
`\\b${keyword}\\s+(?:"(?<double>[^"]+)"|'(?<single>[^']+)')`,
|
|
);
|
|
const match = content.match(regex);
|
|
return match?.groups?.double ?? match?.groups?.single ?? null;
|
|
}
|
|
|
|
// Update Ruby string value (preserves quote style)
|
|
export function updateRubyString(
|
|
content: string,
|
|
keyword: string,
|
|
oldValue: string,
|
|
newValue: string,
|
|
): string | null {
|
|
const doubleQuote = regEx(
|
|
`(\\b${keyword}\\s+)"${RegExp.escape(oldValue)}"`,
|
|
'g',
|
|
);
|
|
const singleQuote = regEx(
|
|
`(\\b${keyword}\\s+)'${RegExp.escape(oldValue)}'`,
|
|
'g',
|
|
);
|
|
const result = content
|
|
.replace(doubleQuote, `$1"${newValue}"`)
|
|
.replace(singleQuote, `$1'${newValue}'`);
|
|
|
|
return result === content ? null : result;
|
|
}
|