Skip to content

Commit

Permalink
convert space to dash for consumer tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed Apr 12, 2024
1 parent 5b06c04 commit 0c99f14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ export async function fetchWithTimeout(resource: string, options: any = {}) {
}

export function alphanumericNoSpaces(str: string) {
return str.replace(/[^A-Za-z0-9:-]/gim, '').replace(/[:]/gim, '-');
return str.replace(/[^A-Za-z0-9 :-]/gim, '').replace(/[ :]/gim, '-');
}
8 changes: 4 additions & 4 deletions src/test/services/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { alphanumericNoSpaces } from '../../services/utils';

describe('alphanumericNoSpaces tests', () => {
it('should remove spaces from the string', () => {
it('should replace space with dash in the string', () => {
const input = 'hello world';
const expectedOutput = 'helloworld';
const expectedOutput = 'hello-world';
expect(alphanumericNoSpaces(input)).toEqual(expectedOutput);
});

it('should remove special characters', () => {
const input = 'hello@world!how%^&*are you?';
const expectedOutput = 'helloworldhowareyou';
const expectedOutput = 'helloworldhoware-you';
expect(alphanumericNoSpaces(input)).toEqual(expectedOutput);
});

Expand Down Expand Up @@ -45,7 +45,7 @@ describe('alphanumericNoSpaces tests', () => {

it('should handle string with mixed characters', () => {
const input = 'hello!-world, how:are?you';
const expectedOutput = 'hello-worldhow-areyou';
const expectedOutput = 'hello-world-how-areyou';
expect(alphanumericNoSpaces(input)).toEqual(expectedOutput);
});
});

0 comments on commit 0c99f14

Please sign in to comment.