How to use multimode plugins?

I know that I need to import the moment plugin if I want to use it. Like this:

import * as moment from "moment-timezone";

//here I can use moment.tr.names() etc.

But what if I want to use multiple plugins? I know that plugins instantly import the moment, add their functionality, and then export the moment again. But if this is correct, how can I use multiple plugins?

One option is to import them under a different name, for example:

import * as momentJdate from "moment-jdateformatparser";
import * as momentTimezone from "moment-timezone";

Or I can combine them at one point like this (using deepExtend):

let moment = {};
deepExtend(moment, momentJdate, momentTimezone);

//here you should be able to use moment().toJDFString() and moment.tz.names()

But none of them look like pure code. Is there a better way to do this?

+4
source share
1 answer

, , , . :

moment = require('moment-business-days');
moment = require('moment-timezone');
moment().tz('America/New_York').businessAdd(1).startOf('day').add(7, 'hours')

, , node, , . .

0

Source: https://habr.com/ru/post/1685216/


All Articles