Created
February 12, 2022 16:07
-
-
Save thmsobrmlr/732ecf958f600ec38e89c4e8ff57f3dd to your computer and use it in GitHub Desktop.
Remove the app name for product titles for Google Play In-App-Purchases
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
import removeAppNameFromProductTitle from './removeAppNameFromProductTitle'; | |
describe('removeAppNameFromProductTitle', () => { | |
it('returns title without app name', () => { | |
const title = 'my test'; | |
const result = removeAppNameFromProductTitle(title); | |
expect(result).toEqual('my test'); | |
}); | |
it('removes app name from title', () => { | |
const title = 'my test (com.test.myapp)'; | |
const result = removeAppNameFromProductTitle(title); | |
expect(result).toEqual('my test'); | |
}); | |
it('removes app name from title with parantheses', () => { | |
const title = 'my test (a good test) (com.test.myapp)'; | |
const result = removeAppNameFromProductTitle(title); | |
expect(result).toEqual('my test (a good test)'); | |
}); | |
it('removes app name with nested parantheses from title', () => { | |
const title = 'my test (com.test.myapp (unreviewed))'; | |
const result = removeAppNameFromProductTitle(title); | |
expect(result).toEqual('my test'); | |
}); | |
it('removes app name with nested parantheses from title with parantheses', () => { | |
const title = 'my test (a good test) (com.test.myapp (unreviewed))'; | |
const result = removeAppNameFromProductTitle(title); | |
expect(result).toEqual('my test (a good test)'); | |
}); | |
}); |
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
const removeAppNameFromProductTitle = (title: string) => { | |
const regex = /( \([^()]*\)$)|( \([^)]*\)\)$)/im; | |
return title.replace(regex, ''); | |
}; | |
export default removeAppNameFromProductTitle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment