voca
Version:
The ultimate JavaScript string library
32 lines (28 loc) • 773 B
JavaScript
import { i as isNil } from './internal/is_nil.js';
/**
* Checks whether `subject` is numeric.
*
* @function isNumeric
* @static
* @since 1.0.0
* @memberOf Query
* @param {string} [subject=''] The string to verify.
* @return {boolean} Returns `true` if `subject` is numeric or `false` otherwise.
* @example
* v.isNumeric('350');
* // => true
*
* v.isNumeric('-20.5');
* // => true
*
* v.isNumeric('1.5E+2');
* // => true
*
* v.isNumeric('five');
* // => false
*/
function isNumeric(subject) {
var valueNumeric = typeof subject === 'object' && !isNil(subject) ? Number(subject) : subject;
return (typeof valueNumeric === 'number' || typeof valueNumeric === 'string') && !isNaN(valueNumeric - parseFloat(valueNumeric));
}
export default isNumeric;