Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Get start and end of range quickly for Intl.NumberFormat #15

Closed
sffc opened this issue Mar 20, 2020 · 5 comments
Closed

Get start and end of range quickly for Intl.NumberFormat #15

sffc opened this issue Mar 20, 2020 · 5 comments

Comments

@sffc
Copy link

sffc commented Mar 20, 2020

It would be nice if you could do,

const nf = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
nf.format(Number.range(1, 5));  // "$1-5"  (or "$1-4" ??)

// or,
Number.range(1, 5).toLocaleString();  // "1-5"  (or "1-4" ??)

To do this, we'd need to efficiently get both the beginning and end of the range. To do this, the .range() functions could return a type that has a [Symbol.iterator] getter but also getters like .start and .end, for example.

@hax
Copy link
Member

hax commented Mar 21, 2020

It's unclear whether "1-5" is inclusive range or exclusive range. I guess most people would treat it as inclusive. But current proposed iteration semantic is exclusive.

@ljharb
Copy link
Member

ljharb commented Mar 21, 2020

I’d expect the same as slice: [1, 5)

@Jack-Works
Copy link
Member

The exclusive semantics is inspired by Python style

@Jack-Works
Copy link
Member

@sffc Hi, now the return value of range has a getter for from and to. Is that enough?

And if Intl.NumberFormat can read the internal slot directly to format the range?

@sffc
Copy link
Author

sffc commented May 15, 2020

The .from and .to getters are sufficient, thanks. If #17 or #22 is adopted, I imagine those getters might be moved to new types.

@sffc sffc closed this as completed May 15, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants