Is there any "ember-moment-shim" alternative for dayJS?

332 Views Asked by At

ember-moment-shim is an ember addon that generates the locales conditionally based on Moment.js and Moment-Timezone.

Any tools or processes to accomplish the same with just DayJs instead.

Ref: https://github.com/jasonmit/ember-cli-moment-shim

UPDATE:

I want to lazy load or dynamically load the dayJs locales based on the requirement. And every time you need to load a locale, you need to import it like

import fr from 'dayjs/locale/fr'

just that it would be a different locale every time and could change on refresh based on the settings from API response.

ember-auto-import throws following Error

Uncaught SyntaxError: Cannot use import statement outside a module*
1

There are 1 best solutions below

3
On

Addons like ember-cli-moment-shim are no longer required to use libraries from NPM instead you can use them directly after installing ember-auto-import.

From the command line do:

ember install ember-auto-import
npm install dayjs

Then you can just import dayjs where you need it.

For example in a component:

//app/components/today.js
import dayjs from 'dayjs';
import Component from '@glimmer/component';

export default class TodayComponent extends Component {
  today = dayjs().format();
}