Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32974282
D7238.1768309032.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D7238.1768309032.diff
View Options
diff --git a/keyserver/src/utils/segmenter.js b/keyserver/src/utils/segmenter.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/utils/segmenter.js
@@ -0,0 +1,52 @@
+// @flow
+
+type SegmenterOptions = {
+ localeMatcher?: 'best fit' | 'lookup',
+ granularity?: 'grapheme' | 'word' | 'sentence',
+};
+
+type ResolvedSegmenterOptions = {
+ locale: string,
+ granularity: 'grapheme' | 'word' | 'sentence',
+};
+
+declare class Segmenter {
+ constructor(
+ locales?: Intl$Locale | Intl$Locale[],
+ options?: SegmenterOptions,
+ ): Segmenter;
+
+ resolvedOptions(): ResolvedSegmenterOptions;
+
+ segment(input: string): Segments;
+}
+
+type SegmentData = {
+ segment: string,
+ index: number,
+ input: string,
+ isWordLike?: boolean,
+};
+
+declare class Segments {
+ containing(codeUnitIndex?: number): SegmentData;
+ @@iterator: () => Iterator<SegmentData>;
+}
+
+type OurIntlType = {
+ +Collator: Class<Intl$Collator>,
+ +DateTimeFormat: Class<Intl$DateTimeFormat>,
+ +NumberFormat: Class<Intl$NumberFormat>,
+ +PluralRules: ?Class<Intl$PluralRules>,
+ +getCanonicalLocales?: (locales?: Intl$Locales) => Intl$Locale[],
+ +Segmenter: Class<Segmenter>,
+};
+
+const OurIntl: OurIntlType = (Intl: any);
+const segmenter = new OurIntl.Segmenter('eng', { granularity: 'word' });
+
+function getSegmenter(): any {
+ return segmenter;
+}
+
+export { getSegmenter };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 13, 12:57 PM (2 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5927866
Default Alt Text
D7238.1768309032.diff (1 KB)
Attached To
Mode
D7238: [keyserver] Add type workaround for Intl.Segmenter
Attached
Detach File
Event Timeline
Log In to Comment