Skip to content

Commit cbd1a07

Browse files
authored
Deprecate unicode-segmenter/utils entry (#84)
1 parent 6435534 commit cbd1a07

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

.changeset/famous-pianos-help.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"unicode-segmenter": minor
3+
---
4+
5+
Deprecated `unicode-segmenter/utils` entry.
6+
7+
Never used internally anymore. It's too simple, better to inline if needed.

README.md

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ Unicode® Standard Annex \#29 - [Revision 45](https://www.unicode.org/reports/tr
3232

3333
## APIs
3434

35-
There are several entries for text segmentation.
35+
Entries for Unicode text segmentation.
3636

3737
- [`unicode-segmenter/grapheme`](#export-unicode-segmentergrapheme): Segments and counts **extended grapheme clusters**
3838
- [`unicode-segmenter/intl-adapter`](#export-unicode-segmenterintl-adapter): [`Intl.Segmenter`] adapter
3939
- [`unicode-segmenter/intl-polyfill`](#export-unicode-segmenterintl-polyfill): [`Intl.Segmenter`] polyfill
4040

41-
And extra utilities for combined use cases.
41+
And matchers for extra use cases.
4242

4343
- [`unicode-segmenter/emoji`](#export-unicode-segmenteremoji): Matches single codepoint emojis
4444
- [`unicode-segmenter/general`](#export-unicode-segmentergeneral): Matches single codepoint alphanumerics
45-
- [`unicode-segmenter/utils`](#export-unicode-segmenterutils): Some utilities for handling codepoints
4645

4746
### Export `unicode-segmenter/grapheme`
4847
[![](https://edge.bundlejs.com/badge?q=unicode-segmenter/grapheme&treeshake=[*])](https://bundlejs.com/?q=unicode-segmenter%2Fgrapheme&treeshake=%5B*%5D)
@@ -187,42 +186,6 @@ import {
187186
} from 'unicode-segmenter/general';
188187
```
189188

190-
### Export `unicode-segmenter/utils`
191-
[![](https://edge.bundlejs.com/badge?q=unicode-segmenter/utils&treeshake=[*])](https://bundlejs.com/?q=unicode-segmenter%2Futils&treeshake=%5B*%5D)
192-
193-
You can access some internal utilities to deal with JavaScript strings.
194-
195-
#### Example: Handle UTF-16 surrogate pairs
196-
197-
```js
198-
import {
199-
isHighSurrogate,
200-
isLowSurrogate,
201-
surrogatePairToCodePoint,
202-
} from 'unicode-segmenter/utils';
203-
204-
const u32 = '😍';
205-
const hi = u32.charCodeAt(0);
206-
const lo = u32.charCodeAt(1);
207-
208-
if (isHighSurrogate(hi) && isLowSurrogate(lo)) {
209-
const codePoint = surrogatePairToCodePoint(hi, lo);
210-
// => equivalent to u32.codePointAt(0)
211-
}
212-
```
213-
214-
#### Example: Determine the length of a character
215-
216-
```js
217-
import { isBMP } from 'unicode-segmenter/utils';
218-
219-
const char = '😍'; // .length = 2
220-
const cp = char.codePointAt(0);
221-
222-
char.length === isBMP(cp) ? 1 : 2;
223-
// => true
224-
```
225-
226189
## Runtime Compatibility
227190

228191
`unicode-segmenter` uses only fundamental features of ES2015, making it compatible with most browsers.

src/utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
// @ts-check
22

33
/**
4+
* @deprecated never used
5+
*
46
* @param {number} c UTF-16 code point
57
*/
68
export function isHighSurrogate(c) {
79
return 0xd800 <= c && c <= 0xdbff;
810
}
911

1012
/**
13+
* @deprecated never used
14+
*
1115
* @param {number} c UTF-16 code point
1216
*/
1317
export function isLowSurrogate(c) {
1418
return 0xdc00 <= c && c <= 0xdfff;
1519
}
1620

1721
/**
22+
* @deprecated never used
23+
*
1824
* @param {number} hi high surrogate
1925
* @param {number} lo low surrogate
2026
*/
@@ -23,6 +29,8 @@ export function surrogatePairToCodePoint(hi, lo) {
2329
}
2430

2531
/**
32+
* @deprecated never used
33+
*
2634
* Check if given code point is within the BMP(Basic Multilingual Plane)
2735
*
2836
* @param {number} c Unicode code point
@@ -33,6 +41,8 @@ export function isBMP(c) {
3341
}
3442

3543
/**
44+
* @deprecated never used
45+
*
3646
* Check if given code point is within the SMP(Supplementary Multilingual Plane)
3747
*
3848
* @param {number} c Unicode code point
@@ -43,6 +53,8 @@ export function isSMP(c) {
4353
}
4454

4555
/**
56+
* @deprecated never used
57+
*
4658
* Check if given code point is within the SIP(Supplementary Ideographic Plane)
4759
*
4860
* @param {number} c Unicode code point
@@ -53,6 +65,8 @@ export function isSIP(c) {
5365
}
5466

5567
/**
68+
* @deprecated never used
69+
*
5670
* Check if given code point is within the TIP(Tertiary Ideographic Plane)
5771
*
5872
* @param {number} c Unicode code point
@@ -63,6 +77,8 @@ export function isTIP(c) {
6377
}
6478

6579
/**
80+
* @deprecated never used
81+
*
6682
* Check if given code point is within the SSP(Supplementary Special-purpose Plane)
6783
*
6884
* @param {number} c Unicode code point

0 commit comments

Comments
 (0)