"use strict";
/*
 * @poppinss/utils
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDecimal = exports.isFloat = exports.isInteger = exports.isClass = exports.isFunction = exports.isError = exports.isRegexp = exports.isArray = exports.isDate = exports.isObject = exports.isArguments = exports.isString = exports.isNumber = exports.isBuffer = exports.isBoolean = exports.isNull = exports.isUndefined = exports.lookup = void 0;
const kind_of_1 = __importDefault(require("kind-of"));
const toString = Function.prototype.toString;
/**
 * Lookup the type for a given value
 */
function lookup(value) {
    const kind = (0, kind_of_1.default)(value);
    if (kind === 'function' && /^class\s/.test(toString.call(value))) {
        return 'class';
    }
    return kind;
}
exports.lookup = lookup;
/**
 * Find if a given value is undefined
 */
function isUndefined(value) {
    return lookup(value) === 'undefined';
}
exports.isUndefined = isUndefined;
/**
 * Find if a given value is null
 */
function isNull(value) {
    return lookup(value) === 'null';
}
exports.isNull = isNull;
/**
 * Find if a given value is a boolean
 */
function isBoolean(value) {
    return lookup(value) === 'boolean';
}
exports.isBoolean = isBoolean;
/**
 * Find if a given value is a buffer
 */
function isBuffer(value) {
    return lookup(value) === 'buffer';
}
exports.isBuffer = isBuffer;
/**
 * Find if a given value is a number
 */
function isNumber(value) {
    return lookup(value) === 'number';
}
exports.isNumber = isNumber;
/**
 * Find if a given value is a string
 */
function isString(value) {
    return lookup(value) === 'string';
}
exports.isString = isString;
/**
 * Find if a given value is function arguments
 */
function isArguments(value) {
    return lookup(value) === 'arguments';
}
exports.isArguments = isArguments;
/**
 * Find if a given value is a plain object
 */
function isObject(value) {
    return lookup(value) === 'object';
}
exports.isObject = isObject;
/**
 * Find if a given value is a date instance
 */
function isDate(value) {
    return lookup(value) === 'date';
}
exports.isDate = isDate;
/**
 * Find if a given value is an array
 */
function isArray(value) {
    return lookup(value) === 'array';
}
exports.isArray = isArray;
/**
 * Find if a given value is an regularExpression
 */
function isRegexp(value) {
    return lookup(value) === 'regexp';
}
exports.isRegexp = isRegexp;
/**
 * Find if a given value is an instance of Error class
 */
function isError(value) {
    return lookup(value) === 'error';
}
exports.isError = isError;
/**
 * Find if a given value is a Function
 */
function isFunction(value) {
    return lookup(value) === 'function';
}
exports.isFunction = isFunction;
/**
 * Find if a given value is a class. Uses regular expression, since there
 * is no way to natively distinguish a class and a function in Javascript
 */
function isClass(value) {
    return lookup(value) === 'class';
}
exports.isClass = isClass;
/**
 * Find if a value is an integer or not
 */
function isInteger(value) {
    return Number.isInteger(value);
}
exports.isInteger = isInteger;
/**
 * Find if a value is float value or not. The values with more than
 * zero remainder returns true
 */
function isFloat(value) {
    return value !== (value | 0);
}
exports.isFloat = isFloat;
/**
 * Find if the value has given decimal place or not.
 *
 * Since there is no direct way in Javascript to check for decimal place. We make
 * use of regex to find it out.
 *
 * Numeric values are converted to string by calling `value.toString()` before
 * testing it against the regex.
 *
 * If this method returns `true`, then you can safely parse the string with `parseFloat`
 * method.
 */
function isDecimal(value, options) {
    if (typeof value === 'number') {
        value = value.toString();
    }
    const decimalPlaces = (options && options.decimalPlaces) || '1,';
    return new RegExp(`^[-+]?([0-9]+)?(\\.[0-9]{${decimalPlaces}})$`).test(value);
}
exports.isDecimal = isDecimal;
