MCPcopy
hub / github.com/formatjs/formatjs / mergeLiteral

Function mergeLiteral

packages/intl-messageformat/formatters.ts:88–107  ·  view source on GitHub ↗
(
  parts: MessageFormatPart<T>[]
)

Source from the content-addressed store, hash-verified

86 | Date
87
88function mergeLiteral<T>(
89 parts: MessageFormatPart<T>[]
90): MessageFormatPart<T>[] {
91 if (parts.length < 2) {
92 return parts
93 }
94 return parts.reduce((all, part) => {
95 const lastPart = all[all.length - 1]
96 if (
97 !lastPart ||
98 lastPart.type !== PART_TYPE.literal ||
99 part.type !== PART_TYPE.literal
100 ) {
101 all.push(part)
102 } else {
103 lastPart.value += part.value
104 }
105 return all
106 }, [] as MessageFormatPart<T>[])
107}
108
109export function isFormatXMLElementFn<T>(
110 el: PrimitiveType | T | FormatXMLElementFn<T>

Callers 1

formatToPartsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected