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.

54 lines (50 loc) 1.97 kB
/*! * ==================================================== * Rzl Utils-JS. * ---------------------------------------------------- * Version: 3.11.0. * Author: Rizalvin Dwiky. * Repository: https://github.com/rzl-zone/utils-js. * ==================================================== */ import { isFinite } from './chunk-CCJ2MSN7.js'; import { isEmptyArray } from './chunk-GOFINGT6.js'; import { isBigInt } from './chunk-QNKGP5DY.js'; import { isNil, isArray, assertIsPlainObject, hasOwnProp, assertIsBoolean, isString, isBoolean, isNull } from './chunk-MSUW5VHZ.js'; function filterNilArray(input) { if (isNil(input)) return void 0; if (!isArray(input)) return []; const filtered = input.reduce((output, element) => { if (!isNil(element)) { if (isArray(element)) { const cleanedNested = filterNilArray(element); if (cleanedNested && !isEmptyArray(cleanedNested)) { output.push(cleanedNested); } } else { output.push(element); } } return output; }, []); return filtered; } function toStringArrayUnRecursive(array, options = {}) { assertIsPlainObject(options, { message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.` }); const riv = hasOwnProp(options, "removeInvalidValue") ? options.removeInvalidValue : true; assertIsBoolean(riv, { message: ({ currentType, validType }) => `Parameter \`removeInvalidValue\` property of the \`options\` (second parameter) must be of type \`${validType}\`, but received: \`${currentType}\`.` }); if (isArray(array)) { const result = Array.from(array, (x) => { if (isString(x) || isFinite(x) || isBoolean(x) || isBigInt(x)) return String(x); return isNull(x) ? null : void 0; }); if (riv) return filterNilArray(result); return result; } return void 0; } export { filterNilArray, toStringArrayUnRecursive };