From 423448e162e3c9fb56ae14cea107db078cb93dc1 Mon Sep 17 00:00:00 2001 From: Sander Looijenga Date: Wed, 24 Jan 2024 17:21:09 +0100 Subject: [PATCH] Add stripAccountPrefix utility function + test --- .../tools/src/utils/__tests__/string.spec.ts | 17 +++++++++++++++++ packages/apps/tools/src/utils/string.ts | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 packages/apps/tools/src/utils/__tests__/string.spec.ts create mode 100644 packages/apps/tools/src/utils/string.ts 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, ''); +};