adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.66k stars 930 forks source link

Locales broken or documentation on main page wrong. #548

Open anselms opened 7 years ago

anselms commented 7 years ago

Locales according to the documentation on the main page do not work:

>var numeral = require("numeral")
> numeral.locale('de')
'de'
> numeral("12.2000.0065,9812")
TypeError: Cannot read property 'delimiters' of undefined
    at stringToNumber (/home/schultes/tpf/baenk-web/server/node_modules/numeral/numeral.js:284:27)
    at numeral (/home/schultes/tpf/baenk-web/server/node_modules/numeral/numeral.js:84:25)
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)

While this works:

>var numeral = require("numeral")
> var de = require('numeral/locales/de')
undefined
> numeral.locale('de')
'de'
> numeral("12.2000.0065,9812")
{ _input: '12.2000.0065,9812', _value: 1220000065.9812 }
> 

Does anyone know what the right way to use this is?

Actually I'm surprised this works at all, as the German locale is not correctly specified #533

tiesont commented 7 years ago

If I'm understanding your question correctly, then the error you're seeing is due to the locales being split into a separate file from the main numeral.js file. You have to also load locales.js for anything other than the US English locale to work. Both locales.js and locales.min.js (in the /min folder) contain a combination of all currently implemented locales, or (as your second example shows), you can load them individually.

The http://numeraljs.com/ site doesn't really mention this, so I suppose you're correct in saying the documentation is broken - I don't think it's been updated since @adamwdraper split the locales out into their own file(s).

anselms commented 7 years ago

Thanks for explaining this. Yes, the homepage does not mention this and the locales examples as present there will not work.

jbreckmckye commented 7 years ago

For anyone just coming across this, simply import the necessary locales along with the library:

var numeral = require("numeral");
require('numeral/locales/en-gb');
TomPradat commented 6 years ago

It could be usefull to update the documentation, is the website code open-source ?

linkb15 commented 2 years ago

any updates on this?

jbreckmckye commented 2 years ago

@linkb15 I don't think this repository is under active maintenance.

Instead, consider using https://github.com/BenjaminVanRyseghem/numbro, which is a fork under active development. I don't know if the locales are fixed though!