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.

Revisions

  1. thmsobrmlr created this gist Feb 12, 2022.
    43 changes: 43 additions & 0 deletions removeAppNameFromProductTitle.test.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    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)');
    });
    });
    6 changes: 6 additions & 0 deletions removeAppNameFromProductTitle.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    const removeAppNameFromProductTitle = (title: string) => {
    const regex = /( \([^()]*\)$)|( \([^)]*\)\)$)/im;
    return title.replace(regex, '');
    };

    export default removeAppNameFromProductTitle;