mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
refactor!: move embedLength function to util package (#11327)
BREAKING CHANGE: Builders no longer exports a `embedLength` function. Import it from `@discordjs/util` instead. Co-authored-by: Danial Raza <danialrazafb@gmail.com> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
16
packages/util/src/functions/embedLength.ts
Normal file
16
packages/util/src/functions/embedLength.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { APIEmbed } from 'discord-api-types/v10';
|
||||
|
||||
/**
|
||||
* Calculates the length of an embed.
|
||||
*
|
||||
* @param data - The embed data to check
|
||||
*/
|
||||
export function embedLength(data: APIEmbed) {
|
||||
return (
|
||||
(data.title?.length ?? 0) +
|
||||
(data.description?.length ?? 0) +
|
||||
(data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) +
|
||||
(data.footer?.text.length ?? 0) +
|
||||
(data.author?.name.length ?? 0)
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './calculateShardId.js';
|
||||
export * from './embedLength.js';
|
||||
export * from './lazy.js';
|
||||
export * from './range.js';
|
||||
export * from './calculateShardId.js';
|
||||
export * from './runtime.js';
|
||||
export * from './userAgentAppendix.js';
|
||||
|
||||
Reference in New Issue
Block a user