Skip to content

Instantly share code, notes, and snippets.

@thmsobrmlr
Created February 12, 2022 16:07
Show Gist options
  • Save thmsobrmlr/732ecf958f600ec38e89c4e8ff57f3dd to your computer and use it in GitHub Desktop.
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
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)');
});
});
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