diff --git a/go.mod b/go.mod index 1e08c34..63b0967 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module apigo.cc/go/cast -go 1.25 +go 1.25.0 + +require apigo.cc/go/jsmod v1.0.0 diff --git a/go.sum b/go.sum index e69de29..c645036 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/js_export.go b/js_export.go new file mode 100644 index 0000000..785f740 --- /dev/null +++ b/js_export.go @@ -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, + }) +}