UNPKG

@deployport/specular-runtime

Version:

Runtime for Specular API clients with support for Node.js and Browser

54 lines (53 loc) 1.2 kB
export function CreateContentFromObject(obj) { if (obj == null) { return null; } return new Content(obj); } export function CreateContentObjectArray(potentialArray) { if (!potentialArray) { return null; } if (!Array.isArray(potentialArray)) { return null; } const array = potentialArray; const result = []; for (const obj of array) { const content = CreateContentFromObject(obj); if (!content) { result.push(null); continue; } result.push(content); } return result; } export default class Content { properties; constructor(properties) { if (properties) { this.properties = properties; } else { this.properties = {}; } } setProperty(key, value) { if (this.properties == null) { this.properties = {}; } this.properties[key] = value; } getProperty(key) { if (this.properties == null) { return null; } return this.properties[key]; } toJSON() { return { ...this.properties, }; } }