Closed dennistobar closed 4 years ago
This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.
🔍 Inspect: https://vercel.com/torstendittmann/omniawrite/nunfq8vsu
✅ Preview: https://omniawrite-git-fork-dennistobar-date-fns.torstendittmann.vercel.app
Instead of importing every dependency everytime we are gonna use it, we could import it in the src/utils.js
file and export methods from there.
Something like this:
import { formatDistanceToNow, format, fromUnixTime } from "date-fns";
import { es, enUS as en, pt, ru, de } from "date-fns/locale";
export formatDistance = timestamp => formatDistanceToNow(fromUnixTime(timestamp), {
locale: locales[$settings.language],
addSuffix: true,
})
and we can re-use it again like:
import { formatDistance } from "./utils";
formatDistance(date.created);
You probably have to use Svelte get(store) to access the settings store 🙂
Feel free to ask if you have any questions 👍
Instead of importing every dependency everytime we are gonna use it, we could import it in the
src/utils.js
file and export methods from there.Something like this:
import { formatDistanceToNow, format, fromUnixTime } from "date-fns"; import { es, enUS as en, pt, ru, de } from "date-fns/locale"; export formatDistance = timestamp => formatDistanceToNow(fromUnixTime(timestamp), { locale: locales[$settings.language], addSuffix: true, })
and we can re-use it again like:
import { formatDistance } from "./utils"; formatDistance(date.created);
You probably have to use Svelte get(store) to access the settings store 🙂
Nice to hear about it. I'll refactor today.
Amazing work you have done here!
Thanks alot 🙇
Here is a possible solution to change dependency from momentjs to date-fns. I must use an alias for English locale, because there is no generic English locale. (I use enUS as generic).
As general question, can we use new helpers?, I see some duplication to get relative time and timestamp functions in svelte.
Ah! another drawback: the local must be defined in a new variable, because they need to be defined and date-fns haven't a "global configuration" (date-fns/date-fns#816)
Closes #96 , Closes #99