MCPcopy
hub / github.com/formatjs/formatjs / get

Function get

packages/intl-datetimeformat/core.ts:65–109  ·  view source on GitHub ↗
(this: IDateTimeFormat)

Source from the content-addressed store, hash-verified

63 enumerable: false,
64 configurable: true,
65 get(this: IDateTimeFormat) {
66 if (
67 typeof this !== 'object' ||
68 !OrdinaryHasInstance(DateTimeFormat, this)
69 ) {
70 throw TypeError(
71 'Intl.DateTimeFormat format property accessor called on incompatible receiver'
72 )
73 }
74 const internalSlots = getInternalSlots(this)
75 // eslint-disable-next-line @typescript-eslint/no-this-alias
76 const dtf = this
77 let boundFormat = internalSlots.boundFormat
78 if (boundFormat === undefined) {
79 // https://tc39.es/proposal-unified-intl-numberformat/section11/numberformat_diff_out.html#sec-number-format-functions
80 boundFormat = (date?: Date | number) => {
81 let x: Decimal
82 if (date === undefined) {
83 x = new Decimal(Date.now())
84 } else {
85 x = ToNumber(date)
86 }
87 return FormatDateTime(dtf as Intl.DateTimeFormat, x, {
88 getInternalSlots,
89 localeData: DateTimeFormat.localeData,
90 tzData: DateTimeFormat.tzData,
91 getDefaultTimeZone: DateTimeFormat.getDefaultTimeZone,
92 })
93 }
94 try {
95 // https://github.com/tc39/test262/blob/master/test/intl402/NumberFormat/prototype/format/format-function-name.js
96 Object.defineProperty(boundFormat, 'name', {
97 configurable: true,
98 enumerable: false,
99 writable: false,
100 value: '',
101 })
102 } catch {
103 // In older browser (e.g Chrome 36 like polyfill-fastly.io)
104 // TypeError: Cannot redefine property: name
105 }
106 internalSlots.boundFormat = boundFormat
107 }
108 return boundFormat
109 },
110} as const
111try {
112 // https://github.com/tc39/test262/blob/master/test/intl402/NumberFormat/prototype/format/name.js

Callers

nothing calls this directly

Calls 4

OrdinaryHasInstanceFunction · 0.85
ToNumberFunction · 0.85
FormatDateTimeFunction · 0.85
getInternalSlotsFunction · 0.70

Tested by

no test coverage detected