/**
 * @module ext/class.js
 * @author Krzysztof Putyra
 * @date Apr 01, 2025
 * @description A collection of functions to manipulate JavaScript classes.
 */


/**
 * Adds enumerable readonly static properties to a class
 * @function
 * @param {function} classConstructor 
 * @param {object} constants 
 */
export const defineConstants = (classConstructor, constants) => Object.defineProperties(
    classConstructor,
    Object.fromEntries(Object.entries(constants).map(
        ([name, value]) => [name, { value, enumerable: true, writable: false }]
    ))
);

/**
 * Copies methods of an object (or of the prototype of a class function) to a class.
 * @function
 * @param {function} classContructor 
 * @param {object|function} object 
 */
export const addMixIn = (classContructor, object) => Object.defineProperties(
    classContructor.prototope,
    Object.getOwnPropertyDescriptors(typeof object === 'function' ? object.prototype : object)
);
