Registry / database / vuex-orm-plugin-date-attribute

vuex-orm-plugin-date-attribute

JSON →
library0.1.1jsnpmunverified

A plugin for Vuex-ORM that adds a `date` attribute type to model fields, automatically converting string/number values to JavaScript Date objects. Current stable version is 0.1.1. The plugin extends Vuex-ORM's field definition API with `this.date()` and handles serialization/deserialization. It is lightweight and has no runtime dependencies beyond Vuex-ORM. Unlike manual field transforms, it provides a declarative way to handle date attributes within Vuex-ORM's data layer.

npm install vuex-orm-plugin-date-attribute
INSTALL
IMPORT
SIG · VUEX-ORM-PLUGIN-DA
V
vuex-orm-plugin-date-attribute
databasejavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import datePlugin from 'vuex-orm-plugin-date-attribute'
const { datePlugin } = require('vuex-orm-plugin-date-attribute')
Plugin is exported as default; named import does not exist
Model.date()
class User extends Model { static fields() { return { last_login: this.date(null) } } }
this.date(null) used inside a static method but without `this` context
`this.date()` is available inside `static fields()` after installing the plugin with `VuexORM.use(datePlugin)`
VuexORM.use()
VuexORM.use(datePlugin)
VuexORM.use('vuex-orm-plugin-date-attribute')
Must pass the imported plugin object, not the package name string

Demonstrates plugin installation, model definition with this.date(), and automatic Date conversion.

import VuexORM from '@vuex-orm/core' import datePlugin from 'vuex-orm-plugin-date-attribute' import { Model } from '@vuex-orm/core' VuexORM.use(datePlugin) class User extends Model { static entity = 'users' static fields() { return { id: this.increment(), name: this.string(''), active: this.boolean(false), last_login: this.date(null), } } } // Usage: const user = new User({ id: 1, last_login: '2024-01-15T10:30:00Z' }) console.log(user.last_login instanceof Date) // true console.log(user.last_login.toISOString()) // '2024-01-15T10:30:00.000Z'
Debug
Known issues
gotcha`this.date()` must be called inside `static fields()` — calling it in instance methods will throw an error because `this` refers to the instance, not the Model class.
fix
Always use `this.date()` within the static `fields()` method of your Model subclass.
affects: >=0.1.0
gotchaDates are serialized to ISO strings when stored in Vuex; ensure your database/API expects ISO 8601 strings.
fix
Override `$toJson()` on your model if custom serialization is needed.
affects: >=0.1.0
gotchaThe plugin does not handle time zones; Dates are always converted to local time based on the runtime environment.
fix
Use a library like `date-fns-tz` if you need time zone handling.
affects: >=0.1.0
Errors
Common errors & fixes
Uncaught Error: Vuex-ORM plugin must be installed before using this attribute.
Using `this.date()` in a model before calling `VuexORM.use(datePlugin)`
fix
Call `VuexORM.use(datePlugin)` before any model definition that uses `this.date()`.
this.date is not a function
The date plugin is not installed, or `this` context is wrong (e.g., called in an instance method instead of static fields)
fix
Ensure `VuexORM.use(datePlugin)` is called. Verify `this.date()` is inside a `static fields()` method.
Cannot read property 'date' of undefined
The `Model` class might not be imported correctly or the plugin failed to register
fix
Check that `@vuex-orm/core` is installed and imported, and that the plugin is passed to `VuexORM.use()` correctly.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
@vuex-orm/corerequiredPeer dependency — required for Vuex-ORM model definition and plugin system
Agent activity
12 hits · last 30 days
node
8
Meta
2
OpenAI (training)
2
Resources
vuex-orm-plugin-date-attribute — npm install vuex-orm-plugin-date-attribute · libregistry