mdhost 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -0
  3. data/VERSION +1 -1
  4. data/lib/mdhost.rb +11 -5
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a8134394649ff658a0481ef6c3e320f778e560154f4d07e873c3f56d28b1f77
4
- data.tar.gz: 40438e7e07e3de5b341c05ee553f14d554329a51c8f688b2326ea63dabb4935d
3
+ metadata.gz: 46252ce5e38effe36d8920e2737cedf6fcb53bd3536d3b9d60c4696e1c2cd8f2
4
+ data.tar.gz: ab71ddc064792091175d0fe2160bf49d84ba6790ab1c9e4ad3834cc580969b1e
5
5
  SHA512:
6
- metadata.gz: 60b49b4c61d662da9335cfd1413b7aedd99e90f624ae0424d99444f0e1a1acea3bf336d660c54fd3237cc9ba20c2b37ddfe98783df63c83a5baf2ac63e3a47da
7
- data.tar.gz: 3c8ecc633e616d5c1863e2a3dceaac95a53c5a270fb51b3c13d8e9af65c29c6b9c9e138eb04da04e1b2834c577df9f55417a66f8fee68232632c2c3cbc2ec48a
6
+ metadata.gz: 460436997058ddbbee346cc12156cec627dd965121e219d46537791d5fe89ccaca5a9b03a00cb397207fada340591dc975345b3ae813fa7b0e9c077cdcf1ef99
7
+ data.tar.gz: 757a7c9ae0e18b9a71c0f0b4383dfe88525c1833d8fbf7c6960ee9e088aee5b0fc2380fb8d0f0c0d65fc9a66c0c0ce567bbc9f04137b6a04171d6e10d4c9a7f3
data/README.md CHANGED
@@ -3,3 +3,88 @@
3
3
  Runs `eshost`, displays the table output in the terminal, and generates a
4
4
  Markdown table of a few of the results (JavaScriptCore, SpiderMonkey, and V8),
5
5
  copying it to your clipboard.
