packageDocumentation module import { Descriptor , DescriptorJSON } from "./Descriptor" ; import { Item , ItemJSON } from "./Item" ; public export interface ContentJSON { descriptor : DescriptorJSON ; contentSet : ItemJSON [ ] ; } public export class Content { /** Descriptor used to create the content */ public readonly descriptor : Descriptor ; /** Content items */ public readonly contentSet : Item [ ] ; /** Create a new [[Content]] instance */ public constructor ( descriptor , items ) { this . descriptor = descriptor ; this . contentSet = items ; } /** Serialize this object to JSON */ public toJSON ( ) { return { descriptor : this . descriptor . toJSON ( ) , contentSet : this . contentSet . map ( ( item ) => item . toJSON ( ) ) } ; } /** Deserialize [[Content]] from JSON */ public static fromJSON ( json ) { if ( ! json ) return undefined ; if ( typeof json === "string" ) return JSON . parse ( json , Content . reviver ) ; const descriptor = Descriptor . fromJSON ( json . descriptor ) ; if ( ! descriptor ) return undefined ; const contentSet = json . contentSet . map ( ( itemJson ) => Item . fromJSON ( itemJson ) ) . filter < Item > ( ( item ) : item is Item => ( item !== undefined ) ) ; return new Content ( descriptor , contentSet ) ; } internal public static reviver ( key , value ) { return key === "" ? Content . fromJSON ( value ) : value ; } }