cerializr
Version:
(de)serialization made easy with ES7/Typescript annotations (decorators)
38 lines (37 loc) • 1.57 kB
TypeScript
import { Indexable, JsonObject, JsonType, SerializablePrimitiveType, SerializableType } from "./interfaces";
/**
* takes an indexable object ie `<T>{ [idx: string] : T }` and for each key serializes
the object using the provided class type.
* @param source - an indexable object
* @param type - Type to serialize
*
* @return Indexable object of JsonType
*/
export declare function SerializeMap<T extends Indexable>(source: T, type: SerializableType<T>): Indexable<JsonType>;
/**
* takes an array of objects and serializes each entry using the provided class type
*
* @param source - An array of objects
* @param type - Type to serialize each entry of the array
*
* @return Array of JsonType
*/
export declare function SerializeArray<T>(source: Array<T>, type: SerializableType<T>): Array<JsonType>;
export declare function SerializePrimitive<T>(source: SerializablePrimitiveType, type: SerializablePrimitiveType): JsonType;
/**
* takes any value and serializes it as json, no structure is assumed
and any serialization annotations on any processed objects are totally ignored.
* @param source
* @param transformKeys
*
* @return JsonType
*/
export declare function SerializeJSON(source: any, transformKeys?: boolean): JsonType;
/**
* takes a single object and serializes it using the provided class type.
* @param instance - A single object to serialize
* @param type - Type to serialize the instance
*
* @return A JsonObject or null
*/
export declare function Serialize<T>(instance: T, type: SerializableType<T>): JsonObject | null;