Numeral-js: TypeError: Cannot read property 'delimiters' of undefined

Created on 15 Dec 2016  路  9Comments  路  Source: adamwdraper/Numeral-js

TypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormatTypeError: Cannot read property 'delimiters' of undefined
at numberToFormat

Most helpful comment

For Vue.js with webpack:

import numeral from 'numeral'
import 'numeral/locales/fr-ch'

numeral.locale('fr-ch')

All 9 comments

numeral.locale('fr');

I am also getting the same error.

My code is:

let number = 10000000.99;
numeral.locale('en-gb');
console.log(numeral(number).format('$ 0,0'));

Then the error is:

ORIGINAL EXCEPTION: Cannot read property 'delimiters' of undefined
TypeError: Cannot read property 'delimiters' of undefined
    at Object.numberToFormat (numeral.js:231)
    at format (numeral.js:778)
    at Numeral.format (numeral.js:593)

If I removed the locale config:

let number = 10000000.99;
//numeral.locale('en-gb');
console.log(numeral(number).format('$ 0,0'));

Code runs and console shows:

$ 10,000,001

Ok this is a typescript error, as I am using numeral-js with Angular 2.

It seems that the typings configuration for numeral-js here is outdated as it cannot see locale.delimiters object.

What I did is to manually numeral.register a locale in the constructor (eg: en-gb). Then set the numeral.locale there.

constructor() {
    numeral.register('locale', 'en-gb', {
        delimiters: {
            thousands: ',',
            decimal: '.'
        },
        abbreviations: {
            thousand: 'k',
            million: 'm',
            billion: 'b',
            trillion: 't'
        },
        ordinal: function (number) {
            var b = number % 10;
            return (~~ (number % 100 / 10) === 1) ? 'th' :
                (b === 1) ? 'st' :
                (b === 2) ? 'nd' :
                (b === 3) ? 'rd' : 'th';
        },
        currency: {
            symbol: '拢'
        }
    });

    numeral.locale('en-gb');
}

Seems like the problem is not a problem as there is a Breaking change: The locale function no longer loads locales, it only sets the current locale

https://github.com/adamwdraper/Numeral-js

From what I understand you need to load the locales now

Here's how I managed to make it work:

var numeral = require('numeral');
var it = require('numeral/locales/it');

numeral.locale('it');

var number = numeral(10000);

console.log(number.format())

@stefanoric I did not use angular and i have no require() directives, i use pure javascript and jquery with underscore, how i can handle this situation? I use numeral.js 2.0.6.

@dikkini I haven't used this library outside of node. I would suggest trying loading the locale objects the same way you load the library (e.g. <src="numeral.min.js "...)

For Vue.js with webpack:

import numeral from 'numeral'
import 'numeral/locales/fr-ch'

numeral.locale('fr-ch')

@adamwdraper : Suggestion Could you had the @Shiva127 comment to the doc please, it would be very great - in the #Locales section... Thanks !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eric24 picture Eric24  路  8Comments

zzzgit picture zzzgit  路  5Comments

tab00 picture tab00  路  8Comments

GitzJoey picture GitzJoey  路  4Comments

kinguru picture kinguru  路  6Comments