MCPcopy Index your code
hub / github.com/formatjs/formatjs / stringListFromIterable

Function stringListFromIterable

packages/intl-listformat/index.ts:110–125  ·  view source on GitHub ↗

* https://tc39.es/proposal-intl-list-format/#sec-createstringlistfromiterable * @param iterable list

(iterable: Iterable<unknown>)

Source from the content-addressed store, hash-verified

108 * @param iterable list
109 */
110function stringListFromIterable(iterable: Iterable<unknown>): string[] {
111 if (typeof iterable !== 'object') return []
112 const elements: string[] = []
113 const iterator = iterable[Symbol.iterator]()
114 let result: IteratorResult<unknown>
115 while (true) {
116 result = iterator.next()
117 if (result.done) break
118 if (typeof result.value !== 'string') {
119 const nextValue = result.value
120 throw new TypeError(`Iterable yielded ${nextValue} which is not a string`)
121 }
122 elements.push(result.value)
123 }
124 return elements
125}
126
127function createPartsFromList(
128 internalSlotMap: WeakMap<ListFormat, ListFormatInternal>,

Callers 2

formatMethod · 0.85
formatToPartsMethod · 0.85

Calls 1

nextMethod · 0.80

Tested by

no test coverage detected