fix #115 - support toJson and toJSON (#116)

This commit is contained in:
Casey Lee
2020-02-28 15:20:31 -08:00
committed by GitHub
parent 45839d68ec
commit e9de6ca2c0
2 changed files with 5 additions and 2 deletions

View File

@@ -166,14 +166,16 @@ func vmJoin(vm *otto.Otto) {
}
func vmToJSON(vm *otto.Otto) {
_ = vm.Set("toJSON", func(o interface{}) string {
toJSON := func(o interface{}) string {
rtn, err := json.MarshalIndent(o, "", " ")
if err != nil {
logrus.Errorf("Unable to marsal: %v", err)
return ""
}
return string(rtn)
})
}
_ = vm.Set("toJSON", toJSON)
_ = vm.Set("toJson", toJSON)
}
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {