@formatjs/intl-segmenter 11.5.2 → 11.5.4
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/lib/polyfill-force.js +2 -4
- package/lib/polyfill.js +4 -6
- package/lib/should-polyfill.js +1 -5
- package/lib/src/cldr-segmentation-rules.generated.js +1 -4
- package/lib/src/segmentation-utils.js +2 -7
- package/lib/src/segmenter.js +23 -26
- package/lib/test262-main.js +1 -3
- package/package.json +3 -3
- package/polyfill.iife.js +5921 -9136
package/lib/polyfill-force.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var segmenter_1 = require("./src/segmenter");
|
|
1
|
+
import { Segmenter } from './src/segmenter';
|
|
4
2
|
Object.defineProperty(Intl, 'Segmenter', {
|
|
5
|
-
value:
|
|
3
|
+
value: Segmenter,
|
|
6
4
|
enumerable: false,
|
|
7
5
|
writable: true,
|
|
8
6
|
configurable: true,
|
package/lib/polyfill.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var should_polyfill_1 = require("./should-polyfill");
|
|
5
|
-
if ((0, should_polyfill_1.shouldPolyfill)()) {
|
|
1
|
+
import { Segmenter } from './src/segmenter';
|
|
2
|
+
import { shouldPolyfill } from './should-polyfill';
|
|
3
|
+
if (shouldPolyfill()) {
|
|
6
4
|
Object.defineProperty(Intl, 'Segmenter', {
|
|
7
|
-
value:
|
|
5
|
+
value: Segmenter,
|
|
8
6
|
enumerable: false,
|
|
9
7
|
writable: true,
|
|
10
8
|
configurable: true,
|
package/lib/should-polyfill.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SegmentationRules = void 0;
|
|
4
1
|
/* @generated */
|
|
5
2
|
// prettier-ignore
|
|
6
|
-
|
|
3
|
+
export var SegmentationRules = {
|
|
7
4
|
"de": {
|
|
8
5
|
"sentence": {
|
|
9
6
|
"segmentRules": {},
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSurrogate = exports.replaceVariables = void 0;
|
|
4
|
-
var replaceVariables = function (variables, input) {
|
|
1
|
+
export var replaceVariables = function (variables, input) {
|
|
5
2
|
var findVarRegex = /\$[A-Za-z0-9_]+/gm;
|
|
6
3
|
return input.replaceAll(findVarRegex, function (match) {
|
|
7
4
|
if (!(match in variables)) {
|
|
@@ -10,14 +7,12 @@ var replaceVariables = function (variables, input) {
|
|
|
10
7
|
return variables[match];
|
|
11
8
|
});
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
var isSurrogate = function (str, pos) {
|
|
10
|
+
export var isSurrogate = function (str, pos) {
|
|
15
11
|
return (0xd800 <= str.charCodeAt(pos - 1) &&
|
|
16
12
|
str.charCodeAt(pos - 1) <= 0xdbff &&
|
|
17
13
|
0xdc00 <= str.charCodeAt(pos) &&
|
|
18
14
|
str.charCodeAt(pos) <= 0xdfff);
|
|
19
15
|
};
|
|
20
|
-
exports.isSurrogate = isSurrogate;
|
|
21
16
|
// alternative surrogate check mimicking the java implementation
|
|
22
17
|
// const TRAIL_SURROGATE_BITMASK = 0xfffffc00
|
|
23
18
|
// const TRAIL_SURROGATE_BITS = 0xdc00
|
package/lib/src/segmenter.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var segmentation_utils_1 = require("./segmentation-utils");
|
|
7
|
-
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
8
|
-
var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
|
1
|
+
import { __assign, __spreadArray } from "tslib";
|
|
2
|
+
import { SegmentationRules } from './cldr-segmentation-rules.generated';
|
|
3
|
+
import { replaceVariables, isSurrogate } from './segmentation-utils';
|
|
4
|
+
import { GetOption, SupportedLocales, CanonicalizeLocaleList, GetOptionsObject, getInternalSlot, setInternalSlot, getMultiInternalSlots, } from '@formatjs/ecma402-abstract';
|
|
5
|
+
import { ResolveLocale } from '@formatjs/intl-localematcher';
|
|
9
6
|
/**
|
|
10
7
|
* Adds $ to before rules and ^ to after rules for strickness
|
|
11
8
|
* Replaces variables
|
|
@@ -17,7 +14,7 @@ var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
|
|
17
14
|
* @returns
|
|
18
15
|
*/
|
|
19
16
|
var generateRuleRegex = function (rule, variables, after) {
|
|
20
|
-
return new RegExp("".concat(after ? '^' : '').concat(
|
|
17
|
+
return new RegExp("".concat(after ? '^' : '').concat(replaceVariables(variables, rule)).concat(after ? '' : '$'));
|
|
21
18
|
};
|
|
22
19
|
var prepareLocaleSegmentationRules = function (segmentationTypeValue) {
|
|
23
20
|
var preparedRules = {};
|
|
@@ -47,29 +44,29 @@ var Segmenter = /** @class */ (function () {
|
|
|
47
44
|
if (_newTarget === undefined) {
|
|
48
45
|
throw TypeError("Constructor Intl.Segmenter requires 'new'");
|
|
49
46
|
}
|
|
50
|
-
var requestedLocales =
|
|
51
|
-
options =
|
|
47
|
+
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
48
|
+
options = GetOptionsObject(options);
|
|
52
49
|
var opt = Object.create(null);
|
|
53
|
-
var matcher =
|
|
50
|
+
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
54
51
|
opt.localeMatcher = matcher;
|
|
55
|
-
var granularity =
|
|
52
|
+
var granularity = GetOption(options, 'granularity', 'string', ['word', 'sentence', 'grapheme'], 'grapheme');
|
|
56
53
|
setSlot(this, 'granularity', granularity);
|
|
57
54
|
//TODO: figure out correct availible locales
|
|
58
|
-
var r =
|
|
55
|
+
var r = ResolveLocale(Segmenter.availableLocales, //availible locales
|
|
59
56
|
requestedLocales, opt, [], // there is no relevantExtensionKeys
|
|
60
57
|
{}, function () { return ''; } //use only root rules
|
|
61
58
|
);
|
|
62
59
|
setSlot(this, 'locale', r.locale);
|
|
63
60
|
//root rules based on granularity
|
|
64
|
-
this.mergedSegmentationTypeValue =
|
|
61
|
+
this.mergedSegmentationTypeValue = SegmentationRules.root[granularity];
|
|
65
62
|
//merge root rules with locale ones if locale is specified
|
|
66
63
|
if (r.locale.length) {
|
|
67
|
-
var localeOverrides =
|
|
64
|
+
var localeOverrides = SegmentationRules[r.locale];
|
|
68
65
|
if (granularity in localeOverrides) {
|
|
69
66
|
var localeSegmentationTypeValue = localeOverrides[granularity];
|
|
70
|
-
this.mergedSegmentationTypeValue.variables =
|
|
71
|
-
this.mergedSegmentationTypeValue.segmentRules =
|
|
72
|
-
this.mergedSegmentationTypeValue.suppressions =
|
|
67
|
+
this.mergedSegmentationTypeValue.variables = __assign(__assign({}, this.mergedSegmentationTypeValue.variables), localeSegmentationTypeValue.variables);
|
|
68
|
+
this.mergedSegmentationTypeValue.segmentRules = __assign(__assign({}, this.mergedSegmentationTypeValue.segmentRules), localeSegmentationTypeValue.segmentRules);
|
|
69
|
+
this.mergedSegmentationTypeValue.suppressions = __spreadArray(__spreadArray([], this.mergedSegmentationTypeValue.suppressions, true), localeSegmentationTypeValue.suppressions, true);
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
//prepare rules
|
|
@@ -91,7 +88,7 @@ var Segmenter = /** @class */ (function () {
|
|
|
91
88
|
}
|
|
92
89
|
//artificial rule 0.1: js specific, due to es5 regex not being unicode aware
|
|
93
90
|
//number 0.1 chosen to mimic java implementation, but needs to execute after 0.2 and 0.3 to be inside the string bounds
|
|
94
|
-
if (
|
|
91
|
+
if (isSurrogate(input, position)) {
|
|
95
92
|
return breaksAtResult(false, '0.1');
|
|
96
93
|
}
|
|
97
94
|
var stringBeforeBreak = input.substring(0, position);
|
|
@@ -136,16 +133,16 @@ var Segmenter = /** @class */ (function () {
|
|
|
136
133
|
};
|
|
137
134
|
Segmenter.prototype.resolvedOptions = function () {
|
|
138
135
|
checkReceiver(this, 'resolvedOptions');
|
|
139
|
-
return
|
|
136
|
+
return __assign({}, getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'locale', 'granularity'));
|
|
140
137
|
};
|
|
141
138
|
Segmenter.supportedLocalesOf = function (locales, options) {
|
|
142
|
-
return
|
|
139
|
+
return SupportedLocales(Segmenter.availableLocales, CanonicalizeLocaleList(locales), options);
|
|
143
140
|
};
|
|
144
|
-
Segmenter.availableLocales = new Set(Object.keys(
|
|
141
|
+
Segmenter.availableLocales = new Set(Object.keys(SegmentationRules).filter(function (key) { return key !== 'root'; }));
|
|
145
142
|
Segmenter.polyfilled = true;
|
|
146
143
|
return Segmenter;
|
|
147
144
|
}());
|
|
148
|
-
|
|
145
|
+
export { Segmenter };
|
|
149
146
|
var createSegmentDataObject = function (segmenter, segment, index, input, matchingRule) {
|
|
150
147
|
var returnValue = {
|
|
151
148
|
segment: segment,
|
|
@@ -233,10 +230,10 @@ var SegmentIterator = /** @class */ (function () {
|
|
|
233
230
|
}());
|
|
234
231
|
var __INTERNAL_SLOT_MAP__ = new WeakMap();
|
|
235
232
|
function getSlot(instance, key) {
|
|
236
|
-
return
|
|
233
|
+
return getInternalSlot(__INTERNAL_SLOT_MAP__, instance, key);
|
|
237
234
|
}
|
|
238
235
|
function setSlot(instance, key, value) {
|
|
239
|
-
|
|
236
|
+
setInternalSlot(__INTERNAL_SLOT_MAP__, instance, key, value);
|
|
240
237
|
}
|
|
241
238
|
function checkReceiver(receiver, methodName) {
|
|
242
239
|
if (!(receiver instanceof Segmenter)) {
|
package/lib/test262-main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-segmenter",
|
|
3
|
-
"version": "11.5.
|
|
3
|
+
"version": "11.5.4",
|
|
4
4
|
"description": "Polyfill for Intl.Segmenter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"tslib": "^2.4.0",
|
|
23
|
-
"@formatjs/
|
|
24
|
-
"@formatjs/
|
|
23
|
+
"@formatjs/ecma402-abstract": "1.18.1",
|
|
24
|
+
"@formatjs/intl-localematcher": "0.5.3"
|
|
25
25
|
},
|
|
26
26
|
"main": "index.js",
|
|
27
27
|
"types": "index.d.ts",
|