6
+
7
+ ## Installation
8
+
9
+ Install via [RubyGems](https://rubygems.org/gems/mdhost):
10
+
11
+ ```sh
12
+ gem install mdhost
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Single input
18
+
19
+ Given a single input, `mdhost` will output the table from `eshost -t` to your
20
+ terminal, and will copy to your clipboard a markdown code block containing the
21
+ relevant `eshost` command, followed by a markdown table of the results. For
22
+ example, running this:
23
+
24
+ ```sh
25
+ mdhost 'Date.parse("0")'
26
+ ```
27
+
28
+ Will output the following markdown to your clipboard:
29
+
30
+ ```
31
+ > eshost -te 'Date.parse("0")'
32
+ ```
33
+ |Engine |Result |
34
+ |--------------|---------------|
35
+ |JavaScriptCore|-62167219200000|
36
+ |SpiderMonkey |NaN |
37
+ |V8 |946710000000 |
38
+
39
+ ### Multiple inputs
40
+
41
+ You can have multiple unrelated inputs at once, and a more complex table will
42
+ be generated. For example, running this:
43
+
44
+ ```sh
45
+ mdhost '"hello"' "42"
46
+ ```
47
+
48
+ Will output the following markdown to your clipboard:
49
+
50
+ |Input|JavaScriptCore|SpiderMonkey|V8
51
+ |---|---|---|---
52
+ |`"hello"`|hello|hello|hello
53
+ |`42`|42|42|42
54
+
55
+ ### Format inputs
56
+
57
+ If you have multiple similar inputs, for example arguments to a function, you
58
+ can format them into a string passed into the `--format` or `-f` parameter. The
59
+ substring `#{}` in the format string will be replaced by each of the multiple
60
+ arguments that follow and arranged into a table. For example, running this:
61
+
62
+ ```sh
63
+ mdhost -f 'Date.parse("#{}")' "1970-01-01" "Thu 1970-01-01" "Thu Jan.01.1970"
64
+ ```
65
+
66
+ Will output the following markdown to your clipboard:
67
+
68
+ |Input|JavaScriptCore|SpiderMonkey|V8
69
+ |---|---|---|---
70
+ |`Date.parse("1970-01-01")`|0|0|0
71
+ |`Date.parse("Thu 1970-01-01")`|NaN|25200000|25200000
72
+ |`Date.parse("Thu Jan.01.1970")`|NaN|25200000|25200000
73
+
74
+ You can also use the `--table-format` or `-t` parameter to specify a different
75
+ format string for the "Input" column of the table. For example, if you wanted
76
+ the inputs to the function in the previous example to simply be displayed
77
+ surrounded by quotation marks, you could run:
78
+
79
+ ```sh
80
+ mdhost -f 'Date.parse("#{}")' -t '"#{}"' "1970-01-01" "Thu 1970-01-01" "Thu Jan.01.1970"
81
+ Date.parse("1970-01-01")
82
+ ```
83
+
84
+ And the following markdown would be output to your clipboard:
85
+
86
+ |Input|JavaScriptCore|SpiderMonkey|V8
87
+ |---|---|---|---
88
+ |`"1970-01-01"`|0|0|0
89
+ |`"Thu 1970-01-01"`|NaN|25200000|25200000
90
+ |`"Thu Jan.01.1970"`|NaN|25200000|25200000
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4
1
+ 0.5
data/lib/mdhost.rb CHANGED
@@ -24,6 +24,7 @@ module MDHost
24
24
  Options:
25
25
  BANNER
26
26
 
27
+ opt :execute, "Execute the input using `eshost -x`", short: :x
27
28
  opt :format, "Format string to compose multiple inputs into", type: :string
28
29
  opt :table_format, 'Format string to use for the table "Input" column', type: :string
29
30
 
@@ -38,6 +39,7 @@ module MDHost
38
39
  end
39
40
 
40
41
  def run
42
+ @eshost_mode = @options.execute ? "x" : "e"
41
43
  @format_string = @options.format
42
44
 
43
45
  if !@format_string && ARGV.length > 1
@@ -66,11 +68,11 @@ module MDHost
66
68
  end
67
69
 
68
70
  def display_table(input)
69
- system("eshost", "-h", "JavaScriptCore,SpiderMonkey,V8", "-te", input)
71
+ system("eshost", "-g", "jsc,jsshell,d8", "-t#{@eshost_mode}", input)
70
72
  end
71
73
 
72
74
  def results_for(escaped_input)
73
- result = `eshost -e #{escaped_input}`.split(/\n+/)
75
+ result = `eshost -g jsc,jsshell,d8 -#{@eshost_mode} #{escaped_input}`.split(/\n+/)
74
76
 
75
77
  # We can't just #each_slice by 2, because sometimes an engine acts up and
76
78
  # produces no output, which would mess up the grouping. So, we need to
@@ -78,8 +80,12 @@ module MDHost
78
80
  # line as the result.
79
81
  table = {}
80
82
  result.each_with_index do |line, i|
81
- if %w[JavaScriptCore SpiderMonkey V8].any? { |e| line.end_with? e }
82
- table[line.match(/\w+/).to_s.to_sym] = result[i + 1]
83
+ engine_name = %w[JavaScriptCore SpiderMonkey V8].find do |engine|
84
+ line.downcase.end_with?(engine.downcase)
85
+ end
86
+
87
+ if engine_name
88
+ table[engine_name.to_sym] = result[i + 1]
83
89
  end
84
90
  end
85
91
 
@@ -104,7 +110,7 @@ module MDHost
104
110
 
105
111
  output = <<~EOS
106
112
  ```
107
- > eshost -te #{escaped_input}
113
+ > eshost -t#{@eshost_mode} #{escaped_input}
108
114
  ```
109
115
  |Engine#{' ' * (engine_length - 6)}|Result#{' ' * (result_length - 6)}|
110
116
  |#{'-' * engine_length}|#{'-' * result_length}|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdhost
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-25 00:00:00.000000000 Z
11
+ date: 2023-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard