@formatjs/intl-locale 3.4.6 → 4.0.0

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/index.js CHANGED
@@ -1,12 +1,21 @@
1
1
  import { __assign, __spreadArray } from "tslib";
2
+ import { CoerceOptionsToObject, GetOption, HasOwnProperty, SameValue, createDataProperty, invariant, } from '@formatjs/ecma402-abstract';
2
3
  import { supportedValuesOf } from '@formatjs/intl-enumerator';
3
- import { defineProperty, GetOption, invariant, SameValue, CoerceOptionsToObject, } from '@formatjs/ecma402-abstract';
4
- import { isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, parseUnicodeLanguageId, isUnicodeScriptSubtag, emitUnicodeLocaleId, parseUnicodeLocaleId, emitUnicodeLanguageId, likelySubtags, } from '@formatjs/intl-getcanonicallocales';
5
- import getInternalSlots from './get_internal_slots';
6
- import { getCalendarPreferenceDataForRegion, getHourCyclesPreferenceDataForLocaleOrRegion, getTimeZonePreferenceForRegion, getWeekDataForRegion, } from './preference-data';
4
+ import { emitUnicodeLanguageId, emitUnicodeLocaleId, isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, likelySubtags, parseUnicodeLanguageId, parseUnicodeLocaleId, } from '@formatjs/intl-getcanonicallocales';
7
5
  import { characterOrders } from './character-orders.generated';
6
+ import getInternalSlots from './get_internal_slots';
8
7
  import { numberingSystems } from './numbering-systems.generated';
9
- var RELEVANT_EXTENSION_KEYS = ['ca', 'co', 'hc', 'kf', 'kn', 'nu'];
8
+ import { getCalendarPreferenceDataForRegion, getHourCyclesPreferenceDataForLocaleOrRegion, getTimeZonePreferenceForRegion, getWeekDataForRegion, } from './preference-data';
9
+ var ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
10
+ var RELEVANT_EXTENSION_KEYS = [
11
+ 'ca',
12
+ 'co',
13
+ 'hc',
14
+ 'kf',
15
+ 'kn',
16
+ 'nu',
17
+ 'fw',
18
+ ];
10
19
  var UNICODE_TYPE_REGEX = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/i;
11
20
  function applyOptionsToTag(tag, options) {
12
21
  invariant(typeof tag === 'string', 'language tag must be a string');
@@ -251,6 +260,10 @@ function weekInfoOfLocale(loc) {
251
260
  }
252
261
  return getWeekDataForRegion(region);
253
262
  }
