Module: Base64

Defined in:
opal/stdlib/base64.rb

Class Method Summary collapse

Class Method Details

.decode64(string) ⇒ Object


59
60
61
# File 'opal/stdlib/base64.rb', line 59

def self.decode64(string)
  `decode(string.replace(/\r?\n/g, ''))`
end

.encode64(string) ⇒ Object


63
64
65
# File 'opal/stdlib/base64.rb', line 63

def self.encode64(string)
  `encode(string).replace(/(.{60})/g, "$1\n").replace(/([^\n])$/g, "$1\n")`
end

.strict_decode64(string) ⇒ Object


67
68
69
# File 'opal/stdlib/base64.rb', line 67

def self.strict_decode64(string)
  `decode(string)`
end

.strict_encode64(string) ⇒ Object


71
72
73
# File 'opal/stdlib/base64.rb', line 71

def self.strict_encode64(string)
  `encode(string)`
end

.urlsafe_decode64(string) ⇒ Object


75
76
77
# File 'opal/stdlib/base64.rb', line 75

def self.urlsafe_decode64(string)
  `decode(string.replace(/\-/g, '+').replace(/_/g, '/'))`
end

.urlsafe_encode64(string, padding: true) ⇒ Object


79
80
81
82
83
# File 'opal/stdlib/base64.rb', line 79

def self.urlsafe_encode64(string, padding: true)
  str = `encode(string).replace(/\+/g, '-').replace(/\//g, '_')`
  str = str.delete('=') unless padding
  str
end