Skip to content

Commit 19d9298

Browse files
authored
Merge pull request #5 from cto-af/update-deps
Update dependencies
2 parents dc2e241 + 0727ec1 commit 19d9298

File tree

8 files changed

+285
-283
lines changed

8 files changed

+285
-283
lines changed

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ module.exports = {
3636
},
3737
},
3838
],
39-
}
39+
};

lib/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* This code point might start an emoji sequence. By default, any code point
66
* with the Emoji property. See TR #51.
77
*/
8-
export const POTENTIAL_EMOJI = 14
8+
export const POTENTIAL_EMOJI = 14;
99

1010
/**
1111
* This code point is Ambiguous with respect to East Asian Width. In CJK
1212
* contexts, it has a width of 2, rather than 1.
1313
*/
14-
export const AMBIGUOUS = 15
14+
export const AMBIGUOUS = 15;

lib/index.js

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {AMBIGUOUS, POTENTIAL_EMOJI} from './constants.js'
2-
import {Width} from './widths.js'
3-
import emojiRegex from 'emoji-regex'
1+
import {AMBIGUOUS, POTENTIAL_EMOJI} from './constants.js';
2+
import {Width} from './widths.js';
3+
import emojiRegex from 'emoji-regex';
44

5-
const ASCII_REGEX = /^[\x20-\x7e]*$/
6-
const DEFAULT_LOCALE = new Intl.Segmenter().resolvedOptions().locale
7-
const EMOJI_REGEX = emojiRegex()
5+
const ASCII_REGEX = /^[\x20-\x7e]*$/;
6+
const DEFAULT_LOCALE = new Intl.Segmenter().resolvedOptions().locale;
7+
const EMOJI_REGEX = emojiRegex();
88

99
export {
1010
AMBIGUOUS,
1111
POTENTIAL_EMOJI,
12-
}
12+
};
1313

1414
/**
1515
* @typedef {object} ExtraWidths
@@ -27,9 +27,9 @@ export {
2727
*/
2828
const NO_EXTRAS = {
2929
get(/** @type {number} */ _n) {
30-
return undefined
30+
return undefined;
3131
},
32-
}
32+
};
3333

3434
/**
3535
* @typedef {object} StringWidthOptions
@@ -44,9 +44,9 @@ const NO_EXTRAS = {
4444
*/
4545

4646
export class StringWidth {
47-
#graphemes
48-
#isCJK
49-
#extraWidths
47+
#graphemes;
48+
#isCJK;
49+
#extraWidths;
5050

5151
/**
5252
* Create a StringWidth instance.
@@ -62,19 +62,19 @@ export class StringWidth {
6262
extraWidths: NO_EXTRAS,
6363
isCJK: false,
6464
...opts,
65-
}
65+
};
6666
this.#graphemes = new Intl.Segmenter(options.locale, {
6767
granularity: 'grapheme',
68-
})
68+
});
6969
if (typeof opts.isCJK === 'boolean') {
70-
this.#isCJK = opts.isCJK
70+
this.#isCJK = opts.isCJK;
7171
} else {
72-
const loc = new Intl.Locale(this.locale).maximize()
72+
const loc = new Intl.Locale(this.locale).maximize();
7373
// Script is never undefined after going through Segmenter
7474
this.#isCJK = ['Hans', 'Hant', 'Kore', 'Jpan']
75-
.includes(/** @type {string} */ (loc.script))
75+
.includes(/** @type {string} */ (loc.script));
7676
}
77-
this.#extraWidths = options.extraWidths
77+
this.#extraWidths = options.extraWidths;
7878
}
7979

8080
/**
@@ -84,7 +84,7 @@ export class StringWidth {
8484
* @readonly
8585
*/
8686
get isCJK() {
87-
return this.#isCJK
87+
return this.#isCJK;
8888
}
8989

9090
/**
@@ -93,7 +93,7 @@ export class StringWidth {
9393
* @readonly
9494
*/
9595
get locale() {
96-
return this.#graphemes.resolvedOptions().locale
96+
return this.#graphemes.resolvedOptions().locale;
9797
}
9898

9999
/**
@@ -103,7 +103,7 @@ export class StringWidth {
103103
*/
104104
*graphemes(str) {
105105
for (const {segment} of this.#graphemes.segment(str)) {
106-
yield segment
106+
yield segment;
107107
}
108108
}
109109

@@ -115,16 +115,16 @@ export class StringWidth {
115115
#segmentWidth(segment) {
116116
// First codepoint in the grapheme. Usually all the rest will be
117117
// combining characters, unless this is an RI or an emoji sequence.
118-
const cp = /** @type {number} */ (segment.codePointAt(0))
119-
const w = this.#extraWidths.get(cp) ?? Width.get(cp)
118+
const cp = /** @type {number} */ (segment.codePointAt(0));
119+
const w = this.#extraWidths.get(cp) ?? Width.get(cp);
120120
switch (w) {
121121
case POTENTIAL_EMOJI:
122-
EMOJI_REGEX.lastIndex = 0 // Revisit this.
123-
return EMOJI_REGEX.test(segment) ? 2 : 1
122+
EMOJI_REGEX.lastIndex = 0; // Revisit this.
123+
return EMOJI_REGEX.test(segment) ? 2 : 1;
124124
case AMBIGUOUS: // Ambiguous
125-
return this.#isCJK ? 2 : 1
125+
return this.#isCJK ? 2 : 1;
126126
default:
127-
return w
127+
return w;
128128
}
129129
}
130130

