Skip to content

Commit

Permalink
fix(default-locale): switch default locale from fr to en (#146)
Browse files Browse the repository at this point in the history
* fix(default-locale): switch default locale from `fr` to `en`

* fix tests

* update README
  • Loading branch information
Kocal committed Apr 7, 2019
1 parent 4de1ebd commit 4637969
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $ yarn add vue-numerals 'numeral@>=2'
import Vue from 'vue';
import VueNumerals from 'vue-numerals';

Vue.use(VueNumerals);
Vue.use(VueNumerals); // default locale is 'en'

// with options
Vue.use(VueNumerals, {
Expand All @@ -47,10 +47,10 @@ Inside your component:
```vue
<template>
<div>
<!-- With french locale, it will display: `12 345` -->
<!-- Will display: `12,345` -->
<p>{{ count | numeralFormat }}</p>
<!-- With french locale, it will display: `12 345 ` -->
<!-- Will display: `12,345 $` -->
<p>{{ count | numeralFormat('0,0[.]00 $') }}</p>
</div>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'numeral/locales';
* @param {VueConstructor} Vue
* @param {string?} locale
*/
export default function install(Vue, { locale } = { locale: null }) {
numeral.locale(locale || 'fr');
export default function install(Vue, { locale = 'en' } = {}) {
numeral.locale(locale);

Vue.filter('numeralFormat', (value, format = '0,0') => numeral(value).format(format));
}
Expand Down
22 changes: 15 additions & 7 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,36 @@ describe('filter', () => {
localVue = createLocalVue();
});

test('format with default locale (fr) and default format', () => {
test('format with default locale (en) and default format', () => {
localVue.use(VueNumerals);

wrapper = mount({ template: '<p>{{ 12345 | numeralFormat }}</p>' }, { localVue });

expect(wrapper.html()).toBe('<p>12 345</p>');
expect(wrapper.html()).toBe('<p>12,345</p>');
});

test('format with default locale (fr) and custom format', () => {
test('format with default locale (en) and custom format', () => {
localVue.use(VueNumerals);

wrapper = mount({ template: '<p>{{ 12345 | numeralFormat("0o") }}</p>' }, { localVue });

expect(wrapper.html()).toBe('<p>12345e</p>');
expect(wrapper.html()).toBe('<p>12345th</p>');
});

test('format with custom locale (en) and default format', () => {
localVue.use(VueNumerals, { locale: 'en' });
test('format with custom locale (fr) and default format', () => {
localVue.use(VueNumerals, { locale: 'fr' });

wrapper = mount({ template: '<p>{{ 12345 | numeralFormat }}</p>' }, { localVue });

expect(wrapper.html()).toBe('<p>12,345</p>');
expect(wrapper.html()).toBe('<p>12 345</p>');
});

test('format with default locale (fr) and custom format', () => {
localVue.use(VueNumerals, { locale: 'fr' });

wrapper = mount({ template: '<p>{{ 12345 | numeralFormat("0o") }}</p>' }, { localVue });

expect(wrapper.html()).toBe('<p>12345e</p>');
});

test('format with custom locale (ru) and custom format', () => {
Expand Down

0 comments on commit 4637969

Please sign in to comment.