doc/resultFormats.html
<!DOCTYPE html><html lang="en"><head><title>resultFormats</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="resultFormats"><meta name="groc-project-path" content="lib/resultFormats.js"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">lib/resultFormats.js</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="kd">var</span> <span class="nx">rf</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="p">;</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Result formatters take a result object and output it,
applying a specified format.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Convert result to long format:
an array of objects, where each
object contains a single instance of an element capture.</p></div></div><div class="code"><div class="wrapper"><span class="nx">rv</span><span class="p">.</span><span class="nx">longJSON</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="k">new</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'object'</span><span class="p">)</span> <span class="p">{</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>iterate over key-value pairs
splitting container values into one object per value</p></div></div><div class="code"><div class="wrapper"> <span class="p">}</span>
<span class="p">}</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Convert result to wide format:
An object where each key has a value
which contains all instances of captured elements matching the key.</p></div></div><div class="code"><div class="wrapper"><span class="nx">rv</span><span class="p">.</span><span class="nx">wideJSON</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="k">new</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'array'</span><span class="p">)</span> <span class="p">{</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>iterate through array adding object contents
to new and aggregating values with matched keys into containers</p></div></div><div class="code"><div class="wrapper"> <span class="p">}</span>
<span class="p">}</span></div></div></div></div></body></html>