diff --git a/packages/apps/tools/src/utils/__tests__/string.spec.ts b/packages/apps/tools/src/utils/__tests__/string.spec.ts new file mode 100644 index 0000000000..8a25546513 --- /dev/null +++ b/packages/apps/tools/src/utils/__tests__/string.spec.ts @@ -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'); + }); +}); diff --git a/packages/apps/tools/src/utils/string.ts b/packages/apps/tools/src/utils/string.ts new file mode 100644 index 0000000000..3e6cec7f81 --- /dev/null +++ b/packages/apps/tools/src/utils/string.ts @@ -0,0 +1,3 @@ +export const stripAccountPrefix = (account: string): string => { + return account.trim().replace(/^k:/i, ''); +};