@awes-io/dayjs

0.5.0 • Public • Published

Date Convertation Module for Awes.io

Based on dayjs

Basic usage

  1. Install module yarn add @awes-io/dayjs
  2. Add module to nuxt.config.js
// nuxt.config.js

export default {
    modules: [
        // ... some other modules
        '@awes-io/dayjs'
    ]
}
  1. 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')
        }
    }
}
  1. 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

Readme

Keywords

none

Package Sidebar

Install

npm i @awes-io/dayjs

Homepage

awes.io

Weekly Downloads

18

Version

0.5.0

License

MIT

Unpacked Size

12.8 kB

Total Files

10

Last publish

Collaborators

  • illjah42
  • awescode
  • the-alex