@@ -138,14 +138,14 @@ export class StringWidth {
138138
width(str) {
139139
// Fast-path shortcut for all-ASCII
140140
if (ASCII_REGEX.test(str)) {
141-
return str.length
141+
return str.length;
142142
}
143143

144-
let ret = 0
144+
let ret = 0;
145145
for (const segment of this.graphemes(str)) {
146-
ret += this.#segmentWidth(segment)
146+
ret += this.#segmentWidth(segment);
147147
}
148-
return ret < 0 ? 0 : ret
148+
return ret < 0 ? 0 : ret;
149149
}
150150

151151
/**
@@ -167,53 +167,53 @@ export class StringWidth {
167167
*/
168168
break(str, width) {
169169
if (width < 1) {
170-
throw new RangeError(`Width must be >= 1. Got ${width}.`)
170+
throw new RangeError(`Width must be >= 1. Got ${width}.`);
171171
}
172172

173173
/** @type {WidthBreak[]} */
174-
const ret = []
175-
let string = ''
176-
let cells = 0
174+
const ret = [];
175+
let string = '';
176+
let cells = 0;
177177

178178
// Fast-path shortcut for all-ASCII
179179
if (ASCII_REGEX.test(str)) {
180180
for (cells = 0; cells < str.length; cells += width) {
181-
string = str.slice(cells, cells + width)
181+
string = str.slice(cells, cells + width);
182182
ret.push({
183183
string,
184184
cells: string.length, // Might be less than width for last chunk
185185
last: false,
186-
})
186+
});
187187
}
188188
} else {
189189
for (const segment of this.graphemes(str)) {
190-
const w = this.#segmentWidth(segment)
190+
const w = this.#segmentWidth(segment);
191191
if (w > width) {
192192
// Skinny width, fat grapheme cluster
193193
if (cells > 0) {
194-
ret.push({string, cells, last: false})
195-
string = ''
196-
cells = 0
194+
ret.push({string, cells, last: false});
195+
string = '';
196+
cells = 0;
197197
}
198-
ret.push({string: segment, cells: w, last: false})
198+
ret.push({string: segment, cells: w, last: false});
199199
} else if (cells + w > width) {
200-
ret.push({string, cells, last: false})
201-
string = segment
202-
cells = w
200+
ret.push({string, cells, last: false});
201+
string = segment;
202+
cells = w;
203203
} else {
204-
string += segment
205-
cells += w
204+
string += segment;
205+
cells += w;
206206
}
207207
}
208208
if (cells > 0) {
209-
ret.push({string, cells, last: true})
209+
ret.push({string, cells, last: true});
210210
}
211211
}
212212

213213
// Several paths lead here.
214214
if (ret.length > 0) {
215-
ret[ret.length - 1].last = true
215+
ret[ret.length - 1].last = true;
216216
}
217-
return ret
217+
return ret;
218218
}
219219
}

lib/widths.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Buffer } from 'buffer'
2-
import { UnicodeTrie } from '@cto.af/unicode-trie'
1+
import {Buffer} from 'buffer';
2+
import {UnicodeTrie} from '@cto.af/unicode-trie';
33

4-
export const version = '15.0.0'
5-
export const inputFileDate = new Date('2022-08-05T22:17:05.000Z')
6-
export const generatedDate = new Date('2023-06-17T16:24:28.610Z')
4+
export const version = '15.0.0';
5+
export const inputFileDate = new Date('2022-08-05T22:17:05.000Z');
6+
export const generatedDate = new Date('2023-07-14T22:30:33.209Z');
77
export const Width = new UnicodeTrie(Buffer.from(
88
`AAARAAAAAADdBAAAGx95MJ4Jts2CbayTN4fNM2YRXbY9d4GqY3iCF4gAAHWynzUpqFcLIMD/
99
d+1TX5FlY+LXCARlVrgCTwHl6pJCPc1/uZ8maVnYPetMVaWq9NUvn1NEeGIXX6+R8yD4EARB
@@ -30,11 +30,12 @@ export const Width = new UnicodeTrie(Buffer.from(
3030
vXdDGdXjEOj1q4ut+l2J7VgO6W+TmrrcyUA+9O40Ur8Zs+OQ+ueh+//u1HwIbPI8EIxR+qh3
3131
qMXmK8kY6uUBqqrqf8MAiwCAW10D`,
3232
'base64'
33-
))
33+
));
34+
3435
/**
3536
* @type {Record<string, number>}
3637
*/
3738
export const names = Object.fromEntries(
3839
Width.values.map((v, i) => [v, i])
39-
)
40-
export const values = Width.values
40+
);
41+
export const {values} = Width;

0 commit comments

Comments
 (0)