UNPKG

pinia-orm-edge

Version:

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.

95 lines (89 loc) 2.02 kB
import { C as CastAttribute } from './shared/pinia-orm.C7bM_uXu.mjs'; export { B as BooleanCast } from './shared/pinia-orm.CgyvBCb2.mjs'; class ArrayCast extends CastAttribute { /** * Create a new String attribute instance. */ constructor(attributes) { super(attributes); } get(value) { return typeof value !== "string" ? value : JSON.parse(value); } /** * Make the value for the attribute. */ set(value) { return JSON.stringify(value); } } class StringCast extends CastAttribute { /** * Create a new String attribute instance. */ constructor(attributes) { super(attributes); } get(value) { return typeof value === "string" || value === void 0 || value === null ? value : `${value}`; } /** * Make the value for the attribute. */ set(value) { return this.get(value); } } class NumberCast extends CastAttribute { /** * Create a new String attribute instance. */ constructor(attributes) { super(attributes); } get(value) { if (typeof value === "number" || value === void 0 || value === null) { return value; } if (typeof value === "string") { return Number.parseFloat(value); } if (typeof value === "boolean") { return value ? 1 : 0; } return 0; } /** * Make the value for the attribute. */ set(value) { return this.get(value); } } class DateCast extends CastAttribute { /** * Create a new String attribute instance. */ constructor(attributes) { super(attributes); } get(value) { return value === null ? null : new Date(value); } /** * Make the value for the attribute. */ set(value) { if (value === null) { return null; } if (typeof value === "number") { return new Date(value).toISOString(); } if (typeof value === "string") { return new Date(Date.parse(value)).toISOString(); } return value.toISOString(); } } export { ArrayCast, DateCast, NumberCast, StringCast };