Export as high order function
lutherism opened this issue · 1 comments
Hello. I'm concerned using this library has implicit conflicts with other plugins. By adding methods to the singleton moment object at import time, it's possible to have conflicts at a distance in an app.
I'd advocate for exporting a "High Order Function" instead, so that the consumer can decide when/where to apply the plugin, and that will leave the original module unmodified.
ie:
require('moment');
var moment = require('moment-hijri');
becomes
var moment = require('moment-hijri')(require('moment'));
or in es6
import moment from 'moment';
import hijriify from 'moment-hijri';
const hijriMoment = hijiriify(moment);
Also remove need for AMD export in repo, as AMD projects could do:
define(['moment', 'moment-hijri'], function(moment, hijriify) {
var hijriMoment = hijriify(moment);
});
were you able to get moment/moment-hijri working in your project? I get an error: Uncaught TypeError: moment.localeData is not a function
from this line extend(getPrototypeOf(moment.localeData()), {
of line 274 in moment-hijri.js when I try to use it below. When I go and examine moment at this line, i see
I am using parceljs to bundle my application though.
import moment from "moment";
import momenti from "moment-hijri";
console.log("moment:", moment());
console.log("momenti:", momenti);