Skip to content

Commit

Permalink
Add stripAccountPrefix utility function + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Looijenga committed Jan 24, 2024
1 parent 75495b2 commit 423448e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/apps/tools/src/utils/__tests__/string.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest';
import { stripAccountPrefix } from '../string';

describe('stripAccountPrefix', () => {
it('should be able strip the k: prefix from an account name', () => {
expect(stripAccountPrefix('k:123abc')).toBe('123abc');
expect(stripAccountPrefix(' k:123abc')).toBe('123abc');
expect(stripAccountPrefix('k:123abc ')).toBe('123abc');
expect(stripAccountPrefix(' k:123abc ')).toBe('123abc');
expect(stripAccountPrefix('K:123abc')).toBe('123abc');
expect(stripAccountPrefix('123abc')).toBe('123abc');
expect(stripAccountPrefix(' 123abc ')).toBe('123abc');
expect(stripAccountPrefix('c:123abc')).toBe('c:123abc');
expect(stripAccountPrefix(' c:123abc ')).toBe('c:123abc');
expect(stripAccountPrefix('w:123abc:keys-any')).toBe('w:123abc:keys-any');
});
});
3 changes: 3 additions & 0 deletions packages/apps/tools/src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const stripAccountPrefix = (account: string): string => {
return account.trim().replace(/^k:/i, '');
};

0 comments on commit 423448e

Please sign in to comment.