GithubHelp home page GithubHelp logo

treefarmer / embed-table Goto Github PK

View Code? Open in Web Editor NEW
12.0 0.0 1.0 457 KB

Easily make nice looking text tables for Discord's embed fields and descriptions.

Home Page: https://www.npmjs.com/package/embed-table

License: MIT License

TypeScript 100.00%
discord discordjs messageembed table

embed-table's Introduction

Embed-Table

Easily make nice looking text tables for Discord's embed fields and descriptions.

Installation

Install with npm install embed-table and it will be installed.

Important

  • titles are the column titles that will display in the name value of the Embed Field. The titleIndexes are the indexes of where the titles start in the generated string, it is recommended to have the first title at 0. See example below.
  • If the start values are not greater than the previous column name, an error will be thrown about an invalid count value.
  • Make sure that your titles, titleIndexes and columnIndexes all are the same number of values, or else things get messy. An option to make the field inline is available since the method creates a complete field object.
  • It is easiet to manage where your data lines up in the columns when using backticks ( ` ) at the start and end of the rows, this makes any character the same width.

Basic Usage (with Discord.js v14+)

import { Table } from 'embed-table';
import { EmbedBuilder } from 'discord.js';

const table = new Table({
  titles: ['Level', 'Money', 'Wins'],
  titleIndexes: [0, 8, 16],
  columnIndexes: [0, 6, 14],
  start: '`',
  end: '`',
  padEnd: 3
});

table.addRow(['1', '$120', '2'], { override: 4 });
table.addRow(['72', '$10', '25'], { override: 0 });
table.addRow(['614', '$1220', '12']);

// Use this 'embed' when sending a message to a channel.
const embed = new EmbedBuilder().setFields(table.toField());

// Use this 'tableString' in a plain text area, (embed description or a regular message)
const string = table.toString();

Embed Output

output

API

Read the documentation for embed-table @ embed-table.treefarmer.xyz

Contributing

Feel free to contribute however, it is appreciated! Join the community server @ treefarmer.xyz/discord

embed-table's People

Contributors

53p avatar fyrlex avatar touratica avatar uriei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

touratica

embed-table's Issues

No support for require()

The package is setup as an ES Module, with no support for CommonJS. Projects using CommonJS use require() for importing, which is not supported for ES Modules.

Unable to generate titleIndexes dynamically

First of all thanks for the wonderful tool. I'm trying to make use of this.

In my case, titleIndexes will have to be dynamically populated based on the max length of the data. I was able to successfully make columnIndexes dynamic but it is not adjusting well with the titleIndexes. Please refer to the below screenshot.

image

Hope you can understand what I mean from the screenshot.

tsc "Can't find RowData"

Hi, while trying to transpile with tsc I get this error.

node_modules/embed-table/dist/structures/Row.d.ts:1:25 - error TS2307: Cannot find module 'index.js' or its corresponding type declarations.

1 import { RowData } from 'index.js';
                          ~~~~~~~~~~

image

Using:

Indexes cannot be alligned on all screen sizes

I can get the titleIndexes and columnIndexes pretty much alligned on desktop, but checking my mobile app, the indents are a different size so the data is now off. Any suggestions for fixing this will help my OCD :)

Package installation requires tsc to be installed globally

When I was trying to install v4.0.5 (was using v3.0.0), the command failed with the error sh: 1: tsc: not found. Through this error, I made the assumption I had to had typescript installed globally and, sure enough, once I did install it with npm i -g typescript, installation went without further issues.

Handling special characters

Is there any proper way to handle special characters?

Example:
image

Btw, thanks for such amazing tool, been using it for my bots and besides this issue, it works flawlessly!

Install Error

This happens when i try npm i embed-table

One is replit and the other is another host:

Screenshot_20221130-043707-1
Screenshot_20221130-043740-1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.