263
+ var TABLE_1 = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
264
+ function weekdayToString(fw) {
265
+ return TABLE_1[+fw];
266
+ }
254
267
  var Locale = /** @class */ (function () {
255
268
  function Locale(tag, opts) {
256
269
  // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
@@ -280,16 +293,16 @@ var Locale = /** @class */ (function () {
280
293
  if (typeof tag !== 'string' && typeof tag !== 'object') {
281
294
  throw new TypeError('tag must be a string or object');
282
295
  }
283
- var internalSlots;
296
+ var tagInternalSlots;
284
297
  if (typeof tag === 'object' &&
285
- (internalSlots = getInternalSlots(tag)) &&
286
- internalSlots.initializedLocale) {
287
- tag = internalSlots.locale;
298
+ (tagInternalSlots = getInternalSlots(tag)) &&
299
+ HasOwnProperty(tagInternalSlots, 'initializedLocale')) {
300
+ tag = tagInternalSlots.locale;
288
301
  }
289
302
  else {
290
303
  tag = tag.toString();
291
304
  }
292
- internalSlots = getInternalSlots(this);
305
+ var internalSlots = getInternalSlots(this, internalSlotsList);
293
306
  var options = CoerceOptionsToObject(opts);
294
307
  tag = applyOptionsToTag(tag, options);
295
308
  var opt = Object.create(null);
@@ -307,6 +320,14 @@ var Locale = /** @class */ (function () {
307
320
  }
308
321
  }
309
322
  opt.co = collation;
323
+ var fw = GetOption(options, 'firstDayOfWeek', 'string', undefined, undefined);
324
+ if (fw !== undefined) {
325
+ fw = weekdayToString(fw);
326
+ if (!ALPHANUM_3_8.test(fw)) {
327
+ throw new RangeError('Invalid firstDayOfWeek');
328
+ }
329
+ }
330
+ opt.fw = fw;
310
331
  var hc = GetOption(options, 'hourCycle', 'string', ['h11', 'h12', 'h23', 'h24'], undefined);
311
332
  opt.hc = hc;
312
333
  var kf = GetOption(options, 'caseFirst', 'string', ['upper', 'lower', 'false'], undefined);
@@ -328,6 +349,7 @@ var Locale = /** @class */ (function () {
328
349
  internalSlots.locale = r.locale;
329
350
  internalSlots.calendar = r.ca;
330
351
  internalSlots.collation = r.co;
352
+ internalSlots.firstDayOfWeek = r.fw;
331
353
  internalSlots.hourCycle = r.hc;
332
354
  if (relevantExtensionKeys.indexOf('kf') > -1) {
333
355
  internalSlots.caseFirst = r.kf;
@@ -388,13 +410,6 @@ var Locale = /** @class */ (function () {
388
410
  enumerable: false,
389
411
  configurable: true
390
412
  });
391
- Object.defineProperty(Locale.prototype, "hourCycle", {
392
- get: function () {
393
- return getInternalSlots(this).hourCycle;
394
- },
395
- enumerable: false,
396
- configurable: true
397
- });
398
413
  Object.defineProperty(Locale.prototype, "caseFirst", {
399
414
  get: function () {
400
415
  return getInternalSlots(this).caseFirst;
@@ -449,6 +464,28 @@ var Locale = /** @class */ (function () {
449
464
  enumerable: false,
450
465
  configurable: true
451
466
  });
467
+ Object.defineProperty(Locale.prototype, "firstDayOfWeek", {
468
+ get: function () {
469
+ var internalSlots = getInternalSlots(this);
470
+ if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
471
+ throw new TypeError('Error uninitialized locale');
472
+ }
473
+ return internalSlots.firstDayOfWeek;
474
+ },
475
+ enumerable: false,
476
+ configurable: true
477
+ });
478
+ Object.defineProperty(Locale.prototype, "hourCycle", {
479
+ get: function () {
480
+ var internalSlots = getInternalSlots(this);
481
+ if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
482
+ throw new TypeError('Error uninitialized locale');
483
+ }
484
+ return internalSlots.hourCycle;
485
+ },
486
+ enumerable: false,
487
+ configurable: true
488
+ });
452
489
  /**
453
490
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars
454
491
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCalendars
@@ -456,16 +493,6 @@ var Locale = /** @class */ (function () {
456
493
  Locale.prototype.getCalendars = function () {
457
494
  return calendarsOfLocale(this);
458
495
  };
459
- Object.defineProperty(Locale.prototype, "calendars", {
460
- /**
461
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.calendars
462
- */
463
- get: function () {
464
- return calendarsOfLocale(this);
465
- },
466
- enumerable: false,
467
- configurable: true
468
- });
469
496
  /**
470
497
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations
471
498
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getCollations
@@ -473,37 +500,17 @@ var Locale = /** @class */ (function () {
473
500
  Locale.prototype.getCollations = function () {
474
501
  return collationsOfLocale(this);
475
502
  };
476
- Object.defineProperty(Locale.prototype, "collations", {
477
- /**
478
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.collations
479
- */
480
- get: function () {
481
- return collationsOfLocale(this);
482
- },
483
- enumerable: false,
484
- configurable: true
485
- });
486
503
  /**
487
504
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles
488
505
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getHourCycles
489
506
  */
490
507
  Locale.prototype.getHourCycles = function () {
491
- var locInternalSlots = getInternalSlots(this);
492
- if (locInternalSlots.initializedLocale === undefined) {
508
+ var internalSlots = getInternalSlots(this);
509
+ if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
493
510
  throw new TypeError('Error uninitialized locale');
494
511
  }
495
512
  return hourCyclesOfLocale(this);
496
513
  };
497
- Object.defineProperty(Locale.prototype, "hourCycles", {
498
- /**
499
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.hourCycles
500
- */
501
- get: function () {
502
- return hourCyclesOfLocale(this);
503
- },
504
- enumerable: false,
505
- configurable: true
506
- });
507
514
  /**
508
515
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems
509
516
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getNumberingSystems
@@ -511,16 +518,6 @@ var Locale = /** @class */ (function () {
511
518
  Locale.prototype.getNumberingSystems = function () {
512
519
  return numberingSystemsOfLocale(this);
513
520
  };
514
- Object.defineProperty(Locale.prototype, "numberingSystems", {
515
- /**
516
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.numberingSystems
517
- */
518
- get: function () {
519
- return numberingSystemsOfLocale(this);
520
- },
521
- enumerable: false,
522
- configurable: true
523
- });
524
521
  /**
525
522
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones
526
523
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTimeZones
@@ -528,16 +525,6 @@ var Locale = /** @class */ (function () {
528
525
  Locale.prototype.getTimeZones = function () {
529
526
  return timeZonesOfLocale(this);
530
527
  };
531
- Object.defineProperty(Locale.prototype, "timeZones", {
532
- /**
533
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.timeZones
534
- */
535
- get: function () {
536
- return timeZonesOfLocale(this);
537
- },
538
- enumerable: false,
539
- configurable: true
540
- });
541
528
  /**
542
529
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
543
530
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getTextInfo
@@ -545,93 +532,30 @@ var Locale = /** @class */ (function () {
545
532
  Locale.prototype.getTextInfo = function () {
546
533
  var info = Object.create(Object.prototype);
547
534
  var dir = characterDirectionOfLocale(this);
548
- defineProperty(info, 'direction', {
549
- value: dir,
550
- });
535
+ createDataProperty(info, 'direction', dir);
551
536
  return info;
552
537
  };
553
- Object.defineProperty(Locale.prototype, "textInfo", {
554
- /**
555
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.textInfo
556
- */
557
- get: function () {
558
- try {
559
- var info = Object.create(Object.prototype);
560
- var dir = characterDirectionOfLocale(this);
561
- Object.defineProperty(info, 'direction', {
562
- value: dir,
563
- writable: true,
564
- enumerable: true,
565
- configurable: true,
566
- });
567
- return info;
568
- }
569
- catch (e) {
570
- throw new TypeError('Error retrieving textInfo');
571
- }
572
- },
573
- enumerable: false,
574
- configurable: true
575
- });
576
538
  /**
577
539
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo
578
540
  * https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.getWeekInfo
579
541
  */
580
542
  Locale.prototype.getWeekInfo = function () {
581
543
  var info = Object.create(Object.prototype);
582
- var locInternalSlots = getInternalSlots(this);
583
- if (locInternalSlots.initializedLocale === undefined) {
544
+ var internalSlots = getInternalSlots(this);
545
+ if (!HasOwnProperty(internalSlots, 'initializedLocale')) {
584
546
  throw new TypeError('Error uninitialized locale');
585
547
  }
586
548
  var wi = weekInfoOfLocale(this);
587
549
  var we = wi.weekend;
588
- defineProperty(info, 'firstDay', {
589
- value: wi.firstDay,
590
- });
591
- defineProperty(info, 'weekend', {
592
- value: we,
593
- });
594
- defineProperty(info, 'minimalDays', {
595
- value: wi.minimalDays,
596
- });
550
+ createDataProperty(info, 'firstDay', wi.firstDay);
551
+ createDataProperty(info, 'weekend', we);
552
+ createDataProperty(info, 'minimalDays', wi.minimalDays);
553
+ var fw = internalSlots.firstDayOfWeek;
554
+ if (fw !== undefined) {
555
+ info.firstDay = fw;
556
+ }
597
557
  return info;
598
558
  };
599
- Object.defineProperty(Locale.prototype, "weekInfo", {
600
- /**
601
- * https://tc39.es/proposal-intl-locale/#sec-Intl.Locale.prototype.weekInfo
602
- */
603
- get: function () {
604
- try {
605
- var info = Object.create(Object.prototype);
606
- var wi = weekInfoOfLocale(this);
607
- var we = wi.weekend;
608
- Object.defineProperty(info, 'firstDay', {
609
- value: wi.firstDay,
610
- writable: true,
611
- enumerable: true,
612
- configurable: true,
613
- });
614
- Object.defineProperty(info, 'weekend', {
615
- value: we,
616
- writable: true,
617
- enumerable: true,
618
- configurable: true,
619
- });
620
- Object.defineProperty(info, 'minimalDays', {
621
- value: wi.minimalDays,
622
- writable: true,
623
- enumerable: true,
624
- configurable: true,
625
- });
626
- return info;
627
- }
628
- catch (e) {
629
- throw new TypeError('Error retrieving weekInfo');
630
- }
631
- },
632
- enumerable: false,
633
- configurable: true
634
- });
635
559
  Locale.relevantExtensionKeys = RELEVANT_EXTENSION_KEYS;
636
560
  Locale.polyfilled = true;
637
561
  return Locale;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-locale",
3
- "version": "3.4.6",
3
+ "version": "4.0.0",
4
4
  "description": "Intl.Locale polyfill",
5
5
  "keywords": [
6
6
  "intl",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "tslib": "^2.4.0",
28
- "@formatjs/intl-enumerator": "1.4.6",
29
- "@formatjs/ecma402-abstract": "1.18.3",
28
+ "@formatjs/ecma402-abstract": "2.0.0",
29
+ "@formatjs/intl-enumerator": "1.4.7",
30
30
  "@formatjs/intl-getcanonicallocales": "2.3.0"
31
31
  }
32
32
  }