@formatjs/intl-segmenter 11.7.2 → 11.7.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.
@@ -5,4 +5,3 @@ Object.defineProperty(Intl, 'Segmenter', {
5
5
  writable: true,
6
6
  configurable: true,
7
7
  });
8
- //# sourceMappingURL=polyfill-force.js.map
package/lib/polyfill.js CHANGED
@@ -8,4 +8,3 @@ if (shouldPolyfill()) {
8
8
  configurable: true,
9
9
  });
10
10
  }
11
- //# sourceMappingURL=polyfill.js.map
@@ -1,4 +1,3 @@
1
1
  export function shouldPolyfill() {
2
2
  return !Intl.Segmenter;
3
3
  }
4
- //# sourceMappingURL=should-polyfill.js.map
@@ -1264,4 +1264,3 @@ export var SegmentationRules = {
1264
1264
  },
1265
1265
  "zh": {}
1266
1266
  };
1267
- //# sourceMappingURL=cldr-segmentation-rules.generated.js.map
@@ -30,4 +30,3 @@ export var isSurrogate = function (str, pos) {
30
30
  // return false
31
31
  // }
32
32
  // }
33
- //# sourceMappingURL=segmentation-utils.js.map
@@ -268,4 +268,3 @@ try {
268
268
  catch (e) {
269
269
  // Meta fix so we're test262-compliant, not important
270
270
  }
271
- //# sourceMappingURL=segmenter.js.map
@@ -1,4 +1,3 @@
1
1
  // @generated
2
2
  // @ts-nocheck
3
3
  import './polyfill-force';
4
- //# sourceMappingURL=test262-main.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-segmenter",
3
- "version": "11.7.2",
3
+ "version": "11.7.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",
23
- "@formatjs/intl-localematcher": "0.5.7",
24
- "@formatjs/ecma402-abstract": "2.2.2"
23
+ "@formatjs/intl-localematcher": "0.5.8",
24
+ "@formatjs/ecma402-abstract": "2.2.4"
25
25
  },
26
26
  "main": "index.js",
27
27
  "types": "index.d.ts",
package/polyfill-force.js CHANGED
@@ -7,4 +7,3 @@ Object.defineProperty(Intl, 'Segmenter', {
7
7
  writable: true,
8
8
  configurable: true,
9
9
  });
10
- //# sourceMappingURL=polyfill-force.js.map
package/polyfill.iife.js CHANGED
@@ -4450,6 +4450,50 @@
4450
4450
  };
4451
4451
  }
4452
4452
 
4453
+ // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/CanonicalizeUValue.js
4454
+ function CanonicalizeUValue(ukey, uvalue) {
4455
+ var lowerValue = uvalue.toLowerCase();
4456
+ invariant(ukey !== void 0, "ukey must be defined");
4457
+ var canonicalized = lowerValue;
4458
+ return canonicalized;
4459
+ }
4460
+
4461
+ // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/CanonicalizeUnicodeLocaleId.js
4462
+ function CanonicalizeUnicodeLocaleId(locale) {
4463
+ return Intl.getCanonicalLocales(locale)[0];
4464
+ }
4465
+
4466
+ // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/InsertUnicodeExtensionAndCanonicalize.js
4467
+ function InsertUnicodeExtensionAndCanonicalize(locale, attributes, keywords) {
4468
+ invariant(locale.indexOf("-u-") === -1, "Expected locale to not have a Unicode locale extension");
4469
+ var extension = "-u";
4470
+ for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
4471
+ var attr = attributes_1[_i];
4472
+ extension += "-".concat(attr);
4473
+ }
4474
+ for (var _a = 0, keywords_1 = keywords; _a < keywords_1.length; _a++) {
4475
+ var kw = keywords_1[_a];
4476
+ var key = kw.key, value = kw.value;
4477
+ extension += "-".concat(key);
4478
+ if (value !== "") {
4479
+ extension += "-".concat(value);
4480
+ }
4481
+ }
4482
+ if (extension === "-u") {
4483
+ return CanonicalizeUnicodeLocaleId(locale);
4484
+ }
4485
+ var privateIndex = locale.indexOf("-x-");
4486
+ var newLocale;
4487
+ if (privateIndex === -1) {
4488
+ newLocale = locale + extension;
4489
+ } else {
4490
+ var preExtension = locale.slice(0, privateIndex);
4491
+ var postExtension = locale.slice(privateIndex);
4492
+ newLocale = preExtension + extension + postExtension;
4493
+ }
4494
+ return CanonicalizeUnicodeLocaleId(newLocale);
4495
+ }
4496
+
4453
4497
  // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/BestAvailableLocale.js
