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

Method parseNumber

src/common/json5.ts:208–237  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

206 }
207
208 private parseNumber(): number {
209 const start = this.index;
210
211 // Check explicitly for signed Infinity
212 if (this.text.startsWith('-Infinity', this.index)) {
213 this.index += '-Infinity'.length;
214 return -Infinity;
215 }
216 if (this.text.startsWith('+Infinity', this.index)) {
217 this.index += '+Infinity'.length;
218 return Infinity;
219 }
220 if (this.text.startsWith('Infinity', this.index)) {
221 this.index += 'Infinity'.length;
222 return Infinity;
223 }
224
225 // Otherwise, collect a typical number literal.
226 while (!this.isAtEnd() && /[0-9+\-_.eE]/.test(this.currentChar())) {
227 this.index++;
228 }
229 const token = this.text.slice(start, this.index);
230 // Remove underscores (allowed in JSON5)
231 const normalized = token.replace(/_/g, '');
232 const num = Number(normalized);
233 if (isNaN(num)) {
234 throw this.error(`Invalid number: ${token}`);
235 }
236 return num;
237 }
238
239 private parseIdentifier(): any {
240 const start = this.index;

Callers 1

parseValueMethod · 0.95

Calls 6

isAtEndMethod · 0.95
currentCharMethod · 0.95
errorMethod · 0.95
isNaNFunction · 0.85
sliceMethod · 0.65
replaceMethod · 0.65

Tested by

no test coverage detected