recital / core / dist / lib / tools / expose-meta.js
expose-meta.js
Raw
"use strict";
/**
 * Copyright (c) 2022 Amorphous
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.exposeMeta = void 0;
/**
 * Pulls out ids and classes of an object.
 * Modifies in place, so does not return anything.
 * @param obj
 */
const exposeMeta = (obj) => {
    if (!obj.meta) {
        return;
    }
    // pull out id and classes
    if (obj.meta.id) {
        obj.id = obj.meta.id;
    }
    if (obj.meta.classes) {
        obj.classes = obj.meta.classes;
    }
    if (obj.id) {
        obj.primary = obj.id;
    }
    else if (obj.classes && obj.classes.length) {
        obj.primary = obj.classes[0];
    }
    if (obj.meta.title) {
        obj.title = obj.meta.title;
    }
};
exports.exposeMeta = exposeMeta;