/**
 * @since Last modified: 2024-09-04 19:49:29
 * @function valToArr
 * @description Converts arbitrary values to array format for easier array traversal.
 * @param {any} data  - Arbitrary value.Format: 'a' or 'a,b,c' or 'a b c' or {} or 0 or 1 or [].
 * @param {string} [hyphen=',']  - Separator of string.
 * @returns {array} Returns an array of arbitrary values.
 * @see {@link https://codepen.io/axui/pen/BaEzoRp|demo @ codepen}
 * @example
 * ax.valToArr('a,b,c');
 * <!--return ['a','b','c']-->
 */
'use strict';
import config from '../global/config';
import getDataType from './getDataType';
import isNull from './isNull';
const valToArr = (data, hyphen) => {
    let dataType = getDataType(data), arr = [];
    if ([undefined, null, 'undefined', 'null', ''].includes(data)) {
        return arr;
    }
    if (dataType === 'Array') {
        arr = data.filter((k) => !isNull(k));
    }
    else if (dataType === 'String') {
        arr = data.trim().split(hyphen || config.splitHyphen);
        arr = arr.filter((k) => {
            k = k.trim();
            return k !== '' && !isNull(k);
        }).map((k) => isNaN(+k) ? k : +k);
    }
    else {
        arr.push(data);
    }
    return [...new Set(arr)];
};
export default valToArr;
