🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@nuxtjs/date-fns

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/date-fns

Modern JavaScript date utility library - date-fns for Nuxt.js

latest
Source
npmnpm
Version
1.5.0
Version published
Weekly downloads
2.5K
5.08%
Maintainers
1
Weekly downloads
 
Created
Source

@nuxtjs/date-fns

npm version npm downloads Github Actions CI Codecov License

Modern JavaScript date utility library - date-fns for Nuxt.js

đź“– Release Notes

Setup

  • Add @nuxtjs/date-fns dependency to your project
yarn add --dev @nuxtjs/date-fns # or npm install --save-dev @nuxtjs/date-fns
  • Add @nuxtjs/date-fns to the buildModules section of nuxt.config.js
export default {
  buildModules: [
    // Simple usage
    '@nuxtjs/date-fns',

    // With options
    ['@nuxtjs/date-fns', { /* module options */ }]
  ]
}

:warning: If you are using Nuxt < v2.9 you have to install the module as a dependency (No --dev or --save-dev flags) and use modules section in nuxt.config.js instead of buildModules.

Using top level options

export default {
  buildModules: [
    '@nuxtjs/date-fns'
  ],
  dateFns: {
    /* module options */
  }
}

Typescript setup

Add the types to your "types" array in tsconfig.json after the @nuxt/types entry.

:warning: Use @nuxt/vue-app instead of @nuxt/types for nuxt < 2.9.

tsconfig.json

{
  "compilerOptions": {
    "types": [
      "@nuxt/types",
      "@nuxtjs/date-fns"
    ]
  }
}

Why?

For typescript to be aware of the additions to the nuxt Context, the vue instance and the vuex store, the types need to be merged via declaration merging by adding @nuxtjs/date-fns to your types.

Options

locales

  • Type: Array[String]
  • Default: []

Locales to be imported.

defaultLocale

  • Type: String
  • Default: null

You can preset default locale.

fallbackLocale

  • Type: String
  • Default: null

You can preset a fallback locale for when a method is called with an unsupported locale.

format

  • Type: String
  • Default: null

You can preset default format.

methods

  • Type: Array
  • Default: null

Methods to be imported. If not defined all methods are imported.

Usage

This module inject $dateFns to your project:

<template>
  <div>
    // Using default format and locale
    {{ $dateFns.format(new Date()) }}

    // Using custom format
    {{ $dateFns.format(new Date(), 'yyyy-MM-dd') }}

    // Using custom format and locale
    {{ $dateFns.format(new Date(), 'yyyy-MM-dd', { locale: 'ru' }) }}

    // Using asyncData
    {{ dateFormatted }}
  </div>
</template>

<script>
export default {
  asyncData({ $dateFns }) {
    return {
      dateFormatted: $dateFns.format(new Date())
    }
  }
}
</script>

Development

  • Clone this repository
  • Install dependencies using yarn install or npm install
  • Start development server using npm run dev

License

MIT License

Copyright (c) Nuxt Community

FAQs

Package last updated on 29 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts