Skip to content

Commit

Permalink
Use double regex instead of if branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed May 8, 2024
1 parent d653ab8 commit d09fcaa
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function getGeneratedTitle({
concatenateChatCompletionChunks(),
last(),
map((concatenatedMessage) => {
let title: string =
const title: string =
(concatenatedMessage.message.function_call.name
? JSON.parse(concatenatedMessage.message.function_call.arguments).title
: concatenatedMessage.message?.content) || '';
Expand All @@ -87,13 +87,8 @@ export function getGeneratedTitle({
// - "Hello, World!" => Captures: Hello, World!
// - 'Another Example' => Captures: Another Example
// - JustTextWithoutQuotes => Captures: JustTextWithoutQuotes
if (
(title.startsWith(`"`) && title.endsWith(`"`)) ||
(title.startsWith(`'`) && title.endsWith(`'`))
) {
title = title.substring(1, title.length - 1);
}
return title;

return title.replace(/^"(.*)"$/g, '$1').replace(/^'(.*)'$/g, '$1');
}),
tap((event) => {
if (typeof event === 'string') {
Expand Down

0 comments on commit d09fcaa

Please sign in to comment.