mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
36 lines
653 B
JavaScript
36 lines
653 B
JavaScript
/**
|
|
* Determine the type of a variable
|
|
*
|
|
* typeof(x)
|
|
*
|
|
* @param {*} x
|
|
* @return {String} type Lower case type, for example 'number', 'string',
|
|
* 'array', 'date'.
|
|
*/
|
|
exports.type = function type (x) {
|
|
var type = typeof x;
|
|
|
|
if (type === 'object') {
|
|
if (x === null) {
|
|
return 'null';
|
|
}
|
|
if (x instanceof Boolean) {
|
|
return 'boolean';
|
|
}
|
|
if (x instanceof Number) {
|
|
return 'number';
|
|
}
|
|
if (x instanceof String) {
|
|
return 'string';
|
|
}
|
|
if (Array.isArray(x)) {
|
|
return 'array';
|
|
}
|
|
if (x instanceof Date) {
|
|
return 'date';
|
|
}
|
|
}
|
|
|
|
return type;
|
|
};
|