UNPKG

@rzl-zone/utils-js

Version:

A modern, lightweight set of JavaScript utility functions with TypeScript support for everyday development, crafted to enhance code readability and maintainability.

36 lines (32 loc) 1.32 kB
/*! * ==================================================== * Rzl Utils-JS. * ---------------------------------------------------- * Version: 3.11.0. * Author: Rizalvin Dwiky. * Repository: https://github.com/rzl-zone/utils-js. * ==================================================== */ import { isArray, isObject, assertIsPlainObject, hasOwnProp, assertIsBoolean } from './chunk-MSUW5VHZ.js'; var isEmptyArray = (value) => { if (!isArray(value)) return true; return value.length === 0; }; function isEmptyObject(value, options = {}) { if (!isObject(value)) { return true; } assertIsPlainObject(options, { message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.` }); const checkSymbols = hasOwnProp(options, "checkSymbols") ? options.checkSymbols : false; assertIsBoolean(checkSymbols, { message: ({ currentType, validType }) => `Parameter \`checkSymbols\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.` }); const hasNoKeys = Object.keys(value).length === 0; if (checkSymbols) { return hasNoKeys && Object.getOwnPropertySymbols(value).length === 0; } return hasNoKeys; } export { isEmptyArray, isEmptyObject };