Skip to content

Commit

Permalink
fix(table): full width characters are not aligned correctly (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
FukeKazki authored Feb 11, 2023
1 parent 44e48ea commit 9fea2ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions table/test/special_chars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ cell1 cell2 ふわふわ
cell1 ふわ ふわ cell3 `.slice(1),
);
});

Deno.test("table - special chars - full width & cjk sybmol characters", () => {
assertEquals(
Table.from([
["!、¥", "cell2", "cell3"],
["cell1", "cell2", "|a"],
["cell1", "〜 〜", "cell3"],
])
.padding(1)
.toString(),
`
!、¥ cell2 cell3
cell1 cell2 |a
cell1 〜 〜 cell3`.slice(1),
);
});
6 changes: 5 additions & 1 deletion table/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export const strLength = (str: string): number => {
// chinese characters: \u4e00 - \u9fa5
(charCode >= 19968 && charCode <= 40869) ||
// japanese characters \u3040 - \u30ff
(charCode >= 12352 && charCode <= 12543)
(charCode >= 12352 && charCode <= 12543) ||
// full width characters \uff00 - \uffef
(charCode >= 65280 && charCode <= 65519) ||
// cjk symbol and punctuation characters \u3000 - \u303f
(charCode >= 12288 && charCode <= 12351)
) {
length += 2;
} else {
Expand Down

0 comments on commit 9fea2ac

Please sign in to comment.