@awes-io/dayjs
v0.5.0
Published
Date convertation module for Awes.io
Downloads
212
Readme
Date Convertation Module for Awes.io
Based on dayjs
Basic usage
- Install module
yarn add @awes-io/dayjs
- Add module to
nuxt.config.js
// nuxt.config.js
export default {
modules: [
// ... some other modules
'@awes-io/dayjs'
]
}
- Now you are ready to use it
By default, the module will parse i18n.locales
in nuxt.config.js
to load additional localization
<template>
<div>
{{ $dayjs(new Date()).format('DD/MM/YYYY') }}
</div>
</template>
export default {
data() {
return {
date: new Date()
}
},
computed: {
formatted() {
return this.$dayjs(this.date).format('HH:mm:ss')
}
}
}
- Additional configuration
// nuxt.config.js
export default {
modules: [
// ... some other modules
'@awes-io/dayjs'
],
awesIo: {
// default configuration
dayjs: {
stringFormat: {
pattern: null,
format: true
},
plugins: [
'dayjs/plugin/customParseFormat',
'dayjs/plugin/localizedFormat'
]
}
}
}
You may provide default format for parsing and formatting string dates, like this:
export default {
modules: [
// ... some other modules
'@awes-io/dayjs'
],
awesIo: {
dayjs: {
// parse and format...
stringFormat: 'YYYY-MM-DD[T]HH:mm:ssZZ'
// ...or parsing only
// stringFormat: {
// pattern: 'YYYY-MM-DD[T]HH:mm:ssZZ',
// format: false
// }
}
}
}
To add more plugins, pass an array to plugins
property, they will be merged with defaults
export default {
modules: [
// ... some other modules
'@awes-io/dayjs'
],
awesIo: {
dayjs: {
plugins: [
'dayjs/plugin/relativeTime',
{ src: '~/assets/js/my-plugin', options: { something: true } }
]
}
}
}
Ensure to write proper commit message according to Git Commit convention