@formatjs/intl-segmenter 11.5.2 → 11.5.3

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,8 +1,6 @@
1
- "use strict";
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: segmenter_1.Segmenter,
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var segmenter_1 = require("./src/segmenter");
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: segmenter_1.Segmenter,
5
+ value: Segmenter,
8
6
  enumerable: false,
9
7
  writable: true,
10
8
  configurable: true,
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldPolyfill = void 0;
4
- function shouldPolyfill() {
1
+ export function shouldPolyfill() {
5
2
  return !Intl.Segmenter;
6
3
  }
7
- exports.shouldPolyfill = shouldPolyfill;
@@ -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
- exports.SegmentationRules = {
3
+ export var SegmentationRules = {
7
4
  "de": {
8
5
  "sentence": {
9
6
  "segmentRules": {},
@@ -1,7 +1,4 @@
1
- "use strict";
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
- exports.replaceVariables = replaceVariables;
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
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Segmenter = void 0;
4
- var tslib_1 = require("tslib");
5
- var cldr_segmentation_rules_generated_1 = require("./cldr-segmentation-rules.generated");
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((0, segmentation_utils_1.replaceVariables)(variables, rule)).concat(after ? '' : '$'));
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 = (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales);
51
- options = (0, ecma402_abstract_1.GetOptionsObject)(options);
47
+ var requestedLocales = CanonicalizeLocaleList(locales);
48
+ options = GetOptionsObject(options);
52
49
  var opt = Object.create(null);
53
- var matcher = (0, ecma402_abstract_1.GetOption)(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
50
+ var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
54
51
  opt.localeMatcher = matcher;
55
- var granularity = (0, ecma402_abstract_1.GetOption)(options, 'granularity', 'string', ['word', 'sentence', 'grapheme'], 'grapheme');
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 = (0, intl_localematcher_1.ResolveLocale)(Segmenter.availableLocales, //availible locales
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 = cldr_segmentation_rules_generated_1.SegmentationRules.root[granularity];
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 = cldr_segmentation_rules_generated_1.SegmentationRules[r.locale];
64
+ var localeOverrides = SegmentationRules[r.locale];
68
65
  if (granularity in localeOverrides) {
69
66
  var localeSegmentationTypeValue = localeOverrides[granularity];
70
- this.mergedSegmentationTypeValue.variables = tslib_1.__assign(tslib_1.__assign({}, this.mergedSegmentationTypeValue.variables), localeSegmentationTypeValue.variables);
71
- this.mergedSegmentationTypeValue.segmentRules = tslib_1.__assign(tslib_1.__assign({}, this.mergedSegmentationTypeValue.segmentRules), localeSegmentationTypeValue.segmentRules);
72
- this.mergedSegmentationTypeValue.suppressions = tslib_1.__spreadArray(tslib_1.__spreadArray([], this.mergedSegmentationTypeValue.suppressions, true), localeSegmentationTypeValue.suppressions, true);
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 ((0, segmentation_utils_1.isSurrogate)(input, position)) {
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 tslib_1.__assign({}, (0, ecma402_abstract_1.getMultiInternalSlots)(__INTERNAL_SLOT_MAP__, this, 'locale', 'granularity'));
136
+ return __assign({}, getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'locale', 'granularity'));
140
137
  };
141
138
  Segmenter.supportedLocalesOf = function (locales, options) {
142
- return (0, ecma402_abstract_1.SupportedLocales)(Segmenter.availableLocales, (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales), options);
139
+ return SupportedLocales(Segmenter.availableLocales, CanonicalizeLocaleList(locales), options);
143
140
  };
144
- Segmenter.availableLocales = new Set(Object.keys(cldr_segmentation_rules_generated_1.SegmentationRules).filter(function (key) { return key !== 'root'; }));
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
- exports.Segmenter = Segmenter;
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 (0, ecma402_abstract_1.getInternalSlot)(__INTERNAL_SLOT_MAP__, instance, key);
233
+ return getInternalSlot(__INTERNAL_SLOT_MAP__, instance, key);
237
234
  }
238
235
  function setSlot(instance, key, value) {
239
- (0, ecma402_abstract_1.setInternalSlot)(__INTERNAL_SLOT_MAP__, instance, key, value);
236
+ setInternalSlot(__INTERNAL_SLOT_MAP__, instance, key, value);
240
237
  }
241
238
  function checkReceiver(receiver, methodName) {
242
239
  if (!(receiver instanceof Segmenter)) {
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  // @generated
4
2
  // @ts-nocheck
5
- require("./polyfill-force");
3
+ import './polyfill-force';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-segmenter",
3
- "version": "11.5.2",
3
+ "version": "11.5.3",
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/intl-localematcher": "0.5.1",
24
- "@formatjs/ecma402-abstract": "1.17.4"
23
+ "@formatjs/intl-localematcher": "0.5.2",
24
+ "@formatjs/ecma402-abstract": "1.18.0"
25
25
  },
26
26
  "main": "index.js",
27
27
  "types": "index.d.ts",