4454
4498
  function BestAvailableLocale(availableLocales, locale) {
4455
4499
  var candidate = locale;
@@ -4487,47 +4531,50 @@
4487
4531
  return result;
4488
4532
  }
4489
4533
 
4490
- // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/UnicodeExtensionValue.js
4491
- function UnicodeExtensionValue(extension, key) {
4492
- invariant(key.length === 2, "key must have 2 elements");
4534
+ // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/UnicodeExtensionComponents.js
4535
+ function UnicodeExtensionComponents(extension) {
4536
+ invariant(extension === extension.toLowerCase(), "Expected extension to be lowercase");
4537
+ invariant(extension.slice(0, 3) === "-u-", "Expected extension to be a Unicode locale extension");
4538
+ var attributes = [];
4539
+ var keywords = [];
4540
+ var keyword;
4493
4541
  var size = extension.length;
4494
- var searchValue = "-".concat(key, "-");
4495
- var pos = extension.indexOf(searchValue);
4496
- if (pos !== -1) {
4497
- var start = pos + 4;
4498
- var end = start;
4499
- var k = start;
4500
- var done = false;
4501
- while (!done) {
4502
- var e = extension.indexOf("-", k);
4503
- var len = void 0;
4504
- if (e === -1) {
4505
- len = size - k;
4506
- } else {
4507
- len = e - k;
4542
+ var k = 3;
4543
+ while (k < size) {
4544
+ var e = extension.indexOf("-", k);
4545
+ var len = void 0;
4546
+ if (e === -1) {
4547
+ len = size - k;
4548
+ } else {
4549
+ len = e - k;
4550
+ }
4551
+ var subtag = extension.slice(k, k + len);
4552
+ invariant(len >= 2, "Expected a subtag to have at least 2 characters");
4553
+ if (keyword === void 0 && len != 2) {
4554
+ if (attributes.indexOf(subtag) === -1) {
4555
+ attributes.push(subtag);
4508
4556
  }
4509
- if (len === 2) {
4510
- done = true;
4511
- } else if (e === -1) {
4512
- end = size;
4513
- done = true;
4514
- } else {
4515
- end = e;
4516
- k = e + 1;
4557
+ } else if (len === 2) {
4558
+ keyword = { key: subtag, value: "" };
4559
+ if (keywords.find(function(k2) {
4560
+ return k2.key === (keyword === null || keyword === void 0 ? void 0 : keyword.key);
4561
+ }) === void 0) {
4562
+ keywords.push(keyword);
4517
4563
  }
4564
+ } else if ((keyword === null || keyword === void 0 ? void 0 : keyword.value) === "") {
4565
+ keyword.value = subtag;
4566
+ } else {
4567
+ invariant(keyword !== void 0, "Expected keyword to be defined");
4568
+ keyword.value += "-" + subtag;
4518
4569
  }
4519
- return extension.slice(start, end);
4570
+ k += len + 1;
4520
4571
  }
4521
- searchValue = "-".concat(key);
4522
- pos = extension.indexOf(searchValue);
4523
- if (pos !== -1 && pos + 3 === size) {
4524
- return "";
4525
- }
4526
- return void 0;
4572
+ return { attributes, keywords };
4527
4573
  }
4528
4574
 
4529
4575
  // node_modules/.aspect_rules_js/@formatjs+intl-localematcher@0.0.0/node_modules/@formatjs/intl-localematcher/lib/abstract/ResolveLocale.js
4530
4576
  function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
4577
+ var _a;
4531
4578
  var matcher = options.localeMatcher;
4532
4579
  var r;
4533
4580
  if (matcher === "lookup") {
@@ -4535,56 +4582,77 @@
4535
4582
  } else {
4536
4583
  r = BestFitMatcher(Array.from(availableLocales), requestedLocales, getDefaultLocale);
4537
4584
  }
4585
+ if (r == null) {
4586
+ r = {
4587
+ locale: getDefaultLocale(),
4588
+ extension: ""
4589
+ };
4590
+ }
4538
4591
  var foundLocale = r.locale;
4539
- var result = { locale: "", dataLocale: foundLocale };
4540
- var supportedExtension = "-u";
4541
- for (var _i = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _i < relevantExtensionKeys_1.length; _i++) {
4542
- var key = relevantExtensionKeys_1[_i];
4543
- invariant(foundLocale in localeData, "Missing locale data for ".concat(foundLocale));
4544
- var foundLocaleData = localeData[foundLocale];
4545
- invariant(typeof foundLocaleData === "object" && foundLocaleData !== null, "locale data ".concat(key, " must be an object"));
4546
- var keyLocaleData = foundLocaleData[key];
4547
- invariant(Array.isArray(keyLocaleData), "keyLocaleData for ".concat(key, " must be an array"));
4592
+ var foundLocaleData = localeData[foundLocale];
4593
+ var result = { locale: "en", dataLocale: foundLocale };
4594
+ var components;
4595
+ var keywords;
4596
+ if (r.extension) {
4597
+ components = UnicodeExtensionComponents(r.extension);
4598
+ keywords = components.keywords;
4599
+ } else {
4600
+ keywords = [];
4601
+ }
4602
+ var supportedKeywords = [];
4603
+ var _loop_1 = function(key2) {
4604
+ var keyLocaleData = (_a = foundLocaleData === null || foundLocaleData === void 0 ? void 0 : foundLocaleData[key2]) !== null && _a !== void 0 ? _a : [];
4605
+ invariant(Array.isArray(keyLocaleData), "keyLocaleData for ".concat(key2, " must be an array"));
4548
4606
  var value = keyLocaleData[0];
4549
- invariant(typeof value === "string" || value === null, "value must be string or null but got ".concat(typeof value, " in key ").concat(key));
4550
- var supportedExtensionAddition = "";
4551
- if (r.extension) {
4552
- var requestedValue = UnicodeExtensionValue(r.extension, key);
4553
- if (requestedValue !== void 0) {
4554
- if (requestedValue !== "") {
4555
- if (~keyLocaleData.indexOf(requestedValue)) {
4556
- value = requestedValue;
4557
- supportedExtensionAddition = "-".concat(key, "-").concat(value);
4558
- }
4559
- } else if (~requestedValue.indexOf("true")) {
4560
- value = "true";
4561
- supportedExtensionAddition = "-".concat(key);
4607
+ invariant(value === void 0 || typeof value === "string", "value must be a string or undefined");
4608
+ var supportedKeyword = void 0;
4609
+ var entry = keywords.find(function(k) {
4610
+ return k.key === key2;
4611
+ });
4612
+ if (entry) {
4613
+ var requestedValue = entry.value;
4614
+ if (requestedValue !== "") {
4615
+ if (keyLocaleData.indexOf(requestedValue) > -1) {
4616
+ value = requestedValue;
4617
+ supportedKeyword = {
4618
+ key: key2,
4619
+ value
4620
+ };
4562
4621
  }
4622
+ } else if (keyLocaleData.indexOf("true") > -1) {
4623
+ value = "true";
4624
+ supportedKeyword = {
4625
+ key: key2,
4626
+ value
4627
+ };
4563
4628
  }
4564
4629
  }
4565
- if (key in options) {
4566
- var optionsValue = options[key];
4567
- invariant(typeof optionsValue === "string" || typeof optionsValue === "undefined" || optionsValue === null, "optionsValue must be String, Undefined or Null");
4568
- if (~keyLocaleData.indexOf(optionsValue)) {
4569
- if (optionsValue !== value) {
4570
- value = optionsValue;
4571
- supportedExtensionAddition = "";
4572
- }
4630
+ var optionsValue = options[key2];
4631
+ invariant(optionsValue == null || typeof optionsValue === "string", "optionsValue must be a string or undefined");
4632
+ if (typeof optionsValue === "string") {
4633
+ var ukey = key2.toLowerCase();
4634
+ optionsValue = CanonicalizeUValue(ukey, optionsValue);
4635
+ if (optionsValue === "") {
4636
+ optionsValue = "true";
4573
4637
  }
4574
4638
  }
4575
- result[key] = value;
4576
- supportedExtension += supportedExtensionAddition;
4577
- }
4578
- if (supportedExtension.length > 2) {
4579
- var privateIndex = foundLocale.indexOf("-x-");
4580
- if (privateIndex === -1) {
4581
- foundLocale = foundLocale + supportedExtension;
4582
- } else {
4583
- var preExtension = foundLocale.slice(0, privateIndex);
4584
- var postExtension = foundLocale.slice(privateIndex, foundLocale.length);
4585
- foundLocale = preExtension + supportedExtension + postExtension;
4639
+ if (optionsValue !== value && keyLocaleData.indexOf(optionsValue) > -1) {
4640
+ value = optionsValue;
4641
+ supportedKeyword = void 0;
4642
+ }
4643
+ if (supportedKeyword) {
4644
+ supportedKeywords.push(supportedKeyword);
4586
4645
  }
4587
- foundLocale = Intl.getCanonicalLocales(foundLocale)[0];
4646
+ result[key2] = value;
4647
+ };
4648
+ for (var _i = 0, relevantExtensionKeys_1 = relevantExtensionKeys; _i < relevantExtensionKeys_1.length; _i++) {
4649
+ var key = relevantExtensionKeys_1[_i];
4650
+ _loop_1(key);
4651
+ }
4652
+ var supportedAttributes = [];
4653
+ if (supportedKeywords.length > 0) {
4654
+ supportedAttributes = [];
4655
+ foundLocale = InsertUnicodeExtensionAndCanonicalize(foundLocale, supportedAttributes, supportedKeywords);
4588
4656
  }
4589
4657
  result.locale = foundLocale;
4590
4658
  return result;
package/polyfill.js CHANGED
@@ -10,4 +10,3 @@ if ((0, should_polyfill_1.shouldPolyfill)()) {
10
10
  configurable: true,
11
11
  });
12
12
  }
13
- //# sourceMappingURL=polyfill.js.map
@@ -4,4 +4,3 @@ exports.shouldPolyfill = shouldPolyfill;
4
4
  function shouldPolyfill() {
5
5
  return !Intl.Segmenter;
6
6
  }
7
- //# sourceMappingURL=should-polyfill.js.map
@@ -1267,4 +1267,3 @@ exports.SegmentationRules = {
1267
1267
  },
1268
1268
  "zh": {}
1269
1269
  };
1270
- //# sourceMappingURL=cldr-segmentation-rules.generated.js.map
@@ -35,4 +35,3 @@ exports.isSurrogate = isSurrogate;
35
35
  // return false
36
36
  // }
37
37
  // }
38
- //# sourceMappingURL=segmentation-utils.js.map
package/src/segmenter.js CHANGED
@@ -271,4 +271,3 @@ try {
271
271
  catch (e) {
272
272
  // Meta fix so we're test262-compliant, not important
273
273
  }
274
- //# sourceMappingURL=segmenter.js.map
package/test262-main.js CHANGED
@@ -3,4 +3,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // @generated
4
4
  // @ts-nocheck
5
5
  require("./polyfill-force");
6
- //# sourceMappingURL=test262-main.js.map