File tree 5 files changed +98
-5
lines changed
5 files changed +98
-5
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,17 @@ You can put it to the console or a preformated text-file.
12
12
13
13
When a autoAlign option is set, the numbers are aligned by its fraction point.
14
14
15
+ CHANGES
16
+ -------
17
+
18
+ * v0.3.3 - Bug fix : Measure a width of wide-chars of east asian characters correctly
19
+ by using the npm eastasianwidth.
20
+ * v0.3.2 - Change Test : Support mocha to test.
21
+ * v0.3.1 - Bug fix : Do not count escape sequences in data for column width.
22
+ * v0.3.0 - Enhance : Several columns or rows can be added at a time.
23
+ * v0.2.0 - Enhance : Auto align mode is available.
24
+ * v0.1.0 - Initial release
25
+
15
26
SAMPLE
16
27
------
17
28
@@ -92,6 +103,44 @@ NEPTUNE 102.0 49528 1638 11.0 23.5 16.1
92
103
PLUTO 0.0146 2370 2095 0.7 1.3 -153.3
93
104
```
94
105
106
+ ### East asian characters
107
+
108
+ __ japanese-foods-jp.js__
109
+
110
+ ```
111
+ var listit = require("list-it");
112
+ var buf = listit.buffer();
113
+ console.log(
114
+ buf
115
+ .d("1").d("寿司")
116
+ .d("酢とご飯とシーフード")
117
+ .d("健康的だ").nl()
118
+ .d("2").d("焼肉")
119
+ .d("日本のグリルされたお肉")
120
+ .d("ジューシー").nl()
121
+ .d("3").d("ラーメン")
122
+ .d("日本のスープに入った麺")
123
+ .d("大好き").nl()
124
+ .d("4").d("天ぷら")
125
+ .d("シーフードや野菜に衣をつけて揚げたもの")
126
+ .d("おいしー").nl()
127
+ .d("5").d("刺身")
128
+ .d("大変フレッシュな魚のスライス")
129
+ .d("食べてみて!あご落ちるぜ").nl()
130
+ .toString());
131
+ ```
132
+
133
+ outputs:
134
+
135
+ ```
136
+ $ node sample/japanese-food-jp.js
137
+ 1 寿司 酢とご飯とシーフード 健康的だ
138
+ 2 焼肉 日本のグリルされたお肉 ジューシー
139
+ 3 ラーメン 日本のスープに入った麺 大好き
140
+ 4 天ぷら シーフードや野菜に衣をつけて揚げたもの おいしー
141
+ 5 刺身 大変フレッシュな魚のスライス 食べてみて!あご落ちるぜ
142
+ ```
143
+
95
144
96
145
METHODS
97
146
-------
Original file line number Diff line number Diff line change 1
1
( function ( ) {
2
2
"use strict" ;
3
+ var eaw = require ( 'eastasianwidth' ) ;
3
4
var exports = { } ;
4
5
var privates = { } ;
5
6
130
131
DataCell . prototype . setData = function ( data ) {
131
132
this . data = data ;
132
133
} ;
134
+
133
135
DataCell . prototype . visibleLength = function ( ) {
134
136
if ( typeof ( this . data ) != "string" ) {
135
137
return ( "" + this . data ) . length ;
136
138
}
139
+ return DataCell . visibleLength ( this . data ) ;
140
+ } ;
141
+
142
+ DataCell . visibleLength = function ( data ) {
137
143
// Remove escape sequences for text style from the string
138
- var s = this . data . replace ( / \x1b [ ^ m ] * m / g, '' ) ;
139
- return s . length ;
144
+ var s = data . replace ( / \x1b [ ^ m ] * m / g, '' ) ;
145
+ return eaw . length ( s ) ;
140
146
} ;
141
147
142
148
//
181
187
}
182
188
}
183
189
var s = "" + data ;
184
- while ( s . length < m ) {
190
+ while ( DataCell . visibleLength ( s ) < m ) {
185
191
s += ' ' ;
186
192
}
187
193
return s ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " list-it" ,
3
- "version" : " 0.3.2 " ,
3
+ "version" : " 0.3.3 " ,
4
4
"description" : " This module is used to create a preformatted text table." ,
5
5
"repository" : {
6
6
"type" : " git" ,
29
29
"chai" : " ^3.5.0"
30
30
},
31
31
"dependencies" : {
32
- "ansi-escape-sequences" : " ^2.2.2"
32
+ "ansi-escape-sequences" : " ^2.2.2" ,
33
+ "eastasianwidth" : " ^0.1.1"
33
34
}
34
35
}
Original file line number Diff line number Diff line change
1
+ var listit = require ( "../lib" ) ;
2
+ var buf = listit . buffer ( ) ;
3
+ console . log (
4
+ buf
5
+ . d ( "1" ) . d ( "寿司" )
6
+ . d ( "酢とご飯とシーフード" )
7
+ . d ( "健康的だ" ) . nl ( )
8
+ . d ( "2" ) . d ( "焼肉" )
9
+ . d ( "日本のグリルされたお肉" )
10
+ . d ( "ジューシー" ) . nl ( )
11
+ . d ( "3" ) . d ( "ラーメン" )
12
+ . d ( "日本のスープに入った麺" )
13
+ . d ( "大好き" ) . nl ( )
14
+ . d ( "4" ) . d ( "天ぷら" )
15
+ . d ( "シーフードや野菜に衣をつけて揚げたもの" )
16
+ . d ( "おいしー" ) . nl ( )
17
+ . d ( "5" ) . d ( "刺身" )
18
+ . d ( "大変フレッシュな魚のスライス" )
19
+ . d ( "食べてみて!あご落ちるぜ" ) . nl ( )
20
+ . toString ( ) ) ;
Original file line number Diff line number Diff line change 302
302
} ) ;
303
303
} ) ;
304
304
} ) ;
305
+ describe ( "Measure a width of wide-chars correctly." , function ( ) {
306
+ it ( "All Japanese" , function ( ) {
307
+ var buffer = new listit . buffer ( ) ;
308
+ buffer
309
+ . d ( "1" ) . d ( "寿司" ) . d ( "酢とご飯とシーフード" ) . d ( "健康的だ" ) . nl ( )
310
+ . d ( "2" ) . d ( "焼肉" ) . d ( "日本のグリルされたお肉" ) . d ( "ジューシー" ) . nl ( )
311
+ . d ( "3" ) . d ( "ラーメン" ) . d ( "日本のスープに入った麺" ) . d ( "大好き" ) . nl ( )
312
+ . d ( "4" ) . d ( "天ぷら" ) . d ( "シーフードや野菜に衣をつけて揚げたもの" ) . d ( "おいしー" ) . nl ( )
313
+ . d ( "5" ) . d ( "刺身" ) . d ( "大変フレッシュな魚のスライス" ) . d ( "食べてみて!あご落ちるぜ" ) . nl ( ) ;
314
+ assert . equal ( buffer . toString ( ) ,
315
+ "1 寿司 酢とご飯とシーフード 健康的だ \n" +
316
+ "2 焼肉 日本のグリルされたお肉 ジューシー \n" +
317
+ "3 ラーメン 日本のスープに入った麺 大好き \n" +
318
+ "4 天ぷら シーフードや野菜に衣をつけて揚げたもの おいしー \n" +
319
+ "5 刺身 大変フレッシュな魚のスライス 食べてみて!あご落ちるぜ" ) ;
320
+ } ) ;
321
+ } ) ;
305
322
} ( ( typeof ( describe ) == "function" ) ? describe : false , ( typeof ( it ) == "function" ) ? it : false ) ) ;
You can’t perform that action at this time.
0 commit comments