base64.go 880 B

12345678910111213141516171819202122232425262728293031323334
  1. package stdlib
  2. import (
  3. "encoding/base64"
  4. "github.com/d5/tengo/v2"
  5. )
  6. var base64Module = map[string]tengo.Object{
  7. "encode": &tengo.UserFunction{
  8. Value: FuncAYRS(base64.StdEncoding.EncodeToString),
  9. },
  10. "decode": &tengo.UserFunction{
  11. Value: FuncASRYE(base64.StdEncoding.DecodeString),
  12. },
  13. "raw_encode": &tengo.UserFunction{
  14. Value: FuncAYRS(base64.RawStdEncoding.EncodeToString),
  15. },
  16. "raw_decode": &tengo.UserFunction{
  17. Value: FuncASRYE(base64.RawStdEncoding.DecodeString),
  18. },
  19. "url_encode": &tengo.UserFunction{
  20. Value: FuncAYRS(base64.URLEncoding.EncodeToString),
  21. },
  22. "url_decode": &tengo.UserFunction{
  23. Value: FuncASRYE(base64.URLEncoding.DecodeString),
  24. },
  25. "raw_url_encode": &tengo.UserFunction{
  26. Value: FuncAYRS(base64.RawURLEncoding.EncodeToString),
  27. },
  28. "raw_url_decode": &tengo.UserFunction{
  29. Value: FuncASRYE(base64.RawURLEncoding.DecodeString),
  30. },
  31. }