Skip to content

Commit

Permalink
feat(utils): separate "avatar"
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustinMauroy committed Oct 11, 2023
1 parent c61cbf9 commit 0e2e396
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/Common/AvatarGroup/Avatar/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import { githubProfileAvatarUrl } from '@/util/avatars';
import { githubProfileAvatarUrl } from '@/util/github';

import Avatar from './';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/AvatarGroup/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import { githubProfileAvatarUrl } from '@/util/avatars';
import { githubProfileAvatarUrl } from '@/util/github';

import AvatarGroup from './';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/AvatarGroup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FC } from 'react';
import { useState, useMemo } from 'react';

import { getAcronymFromString } from '@/util/avatars';
import { getAcronymFromString } from '@/util/stringutils';

import Avatar from './Avatar';
import avatarstyles from './Avatar/index.module.css';
Expand Down
9 changes: 9 additions & 0 deletions util/__tests__/github.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { githubProfileAvatarUrl } from '@/util/github';

describe('Github utils', () => {
it('githubProfileAvatarUrl returns the correct URL', () => {
expect(githubProfileAvatarUrl('octocat')).toBe(
'https://avatars.githubusercontent.com/octocat'
);
});
});
10 changes: 2 additions & 8 deletions util/__tests__/avatar.test.mjs → util/__tests__/string.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { githubProfileAvatarUrl, getAcronymFromString } from '@/util/avatars';

describe('Avatar', () => {
it('githubProfileAvatarUrl returns the correct URL', () => {
expect(githubProfileAvatarUrl('octocat')).toBe(
'https://avatars.githubusercontent.com/octocat'
);
});
import { getAcronymFromString } from '@/util/stringUtils';

describe('String utils', () => {
it('getAcronymFromString returns the correct acronym', () => {
expect(getAcronymFromString('John Doe')).toBe('JD');
});
Expand Down
2 changes: 2 additions & 0 deletions util/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const githubProfileAvatarUrl = (username: string): string =>
`https://avatars.githubusercontent.com/${username}`;
3 changes: 0 additions & 3 deletions util/avatars.ts → util/stringutils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export const githubProfileAvatarUrl = (username: string): string =>
`https://avatars.githubusercontent.com/${username}`;

export const getAcronymFromString = (str = '') =>
str.length > 0
? [...(str.trim().match(/\b(\w)/g) || '')].join('').toUpperCase()
Expand Down

0 comments on commit 0e2e396

Please sign in to comment.