Skip to content

Value inconsistent with codePointAt #11

@simonbuchan

Description

@simonbuchan

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions