1

I am installing and using package decimal.js in NodeJS.

This package is described here.

All the examples state that I should be using Decimal. For some reason, it also works when using decimal.

What is the rationale behind this?

I've found a similar question on C# here, which states exactly what I sort of speculated:

The symbol decimal is declared as an alias for Decimal.

Is it the same in NodeJS, and how exactly do you go about aliasing something in JavaScript?

For the record, I am importing the package as follows:

import Decimal from 'decimal.js';

And as already implied, this seems to work just as well:

import decimal from 'decimal.js';
halfer
  • 19,824
  • 17
  • 99
  • 186
goodvibration
  • 5,980
  • 4
  • 28
  • 61
  • 3
    Probably because that's the default export from the module; so, you can name it anything you want when you import it. – canon Oct 31 '17 at 17:49
  • @canon: So it's me who determines the name then? I don't quite understand, isn't there a class with some explicit name inside this package that I need to use? – goodvibration Oct 31 '17 at 17:53

1 Answers1

3

There are two different types of export. Named exports and Default exports.You can read more about it here.

From that Page: Named exports are useful to export several values. During the import, it is mandatory to use the same name of the corresponding object. But a default export can be imported with any name.

sidoshi
  • 2,040
  • 2
  • 15
  • 30