-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Tidal): format textual copyright symbols as © or ℗
Add a utility function formatCopyrightSymbols to handle this and use it also in the Spotify implementation.
- Loading branch information
Showing
4 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { formatCopyrightSymbols } from './copyright.ts'; | ||
|
||
import { assertEquals } from 'std/assert/assert_equals.ts'; | ||
import { describe, it } from 'std/testing/bdd.ts'; | ||
|
||
import type { FunctionSpec } from './test_spec.ts'; | ||
|
||
describe('format copyright symbols', () => { | ||
const passingCases: FunctionSpec<typeof formatCopyrightSymbols> = [ | ||
['should keep string without symbols', 'Nuclear Blast', undefined, 'Nuclear Blast'], | ||
['should replace (P)', '(P) 2016 Century Media Records Ltd.', undefined, '℗ 2016 Century Media Records Ltd.'], | ||
['should keep symbols', '© 2012 S. Carter Enterprises, LLC.', undefined, '© 2012 S. Carter Enterprises, LLC.'], | ||
[ | ||
'should convert multiple symbols', | ||
'(p)(c) 2017 S. CARTER ENTERPRISES, LLC. MARKETED BY ROC NATION & DISTRIBUTED BY ROC NATION/UMG RECORDINGS INC.', | ||
undefined, | ||
'℗© 2017 S. CARTER ENTERPRISES, LLC. MARKETED BY ROC NATION & DISTRIBUTED BY ROC NATION/UMG RECORDINGS INC.', | ||
], | ||
['should prepend expected symbol', 'Nuclear Blast', '℗', '℗ Nuclear Blast'], | ||
['should not prepend symbol if it exists', '2024 ℗ Nuclear Blast', '℗', '2024 ℗ Nuclear Blast'], | ||
['should not prepend symbol if any exists', '2024 © Nuclear Blast', '℗', '2024 © Nuclear Blast'], | ||
['should not prepend symbol if it exists as text', '(c)+(p) Nuclear Blast', '℗', '©+℗ Nuclear Blast'], | ||
]; | ||
|
||
passingCases.forEach(([description, copyright, expectedSymbol, expected]) => { | ||
it(description, () => { | ||
assertEquals(formatCopyrightSymbols(copyright, expectedSymbol), expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** Formats a copyright string, replacing (c) and (p) with the corresponding symbol. | ||
* | ||
* If expectedSymbol is given the symbol will be prepended if no other copyright symbol | ||
* is already present in the string. | ||
*/ | ||
export function formatCopyrightSymbols(copyright: string, expectedSymbol: '©' | '℗' | undefined = undefined): string { | ||
copyright = copyright.replace(/\(c\)/i, '©').replace(/\(p\)/i, '℗'); | ||
if (expectedSymbol && !copyright.includes('©') && !copyright.includes('℗')) { | ||
copyright = `${expectedSymbol} ${copyright}`; | ||
} | ||
return copyright; | ||
} |