console-table-printer icon indicating copy to clipboard operation
console-table-printer copied to clipboard

unicode breaks alignment

Open markg85 opened this issue 3 years ago • 0 comments
trafficstars

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

markg85 avatar Aug 05 '22 19:08 markg85