Skip to content

Commit 98ebe1b

Browse files
authored
Merge pull request #208 from bvelastegui/master
✨ Add plugins support
2 parents 0e91899 + a824046 commit 98ebe1b

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

lib/module.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ function dayjsModule(moduleOptions) {
1212
moduleOptions.defaultLocale ||
1313
this.options.dayjs.defaultLocale ||
1414
null
15-
)
15+
),
16+
plugins: [
17+
...(this.options.dayjs.plugins || []),
18+
...(moduleOptions.plugins || []),
19+
]
1620
}
1721

1822
this.addPlugin({

lib/plugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import dayjs from 'dayjs'
22

33
<%= options.locales.map(l => `import 'dayjs/locale/${l}'`).join('\n') %>
44

5+
<%= options.plugins.map(l => `dayjs.extend(require('dayjs/plugin/${l}'))`).join('\n') %>
6+
57
<% if (options.defaultLocale) { %>
68
dayjs.locale('<%= options.defaultLocale %>')
79
<% } %>

test/fixture/nuxt.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module.exports = {
77
dev: process.env.NODE_ENV !== 'test' && process.env.NODE_ENV === 'production',
88
dayjs: {
99
locales: ['ja'],
10-
},
10+
plugins: ['advancedFormat', 'localizedFormat']
11+
}
1112
}

test/fixture/pages/plugin.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>
3+
<p data-test-id="advancedFormat">{{ advancedFormat }}</p>
4+
<p data-test-id="localized">{{ localized }}</p>
5+
</div>
6+
</template>
7+
<script>
8+
export default {
9+
asyncData(context) {
10+
return {
11+
advancedFormat: context
12+
.$dayjs('2018-08-16')
13+
.format('Do'),
14+
localized: context
15+
.$dayjs('2018-08-16')
16+
.format('ll')
17+
}
18+
}
19+
}
20+
</script>

test/system/module.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,18 @@ describe('basic', () => {
6262
const newValue = await newTextContent.jsonValue()
6363
return expect(newValue).toBe('1995/12/18(月曜日)')
6464
})
65+
66+
test('support plugins', async () => {
67+
expect.assertions(2)
68+
await page.goto(url('/plugin'))
69+
const el = await page.$('[data-test-id="advancedFormat"]')
70+
const textContent = await el!.getProperty('textContent')
71+
const value = await textContent.jsonValue()
72+
expect(value).toBe('16th')
73+
74+
const el1 = await page.$('[data-test-id="localized"]')
75+
const textContent1 = await el1!.getProperty('textContent')
76+
const value1 = await textContent1.jsonValue()
77+
return expect(value1).toBe('Aug 16, 2018')
78+
})
6579
})

0 commit comments

Comments
 (0)