Skip to content

Commit

Permalink
Add replaceSmartQuotes function (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
inverse authored Dec 29, 2023
1 parent a8f7a31 commit c37927e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,14 @@ export function youtube(text: string): string {
...TRIM_SYMBOLS_FILTER_RULES,
]);
}

/**
* Replace smart quotes with regular quotes.
*
* @param text String to be filtered
*
* @return Filtered string
*/
export function replaceSmartQuotes(text: string): string {
return text.replace(/[\u2018\u2019]/g, "'").replace(/[\u201c\u201d]/g, '"');
}
32 changes: 32 additions & 0 deletions test/fixtures/functions/replace-smart-quotes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"description": "should do nothing with clean string",
"funcParameter": "Track field",
"expectedValue": "Track field"
},
{
"description": "should remove a double left single quotation space",
"funcParameter": "Track \u201cfield",
"expectedValue": "Track \"field"
},
{
"description": "should remove a double left and double right quotation space",
"funcParameter": "Track \u201cfield\u201d",
"expectedValue": "Track \"field\""
},
{
"description": "should remove a single left single quotation space",
"funcParameter": "Track \u2018field",
"expectedValue": "Track 'field"
},
{
"description": "should remove a single left and single right quotation space",
"funcParameter": "Track \u2018field\u2019",
"expectedValue": "Track 'field'"
},
{
"description": "should remove a single left and double right quotation space",
"funcParameter": "Track \u2018field\u201d",
"expectedValue": "Track 'field\""
}
]
2 changes: 2 additions & 0 deletions test/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
removeFeature,
youtube,
fixVariousArtists,
replaceSmartQuotes,
} from '../src';

const functionsToTest = {
Expand All @@ -38,6 +39,7 @@ const functionsToTest = {
'remove-version': removeVersion,
'remove-parody': removeParody,
'remove-feature': removeFeature,
'replace-smart-quotes': replaceSmartQuotes,
youtube: youtube,
};

Expand Down

0 comments on commit c37927e

Please sign in to comment.