-
Notifications
You must be signed in to change notification settings - Fork 109
Open
Labels
c: textComponent: case mapping, collation, propertiesComponent: case mapping, collation, propertiesenhancements: discussStatus: TG2 must discuss to move forwardStatus: TG2 must discuss to move forward
Description
This would be immensely useful for things like virtual DOM lists and polyfilling whatwg/html#4630 without a ton of pain.
I'm thinking of an API like this:
interface ListFormat {
// Existing
formatToParts(list: string[]): ListFormatPart<string>
// New
formatToElements<T>(list: Array<{value: T, part: string}>): ListFormatPart<T>
}
type ListFormatPart<T> =
| {type: "element", value: T}
| {type: "literal", value: string}
The key functional difference is that formatToElements
, while it coerces its arguments, it does not return the coerced results.
Polyfilling this is very awkward and only works because Unicode explicitly states that previous parts must come before next parts:
Intl.ListFormat.prototype.formatToElements = function (list) {
const parts = []
const values = []
for (const {part, value} of list) {
parts.push(part)
values.push(value)
}
const result = this.formatToParts(parts)
let index = 0
for (const part of result) {
if (part.type === "element") {
part.value = values[index++]
}
}
return result
}
Metadata
Metadata
Assignees
Labels
c: textComponent: case mapping, collation, propertiesComponent: case mapping, collation, propertiesenhancements: discussStatus: TG2 must discuss to move forwardStatus: TG2 must discuss to move forward
Type
Projects
Status
Other Issues