UNPKG

@bjesuiter/serializr-helpers

Version:

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

24 lines (23 loc) 1.5 kB
/// <reference types="minilog" /> /** * This serializr PropertySchema can be used with @serializable(MomentSerializationSchema) * to make moment.js Moment objects serializable * @type {PropSchema} */ import { Context, PropSchema } from 'serializr'; import moment, { Moment } from 'moment'; import { DeserializationErrorPolicy, MomentSerializationOptions } from "./moment-serialization-options"; export declare function buildSerializer(valueIfUndefined?: any, useUtc?: boolean, serializationFormat?: string): (value: moment.Moment | undefined) => any; export declare function validateDefaultDeserializeValue(defaultRestoreValue: Moment): boolean; export declare function buildDeserializer(handleErrorPolicy?: DeserializationErrorPolicy, useUtc?: boolean, defaultRestoreValue?: Moment, logger?: Minilog): (jsonValue: string, callback: (err: any, targetPropertyValue: any) => void, context?: Context | undefined) => moment.Moment; /** * This factory function returns a serialization schema for Moment objects. * * @default The default schema skips undefined moment objects in serialization and * keeps timezone offset while serialization and deserialization. * This differs from default moment.toIsoString() behavior, which converts local timestamps (with like +02:00 offset) * to UTC in serialization (Strings with Z as offset) * @param options * @constructor */ export declare function MomentSerializationSchema(options?: MomentSerializationOptions): PropSchema;