plotly.js
Version:
The open source javascript graphing library that powers plotly
24 lines (23 loc) • 885 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fast_isnumeric_1 = __importDefault(require("fast-isnumeric"));
const numerical_1 = require("../constants/numerical");
// precompile for speed
const JUNK = /^['"%,$#\s']+|[, ]|['"%,$#\s']+$/g;
/**
* Remove common leading and trailing cruft from a value and coerce it to a number.
* Always returns either a number or BADNUM.
*
* @param v - value to clean; strings have leading/trailing junk characters stripped before numeric coercion
*/
function cleanNumber(v) {
if (typeof v === 'string')
v = v.replace(JUNK, '');
if ((0, fast_isnumeric_1.default)(v))
return Number(v);
return numerical_1.BADNUM;
}
exports.default = cleanNumber;