@flighthq/textsegment 0.5.1-next.731.0ae0aa4 → 0.5.1-next.799.62ef0c7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/textSegmenterBackend.d.ts.map +1 -1
- package/dist/textSegmenterBackend.js +2 -1
- package/dist/textSegmenterBackend.js.map +1 -1
- package/package.json +3 -2
- package/src/textSegment.test.ts +6 -4
- package/src/textSegmentBoundary.test.ts +13 -9
- package/src/textSegmenterBackend.test.ts +4 -2
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/textsegment`. The `@
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/textsegment@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/textsegment@0.5.1-next.799.62ef0c7](https://github.com/flighthq/flight/tree/62ef0c74f09f24177aac3695b2487b2d743d4fe6/packages/textsegment)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/62ef0c74f09f24177aac3695b2487b2d743d4fe6/LICENSE.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegmenterBackend.d.ts","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textSegmenterBackend.d.ts","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGhB,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAQlC,wBAAgB,6BAA6B,IAAI,oBAAoB,CAEpE;AAID,eAAO,MAAM,uBAAuB,EAAE,oBAAsD,CAAC;AAK7F,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,oBAAoB,CAErF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,GAAG,IAAI,CAElF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
1
2
|
// Builds the default web backend: a wrapper over the browser-native Intl.Segmenter. It ships no
|
|
2
3
|
// Unicode tables — the engine already carries them — so the common path costs nothing in bundle
|
|
3
4
|
// weight. Intl.Segmenter instances are cached by (locale, granularity) because constructing one is
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
// engine), segment() returns [] rather than throwing; compose a from-scratch UAX #29 backend into
|
|
6
7
|
// the host for those environments.
|
|
7
8
|
export function createWebTextSegmenterBackend() {
|
|
8
|
-
return { segment: segmentWithIntlSegmenter };
|
|
9
|
+
return createEntity({ segment: segmentWithIntlSegmenter });
|
|
9
10
|
}
|
|
10
11
|
// Stable bundled web provider. Hosts can import this directly when composing their explicit
|
|
11
12
|
// capability object; callers that omit a host receive it as the final fallback.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textSegmenterBackend.js","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textSegmenterBackend.js","sourceRoot":"","sources":["../src/textSegmenterBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAQzD,gGAAgG;AAChG,gGAAgG;AAChG,mGAAmG;AACnG,oGAAoG;AACpG,kGAAkG;AAClG,mCAAmC;AACnC,MAAM,UAAU,6BAA6B;IAC3C,OAAO,YAAY,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,4FAA4F;AAC5F,gFAAgF;AAChF,MAAM,CAAC,MAAM,uBAAuB,GAAyB,6BAA6B,EAAE,CAAC;AAE7F,6FAA6F;AAC7F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ACZ,WAAmC,EACnC,MAAe;IAEf,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC1D,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAElC,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,MAAM,iBAAiB,GAAG,WAAW,KAAK,MAAM,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,MAAM,GAAgB,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5F,4EAA4E;QAC5E,IAAI,iBAAiB;YAAE,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC;QACpE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/textsegment",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.799.62ef0c7",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/
|
|
41
|
+
"@flighthq/entity": "0.5.1-next.799.62ef0c7",
|
|
42
|
+
"@flighthq/types": "0.5.1-next.799.62ef0c7"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"typescript": "^5.3.0"
|
package/src/textSegment.test.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import type { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
1
3
|
import type {
|
|
2
4
|
HasTextSegmenter,
|
|
3
5
|
TextSegment,
|
|
@@ -45,12 +47,12 @@ describe('segmentGraphemes', () => {
|
|
|
45
47
|
|
|
46
48
|
it('threads the locale argument to the active backend', () => {
|
|
47
49
|
let seenLocale: string | undefined = 'unset';
|
|
48
|
-
const fake
|
|
50
|
+
const fake = createEntity<Omit<TextSegmenterBackend, typeof EntityRuntimeKey>>({
|
|
49
51
|
segment(text: string, _granularity: TextSegmentGranularity, locale?: string): readonly TextSegment[] {
|
|
50
52
|
seenLocale = locale;
|
|
51
53
|
return [{ start: 0, end: text.length, text }];
|
|
52
54
|
},
|
|
53
|
-
};
|
|
55
|
+
});
|
|
54
56
|
setTextSegmenterBackend(fake);
|
|
55
57
|
segmentGraphemes('hi', 'de-DE');
|
|
56
58
|
expect(seenLocale).toBe('de-DE');
|
|
@@ -62,9 +64,9 @@ function segmenterHost(segmenter: TextSegmenterBackend): HasTextSegmenter {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
function taggingBackend(tag: string): TextSegmenterBackend {
|
|
65
|
-
return {
|
|
67
|
+
return createEntity({
|
|
66
68
|
segment: () => [{ start: 0, end: tag.length, text: tag }],
|
|
67
|
-
};
|
|
69
|
+
});
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
describe('segmentSentences', () => {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import type { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
1
3
|
import type { HasTextSegmenter, TextSegmenterBackend } from '@flighthq/types/contract';
|
|
2
4
|
|
|
3
5
|
import {
|
|
@@ -71,11 +73,11 @@ describe('getPreviousWordBoundary', () => {
|
|
|
71
73
|
|
|
72
74
|
describe('getWordRangeAt', () => {
|
|
73
75
|
it('threads an explicit host through the boundary helper', () => {
|
|
74
|
-
const explicit
|
|
76
|
+
const explicit = createEntity<Omit<TextSegmenterBackend, typeof EntityRuntimeKey>>({
|
|
75
77
|
segment: (text) => [{ start: 0, end: text.length, text, isWordLike: true }],
|
|
76
|
-
};
|
|
78
|
+
});
|
|
77
79
|
const host: HasTextSegmenter = { text: { segmenter: explicit } };
|
|
78
|
-
setTextSegmenterBackend({ segment: () => [] });
|
|
80
|
+
setTextSegmenterBackend(createEntity({ segment: () => [] }));
|
|
79
81
|
expect(getWordRangeAt('word', 1, undefined, host)).toEqual({ start: 0, end: 4 });
|
|
80
82
|
});
|
|
81
83
|
|
|
@@ -97,12 +99,14 @@ describe('getWordRangeAt', () => {
|
|
|
97
99
|
|
|
98
100
|
it('threads the locale to the active backend', () => {
|
|
99
101
|
let seenLocale: string | undefined = 'unset';
|
|
100
|
-
setTextSegmenterBackend(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
setTextSegmenterBackend(
|
|
103
|
+
createEntity<Omit<TextSegmenterBackend, typeof EntityRuntimeKey>>({
|
|
104
|
+
segment(text, _granularity, locale) {
|
|
105
|
+
seenLocale = locale;
|
|
106
|
+
return [{ start: 0, end: text.length, text, isWordLike: true }];
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
106
110
|
getWordRangeAt('word', 1, 'ja-JP');
|
|
107
111
|
expect(seenLocale).toBe('ja-JP');
|
|
108
112
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import type { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
1
3
|
import type {
|
|
2
4
|
HasTextSegmenter,
|
|
3
5
|
TextSegment,
|
|
@@ -18,13 +20,13 @@ interface RecordingBackend extends TextSegmenterBackend {
|
|
|
18
20
|
|
|
19
21
|
function recordingBackend(): RecordingBackend {
|
|
20
22
|
const calls: RecordingBackend['calls'] = [];
|
|
21
|
-
return {
|
|
23
|
+
return createEntity<Omit<RecordingBackend, typeof EntityRuntimeKey>>({
|
|
22
24
|
calls,
|
|
23
25
|
segment(text: string, granularity: TextSegmentGranularity, locale?: string): readonly TextSegment[] {
|
|
24
26
|
calls.push({ text, granularity, locale });
|
|
25
27
|
return [{ start: 0, end: text.length, text }];
|
|
26
28
|
},
|
|
27
|
-
};
|
|
29
|
+
});
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
afterEach(() => setTextSegmenterBackend(null));
|