Numeral-js: Bug with locales in 2.0.1

Created on 9 Dec 2016  ·  11Comments  ·  Source: adamwdraper/Numeral-js

I want to use the locales (old language) feature but got problems loading the predefined languages:

For testing I installed it in a new directory:

pc-alex-linux ~ $ mkdir t4
pc-alex-linux ~ $ cd t4
pc-alex-linux ~/t4 $ npm install numeral
/home/alex/t4
└── [email protected]

And then tried to use it with REPL:

pc-alex-linux ~/t4 $ node
> numeral = require("numeral");
{ [Function]
  ...
  locales: 
   { en: 
      { delimiters: [Object],
        abbreviations: [Object],
        ordinal: [Function],
        currency: [Object] } },
  ...
> require("numeral/src/locales/de");
{}
> numeral.locale('de');
{ [Function]
  ...
  locales: 
   { en: 
      { delimiters: [Object],
        abbreviations: [Object],
        ordinal: [Function],
        currency: [Object] } },
  ...
> numeral(5000.66).format();
TypeError: Cannot read property 'delimiters' of undefined
    at numeral._._.numberToFormat (/home/alex/t4/node_modules/numeral/numeral.js:203:86)
    at Object.numeral.fn.Numeral.format (/home/alex/t4/node_modules/numeral/numeral.js:550:26)
    at repl:1:18
    at REPLServer.defaultEval (repl.js:270:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:439:10)
    at emitOne (events.js:95:20)
    at REPLServer.emit (events.js:182:7)
    at REPLServer.Interface._onLine (readline.js:211:10)

I think loading the locale file is broken here. I use NPM 3.8.6 with Node v5.12.0.

Most helpful comment

There really should be some documentation for this. Took me a while to find out that require('numeral/locals/nl') works..

All 11 comments

Same problem here.
One more thing: If I require numeral-with-locales it immediately fails during the require-load. Error is: TypeError: bytes format already registered.

There are no tests for this file in your repo. Also I am missing tests that switch languages. This was easily possible in the earlier version.

If you need / want help in creating a reproducing test (before / after) ping me

Your tests have much potential for improvement right now. All the locale tests can not run if the formattests haven't been run before. - There is no independence now.
Also, I'd really prefer to run the tests on the produced artifacts in the top level directory as those are the ones used by your consumers. As long as you test them from inside the src you cannot be sure that your library will behave as planned.

I have the same problem!

Hey guys I've got the same problem here. I would be grateful for a fix :)

Take a look at #417. Check out that branch and see if this fixes the issues. Thanks

Sorry, but it changed but didn't work again:

alex@pc-alex ~ $ mkdir t4
alex@pc-alex ~ $ cd t4
alex@pc-alex ~/t4 $ npm install numeral
/home/alex/t4
└── [email protected] 
alex@pc-alex ~/t4 $ node
> numeral = require('numeral');
{ [Function]
  version: '2.0.2',
  isNumeral: [Function],
  _: 
   { numberToFormat: [Function],
     stringToNumber: [Function],
     isNaN: [Function],
     includes: [Function],
     reduce: [Function],
     multiplier: [Function],
     correctionFactor: [Function],
     toFixed: [Function] },
  options: 
   { currentLocale: 'en',
     zeroFormat: null,
     nullFormat: null,
     defaultFormat: '0,0' },
  formats: 
   { bytes: { regexps: [Object], format: [Function], unformat: [Function] },
     currency: { regexps: [Object], format: [Function] },
     exponential: { regexps: [Object], format: [Function], unformat: [Function] },
     ordinal: { regexps: [Object], format: [Function] },
     percentage: { regexps: [Object], format: [Function], unformat: [Function] },
     time: { regexps: [Object], format: [Function], unformat: [Function] } },
  locales: 
   { en: 
      { delimiters: [Object],
        abbreviations: [Object],
        ordinal: [Function],
        currency: [Object] } },
  locale: [Function],
  localeData: [Function],
  reset: [Function],
  zeroFormat: [Function],
  nullFormat: [Function],
  defaultFormat: [Function],
  register: [Function],
  validate: [Function],
  fn: 
   { clone: [Function],
     format: [Function],
     value: [Function],
     input: [Function],
     set: [Function],
     add: [Function],
     subtract: [Function],
     multiply: [Function],
     divide: [Function],
     difference: [Function] } }
> require("numeral/src/locales/de");
{}
> numeral.locale('de');
'de'
> numeral(5000.66).format();
TypeError: Cannot read property 'delimiters' of undefined
    at numeral._._.numberToFormat (/home/alex/t4/node_modules/numeral/numeral.js:211:86)
    at Object.numeral.fn.Numeral.format (/home/alex/t4/node_modules/numeral/numeral.js:558:26)
    at repl:1:18
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)

Is there something I do wrong and have you tested this scenario on your own?
I did my tests with node v4.2.6 this time.

Is it because you won't support older node versions, then please specify this in the package.json. Currently there is:

"engines": { "node": "*"}

So I think a node v4 (it's active LTS version till April and maintenance till 2018) should be supported. If not please change the above definition.

Travis tests run on node 4 and are passing so not quite sure what is happening. I'll take a closer look today.

I think I see the issue. src files are not meant to be used as they are compiled to create the final files. I am going to add a locales directory at the root of the project and then you could use those. Then you'll be able to require("numeral/locales/de");

Should be fixed in 2.0.3 if you see my last comment. Thanks

There really should be some documentation for this. Took me a while to find out that require('numeral/locals/nl') works..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfstephe picture jfstephe  ·  4Comments

chumager picture chumager  ·  3Comments

rogerfar picture rogerfar  ·  8Comments

ragulka picture ragulka  ·  6Comments

garbinmarcelo picture garbinmarcelo  ·  5Comments