1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
otto/tools/gen-jscore/helpers.go
Steven Hartland 233dfa4ef0
chore: remove perl, make and local docs. (#476)
Remove the dependencies on perl and make.

inline.pl is replaced by tools/gen-jscore and token/tokenfmt is replaced
by tools/gen-tokens which are both golang text/template utilities.

gen-jscore uses property ordering that matches chromes output ordering
adding missing properties to the Error types.

Local generated documentation have been removed as https://pkg.go.dev/
is more feature rich.

The use of make has been removed as the functionality is now replicated by
standard golang tools go test ./... and go generate ./... as well as integrated
into github actions.
2022-12-05 22:19:34 +00:00

35 lines
892 B
Go

package main
import (
"fmt"
"unicode"
)
// ucfirst converts the first rune of val to uppercase an returns the result.
func ucfirst(val string) string {
r := []rune(val)
r[0] = unicode.ToUpper(r[0])
return string(r)
}
// dict is a template helper returns a map created from alternating values.
// Values must be passed as key, value pairs with key being a string.
// It can be used to pass the combination of multiple values to a template.
func dict(values ...interface{}) (map[string]interface{}, error) {
if len(values)%2 != 0 {
return nil, fmt.Errorf("map requires parameters which are multiple of 2 got %d", len(values))
}
m := make(map[string]interface{}, len(values)/2)
for i := 0; i < len(values); i += 2 {
key, ok := values[i].(string)
if !ok {
return nil, fmt.Errorf("map keys must be strings got %T", values[i])
}
m[key] = values[i+1]
}
return m, nil
}