Skip to content

Commit 21cd789

Browse files
authored
remove deprecated and never used APIs (#72)
* remove deprecated (never used) APIs * add changeset * remove related tests
1 parent 483d258 commit 21cd789

File tree

5 files changed

+13
-133
lines changed

5 files changed

+13
-133
lines changed

.changeset/silver-flowers-refuse.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"unicode-segmenter": minor
3+
---
4+
5+
Removed deprecated APIs
6+
7+
- `searchGrapheme` in `unicode-segmenter/grapheme`
8+
- `takeChar` and `takeCodePoint` in `unicode-segmenter/utils`
9+
10+
Which are used internally before, but never from outside.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Since [Hermes doesn't support the `Intl.Segmenter` API](https://github.com/faceb
254254

255255
| Name | Unicode® | ESM? | Size | Size (min) | Size (min+gzip) | Size (min+br) |
256256
|------------------------------|----------|------|----------:|-----------:|----------------:|--------------:|
257-
| `unicode-segmenter/grapheme` | 16.0.0 | ✔️ | 15,929 | 12,110 | 5,049 | 3,740 |
257+
| `unicode-segmenter/grapheme` | 16.0.0 | ✔️ | 15,929 | 12,110 | 5,050 | 3,738 |
258258
| `graphemer` | 15.0.0 | ✖️ ️| 410,435 | 95,104 | 15,752 | 10,660 |
259259
| `grapheme-splitter` | 10.0.0 | ✖️ | 122,252 | 23,680 | 7,852 | 4,841 |
260260
| `@formatjs/intl-segmenter`* | 15.0.0 | ✖️ | 491,043 | 318,721 | 54,248 | 34,380 |
@@ -270,7 +270,7 @@ Since [Hermes doesn't support the `Intl.Segmenter` API](https://github.com/faceb
270270

271271
| Name | Bytecode size | Bytecode size (gzip)* |
272272
|------------------------------|--------------:|----------------------:|
273-
| `unicode-segmenter/grapheme` | 23,037 | 12,058 |
273+
| `unicode-segmenter/grapheme` | 21,997 | 11,505 |
274274
| `graphemer` | 133,952 | 31,708 |
275275
| `grapheme-splitter` | 63,813 | 19,123 |
276276

src/grapheme.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,7 @@ import { consonant_ranges } from './_incb_data.js';
3131
* @typedef {import('./core.js').Segmenter<GraphemeSegmentExtra>} GraphemeSegmenter
3232
*/
3333

34-
export {
35-
/**
36-
* @deprecated DO NOT USE directly, will be removed in v1
37-
*/
38-
searchGraphemeCategory as searchGrapheme,
39-
GraphemeCategory,
40-
};
41-
42-
/**
43-
* @deprecated DO NOT USE directly, will be removed in v1
44-
* @param {number} cp
45-
* @return A {@link GraphemeCategoryRange} value if found, or garbage value with {@link GC_Any} category.
46-
*/
47-
export function searchGraphemeCategory(cp) {
48-
let index = findUnicodeRangeIndex(cp, grapheme_ranges);
49-
if (index < 0) {
50-
return [0, 0, 0 /* GC_Any */];
51-
}
52-
return grapheme_ranges[index];
53-
}
34+
export { GraphemeCategory };
5435

5536
/**
5637
* Unicode segmentation by extended grapheme rules.

src/utils.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,5 @@
11
// @ts-check
22

3-
/**
4-
* Take a Unicode code point from the given input by cursor
5-
*
6-
* @deprecated
7-
* Use this only if `String.prototype.codePointAt()` isn't available on the host environment
8-
*
9-
* @param {string} input
10-
* @param {number} cursor
11-
* @param {number} [length] length of input
12-
* @return {number} a code point of the character
13-
*/
14-
export function takeCodePoint(input, cursor, length = input.length) {
15-
let hi = input.charCodeAt(cursor);
16-
if (isHighSurrogate(hi)) {
17-
if (cursor + 1 < length) {
18-
let lo = input.charCodeAt(cursor + 1);
19-
if (isLowSurrogate(lo)) {
20-
return surrogatePairToCodePoint(hi, lo);
21-
}
22-
}
23-
}
24-
return hi;
25-
}
26-
27-
/**
28-
* Take a UTF-8 char from the given input by cursor
29-
*
30-
* @deprecated
31-
* Use this only if `String.fromCodePoint()` isn't available on the host environment
32-
*
33-
* @param {string} input
34-
* @param {number} cursor
35-
* @param {number} [length] length of input
36-
* @return {string} a UTF-8 character (its `.length` will be 1 or 2)
37-
*/
38-
export function takeChar(input, cursor, length = input.length) {
39-
let hi = input.charCodeAt(cursor);
40-
if (isHighSurrogate(hi)) {
41-
if (cursor + 1 < length) {
42-
let lo = input.charCodeAt(cursor + 1);
43-
if (isLowSurrogate(lo)) {
44-
// This seems to be much slower in V8
45-
// return String.fromCharCode(hi, lo);
46-
return String.fromCharCode(hi) + String.fromCharCode(lo);
47-
}
48-
}
49-
}
50-
return String.fromCharCode(hi);
51-
}
52-
533
/**
544
* @param {number} c UTF-16 code point
555
*/

test/utils.js

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// @ts-check
22

33
import { test } from 'node:test';
4-
import * as assert from 'node:assert/strict';
54
import fc from 'fast-check';
65

76
import {
8-
takeChar,
9-
takeCodePoint,
107
isBMP,
118
isSMP,
129
isSIP,
@@ -20,64 +17,6 @@ fc.configureGlobal({
2017
numRuns: 100_000,
2118
});
2219

23-
test('takeChar', async t => {
24-
await t.test('ascii', () => {
25-
fc.assert(
26-
fc.property(
27-
fc.string({ unit: 'binary-ascii', minLength: 1, maxLength: 1 }),
28-
// @ts-ignore
29-
fc.string({ unit: 'grapheme' }),
30-
(data, extra) => {
31-
return takeChar(data + extra, 0).length === 1;
32-
}
33-
),
34-
);
35-
});
36-
37-
await t.test('over BMP', () => {
38-
fc.assert(
39-
fc.property(
40-
fc.integer({ min: 0xffff + 1, max: 0x10ffff }),
41-
// @ts-ignore
42-
fc.string({ unit: 'grapheme' }),
43-
(data, extra) => {
44-
let leading = String.fromCodePoint(data);
45-
return takeChar(leading + extra, 0).length === 2;
46-
},
47-
),
48-
);
49-
});
50-
});
51-
52-
test('takeCodePoint', async t => {
53-
await t.test('ascii', () => {
54-
fc.assert(
55-
fc.property(
56-
fc.string({ unit: 'binary-ascii', minLength: 1, maxLength: 1 }),
57-
// @ts-ignore
58-
fc.string({ unit: 'grapheme' }),
59-
(data, extra) => {
60-
return takeCodePoint(data + extra, 0) === (data + extra).codePointAt(0);
61-
},
62-
),
63-
);
64-
});
65-
66-
await t.test('over BMP', () => {
67-
fc.assert(
68-
fc.property(
69-
fc.integer({ min: 0xffff + 1, max: 0x10ffff }),
70-
// @ts-ignore
71-
fc.string({ unit: 'grapheme' }),
72-
(data, extra) => {
73-
let leading = String.fromCodePoint(data);
74-
return takeCodePoint(leading + extra, 0) === (leading + extra).codePointAt(0);
75-
},
76-
),
77-
);
78-
});
79-
});
80-
8120
test('isBMP', () => {
8221
fc.assert(
8322
fc.property(

0 commit comments

Comments
 (0)