UNPKG

sussy-util

Version:
22 lines (21 loc) 792 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Converts the attributes of a mutable object into an array. * @template T - The type of the attributes. * @param {MutableObject<T>} obj - The mutable object whose attributes will be converted. * @param {boolean} [removeNull] - Optional. Specifies whether to remove null values from the resulting array. * @returns {T[]} An array containing the attributes of the mutable object. */ const attributesToArray = (obj, removeNull = false) => { if (!obj || typeof obj !== 'object') { return []; } if (Array.isArray(obj)) { return obj; } return Object.keys(obj) .map((e) => obj[e]) .filter((obj) => !removeNull || obj); }; exports.default = attributesToArray;