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

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