MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / validJSONNumber

Function validJSONNumber

test/utils.ts:265–279  ·  view source on GitHub ↗
(num: string | number)

Source from the content-addressed store, hash-verified

263 if (typeof num === 'number') return num;
264 const val = Number(num);
265 if (num[0] === '+') num = num.slice(1);
266 if (val.toString() === num) {
267 // If the number roundtrips, it can be represented by a
268 // JavaScript number
269 // However, NaN and Infinity cannot be represented by JSON
270 if (isNaN(val)) return 'NaN';
271 if (!isFinite(val) && val < 0) return 'NegativeInfinity';
272 if (!isFinite(val) && val > 0) return 'PositiveInfinity';
273 return val;
274 }
275 return { num };
276}
277
278function strip(expr: Expression): Expression | null {
279 if (typeof expr === 'number') return expr;
280 if (typeof expr === 'string') {
281 if (expr[0] === "'" && expr[expr.length - 1] === "'") {
282 return { str: expr.slice(1, -1) };

Callers 1

stripFunction · 0.85

Calls 4

isNaNFunction · 0.85
isFiniteFunction · 0.85
sliceMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected