Giter VIP home page Giter VIP logo

nuxt-date's Introduction

Nuxt Time

npm version npm downloads Github Actions Codecov

SSR-safe time element for Nuxt 3

Features

  • ✨ SSR/SSG-safe rendering of any date/time
  • 💪 Prevents hydration mismatch on client
  • 🏁 Respects browser locale
  • ✅ Renders semantic <time> element

Installation

Install and add nuxt-time to your nuxt.config.

# Whichever matches your package manager
pnpm add -D nuxt-time
npm install -D nuxt-time
yarn add -D nuxt-time
export default defineNuxtConfig({
  modules: ['nuxt-time'],
})

Usage

To use, you can use the <NuxtTime> component anywhere in your app. It will render a spec-compliant <time> element.

It accepts datetime and locale (optional) properties, along with any property accepted by Intl.DateTimeFormat (see MDN reference). Note: you can provide a Date or number (e.g. Date.now()) via datetime and it will be rendered correctly as an ISO-formatted date.

<template>
  <!--
    Date.now() will safely respect the time on the server, not on the
    client. What's more, there will be no flash between server
    and client locale formatting.
  -->
  <NuxtTime :datetime="Date.now()" second="numeric" month="long" day="numeric" />
</template>

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Stub module with pnpm dev:prepare
  • Run pnpm dev to start playground in development mode

License

Made with ❤️

Published under the MIT License.

nuxt-date's People

Contributors

danielroe avatar mini-ghost avatar harlan-zw avatar atinux avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.