ayonious / console-table-printer

🖥️ 🍭 Printing Pretty Tables on your console
https://console-table.netlify.app
MIT License
172 stars 22 forks source link

unicode breaks alignment #430

Closed markg85 closed 2 years ago

markg85 commented 2 years ago

image

const { printTable } = require('./dist');

//Create a table
const testCases = [
  { index: 3, text: 'I would like some gelb bananen bitte', value: 100 },
  { index: 4, text: 'I hope batch update is working', value: 300 },
  { index: 4, text: 'Unicode.... \uD83C\uDD9E', value: 300 },
];

//print
printTable(testCases);

This might be of interest: https://stackoverflow.com/questions/54369513/how-to-count-the-correct-length-of-a-string-with-emojis-in-javascript

Though the fix likely is [...str].length. Example:

let str = `Unicode.... \uD83C\uDD9E`
console.log(str.length) // 14
console.log([...str].length) // 13
ayonious commented 2 years ago

This is the same as https://github.com/ayonious/console-table-printer/issues/389 Im open to PRs.

ayonious commented 2 years ago

Fixed this in 2.11.1 version

markg85 commented 2 years ago

Sweet! :D Thanx!