-
Notifications
You must be signed in to change notification settings - Fork 8
Description
I could definitely see myself using this and agree that you would likely want position as well as the code point in most cases, but it grates somewhat that while codePointAt()
returns just a number, codePoints()
yields objects: from the naming I would expect s.codePointAt(0) === s.codePoints().next().value
.
Similarly, without type checking, its pretty natural to type for (const codePoint of s.codePoints()) ...
, instead of for (const { codePoint } of s.codePoints()) ...
The solution might be as simple as a different name: codePointTokens
for example.
Alternatively, since .value.position
being valid even when .done
is true is pretty funky already, and usage of position seemingly being most useful when directly using the iterator, perhaps instead having next()
return { done: boolean, value: number, position: number }
, where value
is valid only when done
is false
, but position
is always valid would make sense?