Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
app/components/DateTime.vue
Outdated
| day: undefined, | ||
| }, | ||
| ) | ||
| interface NuxtTimeProps { |
There was a problem hiding this comment.
Could these be simply imported from nuxt/dist/app/components/nuxt-time.d.vue.ts?
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| const formatter = computed(() => { | ||
| const { relativeStyle, ...rest } = props | ||
| if (relativeDates.value) { | ||
| return new Intl.RelativeTimeFormat(_locale ?? locale.value, { | ||
| ...defaults, | ||
| ...rest, | ||
| style: relativeStyle, | ||
| }) | ||
| } | ||
| return new Intl.DateTimeFormat(_locale ?? locale.value, { ...defaults, ...rest }) | ||
| }) |
There was a problem hiding this comment.
Maybe we could avoid type assertions by doing:
| const formatter = computed(() => { | |
| const { relativeStyle, ...rest } = props | |
| if (relativeDates.value) { | |
| return new Intl.RelativeTimeFormat(_locale ?? locale.value, { | |
| ...defaults, | |
| ...rest, | |
| style: relativeStyle, | |
| }) | |
| } | |
| return new Intl.DateTimeFormat(_locale ?? locale.value, { ...defaults, ...rest }) | |
| }) | |
| const relativeFormatter = computed(() => { | |
| const { relativeStyle, ...rest } = props | |
| return new Intl.RelativeTimeFormat(_locale ?? locale.value, { | |
| ...defaults, | |
| ...rest, | |
| style: relativeStyle, | |
| }) | |
| }) | |
| const formatter = computed(() => { | |
| const { relativeStyle, ...rest } = props | |
| return new Intl.DateTimeFormat(_locale ?? locale.value, { ...defaults, ...rest }) | |
| }) |
?
| // eslint-disable-next-line eslint-plugin-unicorn/consistent-function-scoping | ||
| const toCamelCase = (name: string, index: number) => { | ||
| if (index > 0) { | ||
| return name[0]!.toUpperCase() + name.slice(1) |
There was a problem hiding this comment.
| return name[0]!.toUpperCase() + name.slice(1) | |
| return name.charAt(0).toUpperCase() + name.slice(1) |
will avoid the need of non-null assertion
| let optionName = name | ||
| .slice(5) | ||
| .split('-') | ||
| .map(toCamelCase) | ||
| .join('') as keyof (Intl.DateTimeFormatOptions & Intl.RelativeTimeFormatOptions) | ||
|
|
||
| if ((optionName as string) === 'relativeStyle') { | ||
| optionName = 'style' | ||
| } |
There was a problem hiding this comment.
Maybe just a tiny bit more accurate - still assertion needed but at least we're "telling the truth" here:
| let optionName = name | |
| .slice(5) | |
| .split('-') | |
| .map(toCamelCase) | |
| .join('') as keyof (Intl.DateTimeFormatOptions & Intl.RelativeTimeFormatOptions) | |
| if ((optionName as string) === 'relativeStyle') { | |
| optionName = 'style' | |
| } | |
| let optionName = name.slice(5).split('-').map(toCamelCase).join('') as | |
| | keyof (Intl.DateTimeFormatOptions & Intl.RelativeTimeFormatOptions) | |
| | 'relativeStyle' | |
| if (optionName === 'relativeStyle') { | |
| optionName = 'style' | |
| } |
ghostdevv
left a comment
There was a problem hiding this comment.
Is this still necessary?
|
@danielroe I'll close it for now, feel free to reopen if I'm wrong :) |
this addresses some hydration mismatches we were encountering, and prevents layout shift/flicker