allmightysauron / ascii-table3 Goto Github PK
View Code? Open in Web Editor NEWBeautiful ASCII table renderer
License: Apache License 2.0
Beautiful ASCII table renderer
License: Apache License 2.0
The library at the current time severely lacks customization. A feature I really need right now is grouping of cells. I need a table that looks something like this (hand-made as an example):
+---------------------------------------+
| Build |
+---------------------------------------+
| x64 | x86 |
+-------+-----------+-------+-----------+
| Name | Time (ms) | Name | Time (ms) |
+-------+-----------+-------+-----------+
| Total | 3 | Total | 4 |
| Deps | 8 | Deps | 5 |
+-------+-----------+-------+-----------+
I understand it isn't a small change to make but I would love it if you would at least consider the idea.
Thanks!
I try to use ascii-table3 using Bun but I got this error
ENOTDIR: Not a directory
path: "/home/joproject0911/Code/typescript/local/unnamed-bot/node_modules/ascii-table3/src/ascii-table3.js/../ascii-table3.styles.json"
syscall: "open"
errno: -20
at new AsciiTable3 (/home/joproject0911/Code/typescript/local/unnamed-bot/node_modules/ascii-table3/src/ascii-table3.js:42:33)
at /home/joproject0911/Code/typescript/local/unnamed-bot/src/services/event.ts:15:24
at _initialize (/home/joproject0911/Code/typescript/local/unnamed-bot/src/services/event.ts:12:24)
at /home/joproject0911/Code/typescript/local/unnamed-bot/src/struct/client.ts:37:12
at registerListeners (/home/joproject0911/Code/typescript/local/unnamed-bot/src/struct/client.ts:35:52)
at /home/joproject0911/Code/typescript/local/unnamed-bot/src/struct/client.ts:31:18
at /home/joproject0911/Code/typescript/local/unnamed-bot/src/struct/client.ts:30:37
at processTicksAndRejections (:1:2602)
I use it to display scoreboard with my discord bot :
using this config :
const table: AsciiTable3 = new AsciiTable3()
.setHeading('#', 'User', 'Kiwi')
.setAlign(1, AlignmentEnum.CENTER)
.setAlign(2, AlignmentEnum.CENTER)
.setAlign(3, AlignmentEnum.RIGHT)
.addRowMatrix(results);
table.setStyle('compact');
As you can see, the 3 first ligne isn't aligned with other ...
Emoji is count as 2, but it take 1 place when it render, so the algorithm add 1 extra space .
Hey, nice pkg, although it doesn't work out-of-the-box.
Offending line is: https://github.com/AllMightySauron/ascii-table3/blob/main/ascii-table3.js#L79
If you change
fs.readFileSync(module.path ? module.path + '/' + STYLES_FILENAME : STYLES_FILENAME, 'utf8')
to
this.styles = require(path.join(__dirname, STYLES_FILENAME));
it works a charm and will always resolve correctly
I wanted to have colored text in cells using chalk
, which adds this type of unicode chars: \x1B[32m<text>\x1B[39m
. The coloring works alright, but it breaks the column width sync between headers & body:
Sample output when all the words in the first column are colored green with chalk.green('text')
:
+----------------------+--------+---------+
| Package | Compat | Version |
+----------------------+--------+---------+
| coveralls | >=6 | 3.1.1 |
| mocha | N/A | N/A |
| nyc | >=8.9 | 15.1.0 |
| release-it | >=10 | 14.11.8 |
+----------------------+--------+---------+
Hi I found this code lines is not necessary while preventing this package from being used in browser context
https://github.com/AllMightySauron/ascii-table3/blob/main/ascii-table3.js#L28
https://github.com/AllMightySauron/ascii-table3/blob/main/ascii-table3.js#L42
You can do this for a more straightforward approach
this.styles = require('./ascii-table3.styles.json');
Have a nice day!
I have a problem with using ascii-table3 with React. After adding the code example from basic usage and trying to npm run start my project i get warning in console: 'Module not found: Error: Can't resolve 'fs' in 'C:\Users******\WebstormProjects\untitled2\node_modules\ascii-table3\src'
ERROR in ./node_modules/ascii-table3/src/ascii-table3.js 27:11-24'.
And I did not find any decisions how to solve it. Earlier in issues you wrote that this problem was solved
Hey, is there any way to run this library in the browser? Apparently it requires the fs module (not available in the browser).
I just noticed during testing that the middle column is slightly off center, despite having .setAlignCenter(true)
I'll attach the code and an image for reference :)
Any advice would be great!
const { updatePosition } = require("../../prisma/levelling/functions");
var { AsciiTable3 } = require("ascii-table3");
module.exports = {
data: {
name: "leaderboard",
description: "View the XP leaderboard",
type: 1,
},
async execute(interaction) {
const leaderboardData = await updatePosition();
if (leaderboardData) {
// Create an ASCII table with compact style
const table = new AsciiTable3("XP Leaderboard");
table
.setHeading("#", "XP", "User")
.setAlignCenter(true)
.setStyle("unicode-round");
// .setStyle("unicode-mix");
// .setStyle("unicode-single")
leaderboardData.forEach((entry, index) => {
table.addRow(index + 1, entry.xp, entry.user.username);
});
// Send the table as a message in Discord
await interaction.reply(`\`\`\`${table.toString()}\`\`\``);
} else if (leaderboardData.length === 0) {
await interaction.reply({
content: "The leaderboard is empty...",
ephemeral: true,
});
} else {
await interaction.reply({
content: "An error occurred while updating the leaderboard.",
ephemeral: true,
});
}
},
};
Hello,
as #7 already started to say, this module is unusable with typescript. You need to define the class again in a d.ts file and link them correctly. This is the minimum that ts recognizes that there is an import:
package.json
:
+ "types": "ascii-table3.d.ts",
ascii-table.d.ts
:
declare module "ascii-table3" {
export class AsciiTable3 {
// list functions signatures here
}
// extra exports here
}
Another idea instead of manually writing the types could be the use of https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html , but this would require some changes on your import algorithm, as then it would generate a circular reference, as it doesn't know the d.ts file.
hello,
trying to compile my small application using npx webpack
for local use and run into this error:
WARNING in ./node_modules/ascii-table3/src/ascii-table3.js 42:49-81
Critical dependency: the request of a dependency is an expression
@ ./node_modules/ascii-table3/index.js 1:0-46
when I go ahead and try running my application, it gives me this error before crashing:
Error: Cannot find module '../ascii-table3.styles.json'
thanks
Is it possible to exclude certain characters from the width computation? This is usefull if the table cells includes markdown syntax e.g. **
that doesn't need to be included in the maxwidth of a column.
Any chance you would consider licensing this under Apache 2 or MIT OS licenses?
We are using ascii-table in a console utility. Upon review by a client's legal department, they are asking us to remove it. I'd rather not..
Thanks for writing this library,
Kurt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.