plotly.js
Version:
The open source javascript graphing library that powers plotly
23 lines (16 loc) • 475 B
JavaScript
var isNumeric = require('fast-isnumeric');
var BADNUM = require('../constants/numerical').BADNUM;
// precompile for speed
var JUNK = /^['"%,$#\s']+|[, ]|['"%,$#\s']+$/g;
/**
* cleanNumber: remove common leading and trailing cruft
* Always returns either a number or BADNUM.
*/
module.exports = function cleanNumber(v) {
if(typeof v === 'string') {
v = v.replace(JUNK, '');
}
if(isNumeric(v)) return Number(v);
return BADNUM;
};
;