Module: Cecil::Lang::TypeScript::Helpers
- Includes:
- Code::Helpers
- Defined in:
- lib/cecil/lang/typescript.rb
Instance Method Summary collapse
-
#j(item) ⇒ String
Short for "json"; returns the JSON representation of the input.
-
#l(items) ⇒ String
Short for "list"; Accepts one or a list of strings and returns them joined with
", "
. -
#s(item) ⇒ String
Short for "string content"; returns a JSON string without quotes.
-
#t(items) ⇒ String
Short for "types"; Accepts one or a list of types and returns their union.
Instance Method Details
#j(item) ⇒ String
Short for "json"; returns the JSON representation of the input.
Useful for when you have a value in Ruby and you want it as a literal value in the JavaScript/TypeScript source code.
59 |
# File 'lib/cecil/lang/typescript.rb', line 59 def j(item) = item.to_json |
#l(items) ⇒ String
Short for "list"; Accepts one or a list of strings and returns them joined with ", "
43 |
# File 'lib/cecil/lang/typescript.rb', line 43 def l(items) = Array(items).compact.join(", ") |
#s(item) ⇒ String
Short for "string content"; returns a JSON string without quotes.
Useful for inserting data into a string or for outputting a string but using quotes to make it clear to the reader what the intended output will be.
It also escapes single quotes and backticks so that it can be inserted into single-quoted strings and string templates.
85 |
# File 'lib/cecil/lang/typescript.rb', line 85 def s(item) = item.to_s.to_json[1...-1].gsub("'", "\\\\'").gsub("`", "\\\\`") |
#t(items) ⇒ String
Short for "types"; Accepts one or a list of types and returns their union.
30 |
# File 'lib/cecil/lang/typescript.rb', line 30 def t(items) = Array(items).compact.join(" | ") |