MCPcopy Create free account
hub / github.com/buke/quickjs-go / normalizeInt

Function normalizeInt

benchcmp/engines.go:306–325  ·  view source on GitHub ↗
(value any)

Source from the content-addressed store, hash-verified

304}
305
306func normalizeInt(value any) (int64, error) {
307 switch current := value.(type) {
308 case int:
309 return int64(current), nil
310 case int32:
311 return int64(current), nil
312 case int64:
313 return current, nil
314 case float64:
315 return int64(current), nil
316 case string:
317 parsed, err := strconv.ParseInt(current, 10, 64)
318 if err != nil {
319 return 0, fmt.Errorf("parse int %q: %w", current, err)
320 }
321 return parsed, nil
322 default:
323 return 0, fmt.Errorf("unsupported integer result type %T", value)
324 }
325}
326
327func wrapQJSScript(script string) string {
328 return script

Callers 2

evalIntMethod · 0.85
evalIntMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected