1 | ;
|
2 |
|
3 | var eaw = require('eastasianwidth');
|
4 |
|
5 | module.exports = function (str) {
|
6 | var i, code, width = 0;
|
7 | for(i = 0; i < str.length; i+=1) {
|
8 | code = eaw.eastAsianWidth(str.charAt(i));
|
9 | switch(code) {
|
10 | case 'F':
|
11 | case 'W':
|
12 | width += 2;
|
13 | break;
|
14 | case 'H':
|
15 | case 'Na':
|
16 | case 'N':
|
17 | width += 1;
|
18 | break;
|
19 | case 'A':
|
20 | width += 1;
|
21 | break;
|
22 | }
|
23 | }
|
24 | return width;
|
25 | };
|