![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@mkody/dayjs-nuxt
Advanced tools
Fast 2kB alternative to Moment.js with the same modern API
Day.js Nuxt Module supporting v3
@mkody/dayjs-nuxt
as a dependency to your projectnpm install --save-dev @mkody/dayjs-nuxt
# or
pnpm add -D @mkody/dayjs-nuxt
# or
yarn add -D @mkody/dayjs-nuxt
@mkody/dayjs-nuxt
to the modules
section of nuxt.config.ts
export default defineNuxtConfig({
modules: [
'@mkody/dayjs-nuxt'
]
})
You can use the provided $dayjs
to access Day.js in template.
<template>
<div>
<time :datetime="$dayjs('2023-01-01').utc().toString()"> {{ date }} </time>
</div>
</template>
You can use the useDayjs composable to access Day.js anywhere.
<script setup>
import { useDayjs } from '#dayjs' // not need if you are using auto import
const dayjs = useDayjs()
dayjs.locale('fr')
dayjs.extend(...)
</script>
You can specify any amount of locales, plugins, set a default locale, and set a default timezone
export default defineNuxtConfig({
modules: ['@mkody/dayjs-nuxt'],
dayjs: {
locales: ['en', 'fr'],
plugins: ['relativeTime', 'utc', 'timezone'],
defaultLocale: 'en',
defaultTimezone: 'America/New_York',
}
})
export default defineNuxtConfig({
modules: ['@mkody/dayjs-nuxt'],
dayjs: {
...
externalPlugins: [{
name: 'dayjsBusinessDays',
package: 'dayjs-business-days2',
option: {
holidays: [`2023-12-26`],
holidayFormat: `YYYY-MM-DD`,
}
}]
...
}
})
Instead of a locale string in defaultLocale:
, you can define an array with a custom locale. See dayjs customization for more information.
Here is an example for a relativeTime configuration, lets create one that Gollum would understand:
export default defineNuxtConfig({
modules: ['@mkody/dayjs-nuxt'],
dayjs: {
...
defaultLocale: ['en', {
relativeTime: {
future: "in %s",
past: "%s ago",
s: 'a few secondses',
m: "a minute",
mm: "%d minuteses",
h: "an hour",
hh: "%d hourses",
d: "a day",
dd: "%d dayses",
M: "a month",
MM: "%d monthseses",
y: "a year",
yy: "%d yearseses"
}
}]
...
}
})
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release
FAQs
Day.JS Module for Nuxt
We found that @mkody/dayjs-nuxt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.