MCPcopy
hub / github.com/formatjs/formatjs / constructor

Method constructor

packages/intl-locale/index.ts:448–592  ·  view source on GitHub ↗
(tag: string | Locale, opts?: IntlLocaleOptions)

Source from the content-addressed store, hash-verified

446
447export class Locale {
448 constructor(tag: string | Locale, opts?: IntlLocaleOptions) {
449 // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
450 // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
451 const newTarget = this && this instanceof Locale ? this.constructor : void 0
452 if (!newTarget) {
453 throw new TypeError("Intl.Locale must be called with 'new'")
454 }
455
456 const {relevantExtensionKeys} = Locale
457
458 const internalSlotsList: Array<keyof IntlLocaleInternal> = [
459 'initializedLocale',
460 'locale',
461 'calendar',
462 'collation',
463 'hourCycle',
464 'numberingSystem',
465 ]
466
467 if (relevantExtensionKeys.indexOf('kf') > -1) {
468 internalSlotsList.push('caseFirst')
469 }
470
471 if (relevantExtensionKeys.indexOf('kn') > -1) {
472 internalSlotsList.push('numeric')
473 }
474
475 if (tag === undefined) {
476 throw new TypeError(
477 "First argument to Intl.Locale constructor can't be empty or missing"
478 )
479 }
480
481 if (typeof tag !== 'string' && typeof tag !== 'object') {
482 throw new TypeError('tag must be a string or object')
483 }
484
485 let tagInternalSlots
486 if (
487 typeof tag === 'object' &&
488 (tagInternalSlots = getInternalSlots(tag)) &&
489 HasOwnProperty(tagInternalSlots, 'initializedLocale')
490 ) {
491 tag = tagInternalSlots.locale
492 } else {
493 tag = tag.toString() as string
494 }
495
496 let internalSlots = getInternalSlots(this, internalSlotsList)
497
498 let options = CoerceOptionsToObject<IntlLocaleOptions>(opts)
499
500 tag = applyOptionsToTag(tag, options)
501 const opt = Object.create(null)
502 const calendar = GetOption(
503 options,
504 'calendar',
505 'string',

Callers

nothing calls this directly

Calls 9

HasOwnPropertyFunction · 0.85
CoerceOptionsToObjectFunction · 0.85
applyOptionsToTagFunction · 0.85
GetOptionFunction · 0.85
weekdayToStringFunction · 0.85
SameValueFunction · 0.85
getInternalSlotsFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected