/**
 * @since Last modified: 2024-01-16 06:51:56
 * @function toNumber
 * @description Convert the string to a number or format the number.
 * @param {string | number} data - The value to be converted.
 * @param {object} [options] - Parameters object.
 * @param  {'ceil'|'floor'|'round'} [options.mode="round"] - Convert mode, the default "" is turning directly to ordinary numbers, you can choose "round" (four houses and five entry), "floor" or "ceil".
 * @param  {number} [options.places=-1] - After retaining the decimal.The default is -1, which is equivalent to only doing numerical conversion.
 * @param  {boolean} [options.zero=false] - Whether to supplement the decimal zero.
 * @param  {boolean} [options.epsilon=true] - Whether to use the Number.EPSILON method to correct the value.
 * @returns {number|string} Return a number or string(use options.zero).
 * @see {@link https://codepen.io/axui/pen/oNVBqaZ|demo @ codepen}
 * @example
 * ax.toNumber('235');
 * <!--return numbner 235-->
 */
'use strict';
const toNumber = (data, opt) => {
    let result = 0, number = Number(data), options = Object.assign({ places: 10, mode: 'round', zero: false, epsilon: true }, opt);
    if (!data || !number) {
        return 0;
    }
    if (options.places < 0) {
        return number;
    }
    else {
        let precise = number + (options.epsilon ? Number.EPSILON : 0), tail = Number(`1${'0'.repeat(options.places)}`), tempPrecise = precise * tail;
        if (options.mode === 'floor') {
            result = Math.floor(tempPrecise) / tail;
        }
        else if (options.mode === 'ceil') {
            result = Math.ceil(tempPrecise) / tail;
        }
        else {
            result = Math.round(tempPrecise) / tail;
        }
        if (options.zero) {
            let decPlaces = result.toString().split(".")[1]?.length || 0;
            options.places > decPlaces ? result = result + (!decPlaces ? '.' : '') + ('0'.repeat(options.places - decPlaces)) : null;
        }
        return result;
    }
};
export default toNumber;
