feat: register cast package to jsmod

This commit is contained in:
AI Engineer 2026-05-30 17:16:05 +08:00
parent 286e5e7317
commit ca82edea01
3 changed files with 36 additions and 1 deletions

4
go.mod
View File

@ -1,3 +1,5 @@
module apigo.cc/go/cast module apigo.cc/go/cast
go 1.25 go 1.25.0
require apigo.cc/go/jsmod v1.0.0

2
go.sum
View File

@ -0,0 +1,2 @@
apigo.cc/go/jsmod v1.0.0 h1:lVQMq0tCno4kbHlQ3j5wzsm+v24J+bznIoHxpton0pE=
apigo.cc/go/jsmod v1.0.0/go.mod h1:bmyeZtOAP/j5am+YRnaiM89smysK24K7ebk0koFtsSw=

31
js_export.go Normal file
View File

@ -0,0 +1,31 @@
package cast
import (
"apigo.cc/go/jsmod"
)
func init() {
jsmod.Register("cast", map[string]any{
// JSON
"toJSON": ToJSON,
"prettyJSON": PrettyToJSON,
"fromJSON": func(data any) (any, error) {
var res any
err := UnmarshalJSON(data, &res)
return res, err
},
// Time
"now": Now,
"parseTime": ParseTime,
"formatTime": FormatTime,
"addTime": AddTime,
"duration": Duration,
"describeDuration": DescribeDuration,
// Logic
"split": Split,
"splitArgs": SplitArgs,
"joinArgs": JoinArgs,
})
}