Skip to content

Commit

Permalink
fix: remove quote (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe authored Nov 12, 2024
1 parent e0e2c09 commit 87fda63
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/helpers/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function getMatchImport(str: string) {
}
}

function removeQuote(str: string) {
return str.replace(/^["'`](.*)["'`]$/, '$1');
}

/**
* Get the array content of the key in the target string.
* @example getMatchArray('key', 'key: [a, b, c]') => ['a', 'b', 'c']
Expand All @@ -37,7 +41,7 @@ export function getMatchArray(key: string, target: string) {
target
.match(mixinReg)?.[1]
?.split(/,\s/g)
.map((i) => i.trim().replace(/["'`]/g, ''))
.map((i) => removeQuote(i.trim()))
.filter(Boolean) ?? []
);

Expand Down Expand Up @@ -74,11 +78,7 @@ export function replaceMatchArray(

key === 'content'
? targetArray.splice(insertIndex + 1, 0, ` ${key}: [${replaceValue}],`)
: targetArray.splice(
insertIndex + 1,
0,
` ${key}: [${value.map((v) => v.replace(/["'`]/g, ''))}],`
);
: targetArray.splice(insertIndex + 1, 0, ` ${key}: [${value.map((v) => removeQuote(v))}],`);

return targetArray.join('\n');
}

0 comments on commit 87fda63

Please sign in to comment.