@formatjs/intl-segmenter 12.0.7 → 12.0.8

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.
@@ -1,17 +1,14 @@
1
- export var replaceVariables = function (variables, input) {
2
- var findVarRegex = /\$[A-Za-z0-9_]+/gm;
3
- return input.replaceAll(findVarRegex, function (match) {
4
- if (!(match in variables)) {
5
- throw new Error("No such variable ".concat(match));
6
- }
7
- return variables[match];
8
- });
1
+ export const replaceVariables = (variables, input) => {
2
+ const findVarRegex = /\$[A-Za-z0-9_]+/gm;
3
+ return input.replaceAll(findVarRegex, (match) => {
4
+ if (!(match in variables)) {
5
+ throw new Error(`No such variable ${match}`);
6
+ }
7
+ return variables[match];
8
+ });
9
9
  };
10
- export var isSurrogate = function (str, pos) {
11
- return (0xd800 <= str.charCodeAt(pos - 1) &&
12
- str.charCodeAt(pos - 1) <= 0xdbff &&
13
- 0xdc00 <= str.charCodeAt(pos) &&
14
- str.charCodeAt(pos) <= 0xdfff);
10
+ export const isSurrogate = (str, pos) => {
11
+ return 55296 <= str.charCodeAt(pos - 1) && str.charCodeAt(pos - 1) <= 56319 && 56320 <= str.charCodeAt(pos) && str.charCodeAt(pos) <= 57343;
15
12
  };
16
13
  // alternative surrogate check mimicking the java implementation
17
14
  // const TRAIL_SURROGATE_BITMASK = 0xfffffc00
@@ -1,55 +1,55 @@
1
1
  type SegmentResult = {
2
- segment: string;
3
- breakingRule?: string;
4
- nonBreakingRules?: string[];
2
+ segment: string;
3
+ breakingRule?: string;
4
+ nonBreakingRules?: string[];
5
5
  } | undefined;
6
6
  export interface SegmenterOptions {
7
- localeMatcher?: 'lookup' | 'best fit';
8
- granularity?: 'word' | 'sentence' | 'grapheme';
7
+ localeMatcher?: "lookup" | "best fit";
8
+ granularity?: "word" | "sentence" | "grapheme";
9
9
  }
10
10
  export interface SegmenterResolvedOptions {
11
- locale: string;
12
- granularity: NonNullable<SegmenterOptions['granularity']>;
11
+ locale: string;
12
+ granularity: NonNullable<SegmenterOptions["granularity"]>;
13
13
  }
14
14
  declare const breaksAtResult: (breaks: boolean, matchingRule: string) => {
15
- breaks: boolean;
16
- matchingRule: string;
15
+ breaks: boolean;
16
+ matchingRule: string;
17
17
  };
18
18
  export declare class Segmenter {
19
- private readonly rules;
20
- private readonly ruleSortedKeys;
21
- private readonly mergedSegmentationTypeValue;
22
- constructor(locales: string | string[] | undefined, options: SegmenterOptions);
23
- breaksAt(position: number, input: string): ReturnType<typeof breaksAtResult>;
24
- segment(input: string): SegmentIterator;
25
- resolvedOptions(): SegmenterResolvedOptions;
26
- static availableLocales: Set<string>;
27
- static supportedLocalesOf(locales?: string | string[], options?: Pick<SegmenterOptions, 'localeMatcher'>): string[];
28
- static readonly polyfilled = true;
19
+ private readonly rules;
20
+ private readonly ruleSortedKeys;
21
+ private readonly mergedSegmentationTypeValue;
22
+ constructor(locales: string | string[] | undefined, options: SegmenterOptions);
23
+ breaksAt(position: number, input: string): ReturnType<typeof breaksAtResult>;
24
+ segment(input: string): SegmentIterator;
25
+ resolvedOptions(): SegmenterResolvedOptions;
26
+ static availableLocales: Set<string>;
27
+ static supportedLocalesOf(locales?: string | string[], options?: Pick<SegmenterOptions, "localeMatcher">): string[];
28
+ static readonly polyfilled: true;
29
29
  }
30
30
  declare class SegmentIterator implements Iterable<SegmentResult>, Iterator<SegmentResult> {
31
- private readonly segmenter;
32
- private lastSegmentIndex;
33
- private input;
34
- constructor(segmenter: Segmenter, input: string);
35
- [Symbol.iterator](): SegmentIterator;
36
- next(): {
37
- done: boolean;
38
- value: {
39
- segment: string;
40
- index: number;
41
- input: string;
42
- isWordLike?: boolean;
43
- };
44
- } | {
45
- done: boolean;
46
- value: undefined;
47
- };
48
- containing(positionInput: number): {
49
- segment: string;
50
- index: number;
51
- input: string;
52
- isWordLike?: boolean;
53
- } | undefined;
31
+ private readonly segmenter;
32
+ private lastSegmentIndex;
33
+ private input;
34
+ constructor(segmenter: Segmenter, input: string);
35
+ [Symbol.iterator](): SegmentIterator;
36
+ next(): {
37
+ done: boolean;
38
+ value: {
39
+ segment: string;
40
+ index: number;
41
+ input: string;
42
+ isWordLike?: boolean;
43
+ };
44
+ } | {
45
+ done: boolean;
46
+ value: undefined;
47
+ };
48
+ containing(positionInput: number): {
49
+ segment: string;
50
+ index: number;
51
+ input: string;
52
+ isWordLike?: boolean;
53
+ } | undefined;
54
54
  }
55
55
  export type { SegmentIterator };