Skip to content

Commit

Permalink
refactor(formatters): Change :_: emoji name placeholder (#10567)
Browse files Browse the repository at this point in the history
* Change `:_:` emoji name placeholder

* Update tests

* Format
  • Loading branch information
cobaltt7 authored Nov 11, 2024
1 parent c973106 commit f2f7f1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
34 changes: 20 additions & 14 deletions packages/formatters/__tests__/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,31 +174,37 @@ describe('Message formatters', () => {
});

describe('formatEmoji', () => {
test('GIVEN static emojiId THEN returns "<:_:${emojiId}>"', () => {
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952')).toEqual('<:_:851461487498493952>');
test('GIVEN static emojiId THEN returns "<:emoji:${emojiId}>"', () => {
expect<`<:emoji:851461487498493952>`>(formatEmoji('851461487498493952')).toEqual('<:emoji:851461487498493952>');
});

test('GIVEN static emojiId WITH animated explicitly false THEN returns "<:_:[emojiId]>"', () => {
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952', false)).toEqual('<:_:851461487498493952>');
test('GIVEN static emojiId WITH animated explicitly false THEN returns "<:emoji:[emojiId]>"', () => {
expect<`<:emoji:851461487498493952>`>(formatEmoji('851461487498493952', false)).toEqual(
'<:emoji:851461487498493952>',
);
});

test('GIVEN animated emojiId THEN returns "<a:_:${emojiId}>"', () => {
expect<`<a:_:827220205352255549>`>(formatEmoji('827220205352255549', true)).toEqual('<a:_:827220205352255549>');
test('GIVEN animated emojiId THEN returns "<a:emoji:${emojiId}>"', () => {
expect<`<a:emoji:827220205352255549>`>(formatEmoji('827220205352255549', true)).toEqual(
'<a:emoji:827220205352255549>',
);
});

test('GIVEN static id in options object THEN returns "<:_:${id}>"', () => {
expect<`<:_:851461487498493952>`>(formatEmoji({ id: '851461487498493952' })).toEqual('<:_:851461487498493952>');
test('GIVEN static id in options object THEN returns "<:emoji:${id}>"', () => {
expect<`<:emoji:851461487498493952>`>(formatEmoji({ id: '851461487498493952' })).toEqual(
'<:emoji:851461487498493952>',
);
});

test('GIVEN static id in options object WITH animated explicitly false THEN returns "<:_:${id}>"', () => {
expect<`<:_:851461487498493952>`>(formatEmoji({ animated: false, id: '851461487498493952' })).toEqual(
'<:_:851461487498493952>',
test('GIVEN static id in options object WITH animated explicitly false THEN returns "<:emoji:${id}>"', () => {
expect<`<:emoji:851461487498493952>`>(formatEmoji({ animated: false, id: '851461487498493952' })).toEqual(
'<:emoji:851461487498493952>',
);
});

test('GIVEN animated id in options object THEN returns "<a:_:${id}>"', () => {
expect<`<a:_:827220205352255549>`>(formatEmoji({ animated: true, id: '827220205352255549' })).toEqual(
'<a:_:827220205352255549>',
test('GIVEN animated id in options object THEN returns "<a:emoji:${id}>"', () => {
expect<`<a:emoji:827220205352255549>`>(formatEmoji({ animated: true, id: '827220205352255549' })).toEqual(
'<a:emoji:827220205352255549>',
);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/formatters/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export function chatInputApplicationCommandMention<
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @param emojiId - The emoji id to format
*/
export function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: false): `<:_:${EmojiId}>`;
export function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: false): `<:emoji:${EmojiId}>`;

/**
* Formats an animated emoji id into a fully qualified emoji identifier.
Expand All @@ -332,7 +332,7 @@ export function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animate
* @param emojiId - The emoji id to format
* @param animated - Whether the emoji is animated
*/
export function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: true): `<a:_:${EmojiId}>`;
export function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: true): `<a:emoji:${EmojiId}>`;

/**
* Formats an emoji id into a fully qualified emoji identifier.
Expand All @@ -344,7 +344,7 @@ export function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animate
export function formatEmoji<EmojiId extends Snowflake>(
emojiId: EmojiId,
animated?: boolean,
): `<:_:${EmojiId}>` | `<a:_:${EmojiId}>`;
): `<:emoji:${EmojiId}>` | `<a:emoji:${EmojiId}>`;

/**
* Formats a non-animated emoji id and name into a fully qualified emoji identifier.
Expand Down Expand Up @@ -393,7 +393,7 @@ export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>

const { id, animated: isAnimated, name: emojiName } = options;

return `<${isAnimated ? 'a' : ''}:${emojiName ?? '_'}:${id}>`;
return `<${isAnimated ? 'a' : ''}:${emojiName ?? 'emoji'}:${id}>`;
}

/**
Expand Down

0 comments on commit f2f7f1f

Please sign in to comment.