Skip to content
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

Extend with plugins simpler #1052

Closed
BCsabaEngine opened this issue Sep 17, 2020 · 4 comments
Closed

Extend with plugins simpler #1052

BCsabaEngine opened this issue Sep 17, 2020 · 4 comments

Comments

@BCsabaEngine
Copy link

BCsabaEngine commented Sep 17, 2020

I am happy to use plugins very simple anc clear. But I have got an idea to more clear import syntax.

Now:

const ....
const dayjs = require('dayjs');
const relativeTime = require('dayjs/plugin/relativeTime');
dayjs.extend(relativeTime);
const ...

I can write it simple (two step in one)

const ....
const dayjs = require('dayjs').extend(require('dayjs/plugin/relativeTime'));
const ...

It would be good to use more simpler:

const dayjs = require('dayjs').extendInline('relativeTime', [options]);

Pseudo for alternative usage:

dayjs.extendInline = function (file, option) {
  import plugin from 'dayjs/plugin/' + file;
  plugin(option, Dayjs, dayjs);
  return dayjs;
}; 

(extendInline may be extend, but I am not familiar with typescript overload)

@iamkun
Copy link
Owner

iamkun commented Sep 17, 2020

Hi, thanks for the advice.

It may be better to leave the import work to our users. Cause different packing tools and compilers may have different syntax.

@BCsabaEngine
Copy link
Author

Thx for reply and for your time!
I agree your opinion and harmonize with you. Of course. Maybe I will make a package to "configure" day.js import with this short format. I don't know how many user will use my tool :)

@BCsabaEngine
Copy link
Author

I have tested behavior of day.js and I found: I need to initialize extensions/plugins only once (top most level; index.js) and every other require() will be use it with these extensions too. Great!

@iamkun
Copy link
Owner

iamkun commented Sep 17, 2020

Yes, because dayjs is in global scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants