Skip to content

Commit

Permalink
Handle env numbers as js numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nhh committed Sep 23, 2024
1 parent f587d6d commit 3626e72
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/ts/ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/evanw/esbuild/pkg/api"
"os"
"path/filepath"
"strconv"
"strings"
)

Expand Down Expand Up @@ -56,7 +57,15 @@ func injectEnv(vm *goja.Runtime) {
continue
}

m[strings.Replace(pair[0], "K8X_", "", 1)] = pair[1]
// Try to parse stuff as number, might break stuff
// Dont know if https://1231412.de gets converted to 1231412
// Allows ts to write k8x.$env["SCALE"] instead of having to parse it: Number(k8x.$env["SCALE"])
i, err := strconv.Atoi(pair[1])
if err != nil {
m[strings.Replace(pair[0], "K8X_", "", 1)] = pair[1]
} else {
m[strings.Replace(pair[0], "K8X_", "", 1)] = i
}
}

obj := vm.NewObject()
Expand Down

0 comments on commit 3626e72

Please sign in to comment.