Module: Cecil::Lang::TypeScript::Helpers
- Includes:
- Code::Helpers
- Defined in:
- lib/cecil/lang/typescript.rb
Overview
rubocop:disable Style/Documentation
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 escaped version of the string that can be inserted into a JavaScript string literal or template literal.
-
#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.
64 |
# File 'lib/cecil/lang/typescript.rb', line 64 def j(item) = item.to_json |
#l(items) ⇒ String
Short for "list"; Accepts one or a list of strings and returns them joined with ", "
Useful for:
- arrays
- objects
- function arguments
48 |
# File 'lib/cecil/lang/typescript.rb', line 48 def l(items) = Array(items).compact.join(", ") |
#s(item) ⇒ String
Short for "string content"; returns escaped version of the string that can be inserted into a JavaScript string literal or template literal.
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.
91 |
# File 'lib/cecil/lang/typescript.rb', line 91 def s(item) = item.to_s.to_json[1...-1].gsub(/['`\$]/) { "\\#{_1}" } |
#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(" | ") |