UNPKG

@bjesuiter/serializr-helpers

Version:

Provides some helper functions and serialization PropertySchemas for mobxjs/serializr - library

51 lines (50 loc) 2.13 kB
/** * This serializr PropertySchema can be used with @serializable(MomentSerializationSchema) * to make moment.js Moment objects serializable * @type {PropSchema} */ import { PropSchema } from 'serializr'; import { JsonType } from "./json-type"; /** * This is the default serialization schema. * It skips undefined moment objects and uses local time deserialization with `moment()` instead of moment.utc(); */ export declare const MomentIsoSerialization: PropSchema; export declare class MomentSerializationSchema { constructor(); } export declare namespace MomentSerializationSchema { class Builder { valueIfUndefined?: JsonType; useUtcFlag: boolean; serializationFormat: string | 'ISO'; constructor(); /** * This value will be returned, if the moment value is undefined, which should have been serialized, * It must be a JSON compatible value. * This means, it must be of one type of: string | boolean | number | object | []. * If this is not set, this moment value will be skipped in serialization. * * Applies only to serialization. * @param value */ useValueIfUndefined(value: JsonType): this; /** * Uses moment.utc() instead of moment(), which parses the variable as utc * and does not convert the time into local time of the running node instance. * * Applies to serialization & deserialization */ useUtc(): this; /** * * @param string format which is used to serialize moment objects into * @default complete RFC-3339 format, which is equal to ISO-8601, for example: 2009-01-01T12:00:00+01:00 * would be written as YYYY-MM-DDTHH:mm:ss.SSSZZ. In contrast to moment js default, * this default keeps the offset in serialization. This breaks the compatibility with javascript Date, * but if it's not needed, this is the more complete option. */ useSerializationFormat(format: string): void; build(): PropSchema; } }