-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚧 UPDATE: format & number #129 #134
Conversation
jycouet
commented
Nov 15, 2023
•
edited
Loading
edited
- add tests for numbers
- Add app defaults.
- Add app presets
🦋 Changeset detectedLatest commit: d5f6377 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@jycouet This is looking great.
I would love to only have a single A quick list of use cases off the top of my head Convenient formattingUsing simple string presets (
InternationalizationInitially I had hopes to just use the browser's default locale (such as what At first glance it looks like you need to be explicit with these formats, unlike This looks great, and i'm on board with both simplifying and supporting non-English locales/Intl. If it would be helpful to sync up on a video chat, let me know and I can try to free up some time. |
The only drawback of Automatic local ( Main point for me is setting once option, then make use of it. (now writing this, maybe it should be any array of options... and take the first one (or a default one) if not specified) Great feedback 👍, Yes, let's have a video chat soon. |
Agreed. If we can get similar flexibility using Metric (significant digits) might be tricky. It looks like const byteValueNumberFormatter = Intl.NumberFormat("en", {
notation: "compact",
style: "unit",
unit: "byte",
unitDisplay: "narrow",
});
console.log(byteValueNumberFormatter.format(10));
=> 10B
console.log(byteValueNumberFormatter.format(200000));
=> 200KB
console.log(byteValueNumberFormatter.format(50000000));
=> 50MB If we think it's worth it (and I think it might), we can try to go through all the presets and find the applicable settings. We might also be able to add a little pre/post processing to get them "just right" (for example take off the "B" (byte) for "metric". I like the idea of dropping a dependency :). Intl.NumberFormat has great browser support.
Yeah, I can of suspected that.
Thanks, and sounds good. |
All right @techniq I guess that you can have a look 👍 |
import { getContext, setContext } from 'svelte'; | ||
import type { Theme } from './theme'; | ||
|
||
export type Setup = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd like to call this Settings
instead of Setup
(everywhere, not just this instance).
I could see apply an override of settings somewhere in your component tree (since it's just context). For example maybe if you had routing with the locale (/en/...
, /fr/...
, etc), or you wanted to style a page/section different (frontpage marketing vs app), etc.
It would also be nice to have a <Settings>
component like <Theme>
(which just makes it easier to set the context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, I'll update to Settings
.
The override thing, you can already do it no?
numbers: { | ||
locales: 'en', | ||
currency: 'USD', | ||
fractionDigits: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any risk of having only a single numbers options, or benefit to having options per style/preset?
For example, if fractionDigits: 4
, wouldn't all currency be set with 4 (since it doesn't specify a min/max in formatNumber()), or would you want to be able to specify them separately...
{
formats: {
numbers: {
default: {
locales: 'en',
},
currency: {
currency: 'USD',
fractionDigits: 2,
},
decimal: {
fractionDigits: 4
}
}
}
}
Just kind of thinking out loud
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's also an options, I like it. I'm hesitant... Adding default
right now is a good thing.
Let's see during my next night 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay... To be checked with what I just did
@jycouet This is really good! A few more small comments, but I think that will be it. Also, the Vercel preview build is failing due to |
locales: 'en', | ||
currency: 'USD', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jycouet I don't assume we should omit these and have it default to the browser's default locale? These settings work for me, mostly asking for a non-US view :). If not, let's keep them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it like this as default.
Let's see when people have a dedicated use case.
With local I will put 3000€, locally everything will work and Co, but people in Hungary will see 3000 Forint (that's 8€)!!! 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awe, very good point! Thanks!
@jycouet I'm ready to merge if you are. I left a note about whether we should default to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!