UNPKG

doublescore

Version:

Utility functions for managing data structures and measurement.

61 lines 1.55 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var isArray = function (arg) { return Array.isArray(arg); }; exports.isArray = isArray; var isNumber = function (arg) { return typeof arg === 'number' && !isNaN(arg); }; exports.isNumber = isNumber; var isObject = function (arg) { return typeof arg === 'object' && !isArray(arg) && !(arg instanceof Number) && arg !== null; }; exports.isObject = isObject; var getType = function (arg) { // handle exceptions that typeof doesn't handle if (arg === null) { return 'null'; } else if (arg === undefined) { return 'undefined'; } else if (isArray(arg)) { return 'array'; } else if (arg instanceof Date) { return 'date'; } else if (arg instanceof RegExp) { return 'regex'; } if (arg instanceof Number) { arg = arg * 1; // TODO figure out why we do this } var typeOfVal = typeof arg; var type; // more resolution on numbers if (typeOfVal === 'number') { if (isNaN(arg)) { type = 'not-a-number'; } else if (Infinity === arg) { type = 'infinity'; } else if (Math.ceil(arg) > Math.floor(arg)) { type = 'float'; } else { type = 'integer'; } return type; } else if (typeOfVal === 'bigint') { return 'integer'; } else { return typeOfVal; } }; exports.getType = getType; //# sourceMappingURL=types.js.map