fumeapp / dayjs

Nuxt V3 module for Day.js
Apache License 2.0
109 stars 11 forks source link

[FEAT]: `dayjs()` as composable #57

Open KillerJulian opened 5 days ago

KillerJulian commented 5 days ago

Current

useDayjs()() is an ugly code style in my opinion!

console.log(useDayjs()().format('YYYY-MM-DD HH:mm:ss'));

// or two lines
const dayjs = useDayjs();
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'));

Feature 🚀

dayjs() as autoimport!

console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'));

Workarround

This can certainly be solved more beautifully in the library, but until the feature is available in the library, it can be used as a composable:

export function dayjs(...args: Parameters<ReturnType<typeof useDayjs>>) {
    return useDayjs()(...args);
}

~/composables/dayjs.ts

acidjazz commented 1 day ago

Very cool suggestion, feel free to start a PR!