mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +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:
@@ -1,5 +1,6 @@
|
||||
import { embedLength } from '@discordjs/util';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { EmbedBuilder, embedLength } from '../../src/index.js';
|
||||
import { EmbedBuilder } from '../../src/index.js';
|
||||
|
||||
const alpha = 'abcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
|
||||
@@ -89,7 +89,6 @@ export * from './messages/Attachment.js';
|
||||
export * from './messages/Message.js';
|
||||
export * from './messages/MessageReference.js';
|
||||
|
||||
export * from './util/componentUtil.js';
|
||||
export * from './util/normalizeArray.js';
|
||||
export * from './util/resolveBuilder.js';
|
||||
export { disableValidators, enableValidators, isValidationEnabled } from './util/validation.js';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { embedLength } from '@discordjs/util';
|
||||
import { z } from 'zod';
|
||||
import { embedLength } from '../../util/componentUtil.js';
|
||||
|
||||
const namePredicate = z.string().max(256);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { embedLength } = require('@discordjs/builders');
|
||||
const { embedLength } = require('@discordjs/util');
|
||||
const isEqual = require('fast-deep-equal');
|
||||
|
||||
/**
|
||||
|
||||
20
packages/util/__tests__/embedLength.test.ts
Normal file
20
packages/util/__tests__/embedLength.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { embedLength } from '../src/functions/embedLength.js';
|
||||
|
||||
describe('embedLength', () => {
|
||||
test('GIVEN an embed with specific amount of characters THEN returns amount of characters', () => {
|
||||
const embed = {
|
||||
title: 'yeet',
|
||||
description: 'yeet',
|
||||
fields: [{ name: 'yeet', value: 'yeet' }],
|
||||
author: { name: 'yeet' },
|
||||
footer: { text: 'yeet' },
|
||||
};
|
||||
|
||||
expect(embedLength(embed)).toEqual('yeet'.length * 6);
|
||||
});
|
||||
|
||||
test('GIVEN an embed with zero characters THEN returns amount of characters', () => {
|
||||
expect(embedLength({})).toEqual(0);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { APIEmbed } from 'discord-api-types/v10';
|
||||
|
||||
/**
|
||||
* Calculates the length of the embed.
|
||||
* Calculates the length of an embed.
|
||||
*
|
||||
* @param data - The embed data to check
|
||||
*/
|
||||
@@ -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