TODO (2014-02-03) jonk => document
3057
def get_tabs(tabs, options, index)
      tab_array = []

      Array(tabs).map do |tab|
        tab_hash = {}

        if tab[:anchor_string]
          tab_hash[:anchorString]             = tab[:anchor_string]
          tab_hash[:anchorXOffset]            = tab[:anchor_x_offset] || '0'
          tab_hash[:anchorYOffset]            = tab[:anchor_y_offset] || '0'
          tab_hash[:anchorIgnoreIfNotPresent] = tab[:ignore_anchor_if_not_present] || false
          tab_hash[:anchorUnits]              = 'pixels'
        end

        tab_hash[:conditionalParentLabel]   = tab[:conditional_parent_label] if tab.key?(:conditional_parent_label)
        tab_hash[:conditionalParentValue]   = tab[:conditional_parent_value] if tab.key?(:conditional_parent_value)
        tab_hash[:documentId]               = tab[:document_id] || '1'
        tab_hash[:pageNumber]               = tab[:page_number] || '1'
        tab_hash[:recipientId]              = index + 1
        tab_hash[:required]                 = tab[:required] || false

        if options[:template] == true
          tab_hash[:templateLocked]   = tab[:template_locked].nil? ? true : tab[:template_locked]
          tab_hash[:templateRequired] = tab[:template_required].nil? ? true : tab[:template_required]
        end

        if options[:sign_here_tab] == true || options[:initial_here_tab] == true
          tab_hash[:scaleValue] = tab[:scale_value] || 1
        end

        tab_hash[:xPosition]  = tab[:x_position] || '0'
        tab_hash[:yPosition]  = tab[:y_position] || '0'
        tab_hash[:name]       = tab[:name] if tab[:name]
        tab_hash[:optional]   = tab[:optional] || false
        tab_hash[:tabLabel]   = tab[:label] || 'Signature 1'
        tab_hash[:width]      = tab[:width] if tab[:width]
        tab_hash[:height]     = tab[:height] if tab[:height]
        tab_hash[:value]      = tab[:value] if tab[:value]
        tab_hash[:fontSize]   = tab[:font_size] if tab[:font_size]
        tab_hash[:fontColor]  = tab[:font_color] if tab[:font_color]
        tab_hash[:bold]       = tab[:bold] if tab[:bold]
        tab_hash[:italic]     = tab[:italic] if tab[:italic]
        tab_hash[:underline]  = tab[:underline] if tab[:underline]
        tab_hash[:selected]   = tab[:selected] if tab[:selected]

        tab_hash[:locked]     = tab[:locked] || false

        tab_hash[:list_items] = tab[:list_items] if tab[:list_items]

        tab_hash[:groupName] = tab[:group_name] if tab.key?(:group_name)
        tab_hash[:radios] = get_tabs(tab[:radios], options, index) if tab.key?(:radios)

        tab_hash[:validationMessage] = tab[:validation_message] if tab[:validation_message]
        tab_hash[:validationPattern] = tab[:validation_pattern] if tab[:validation_pattern]

        tab_array << tab_hash
      end
      tab_array
    end
28290
function afeclone(doc, i) {
    return {
      elt: createHTMLElt(doc, afe.list[i].localName, afe.attrs[i]),
      attrs: afe.attrs[i],
    };
  }
306627
function Doc(runner) {
  Base.call(this, runner);

  var self = this
    , stats = this.stats
    , total = runner.total
    , indents = 2;

  function indent() {
    return Array(indents).join('  ');
  }

  runner.on('suite', function(suite){
    if (suite.root) return;
    ++indents;
    console.log('%s<section class="suite">', indent());
    ++indents;
    console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
    console.log('%s<dl>', indent());
  });

  runner.on('suite end', function(suite){
    if (suite.root) return;
    console.log('%s</dl>', indent());
    --indents;
    console.log('%s</section>', indent());
    --indents;
  });

  runner.on('pass', function(test){
    console.log('%s  <dt>%s</dt>', indent(), utils.escape(test.title));
    var code = utils.escape(utils.clean(test.fn.toString()));
    console.log('%s  <dd><pre><code>%s</code></pre></dd>', indent(), code);
  });
}
443271
function html(obj, indents) {
  indents = indents || 1;

  function indent() {
    return Array(indents).join('  ');
  }

  if ('string' == typeof obj) {
    var str = escape(obj);
    if (urlRegex().test(obj)) {
      str = '<a href="' + str + '">' + str + '</a>';
    }
    return span('string value', '"' + str + '"');
  }

  if ('number' == typeof obj) {
    return span('number', obj);
  }

  if ('boolean' == typeof obj) {
    return span('boolean', obj);
  }

  if (null === obj) {
    return span('null', 'null');
  }

  var buf;

  if (Array.isArray(obj)) {
    ++indents;

    buf = '[\n' + obj.map(function(val){
      return indent() + html(val, indents);
    }).join(',\n');

    --indents;
    buf += '\n' + indent() + ']';
    return buf;
  }

  buf = '{';
  var keys = Object.keys(obj);
  var len = keys.length;
  if (len) buf += '\n';

  ++indents;
  buf += keys.map(function(key){
    var val = obj[key];
    key = '"' + key + '"';
    key = span('string key', key);
    return indent() + key + ': ' + html(val, indents);
  }).join(',\n');
  --indents;

  if (len) buf += '\n' + indent();
  buf += '}';

  return buf;
}
64490
function( documents ) {
    
    var key, document
    var fillwords = new Array( 0 )
    
    if( this.language && this.language.fillwords ) {
      fillwords = this.language.fillwords
    }
    
    for( key in documents ) {
      
      document = ( documents[ key ] + '' )
      document = document.toLowerCase()
      document = document.split( /\W+/ )
      
      documents[ key ] = document.reduce(
        function ( document, word ) {
          if( !~fillwords.indexOf( word ) && word !== '' ) {
            document[ word ] = ( document[ word ] ? document[ word ] + 1 : 1 )
          }
          return document
        },
        Object.create( null )
      )
      
    }
    
    return documents
    
  }
1369929
function validateVuln (doc) {
	log(`validateVuln: doc ${JSON.stringify(doc)}`);
	const validateVulnQuery = { pattern: doc.pattern, language: doc.language, evilInput: doc.evilInput, nPumps: 250000, timeLimit: 1 };

	const tmpFile = `/tmp/validate-uploads-${process.pid}.json`;
	fs.writeFileSync(tmpFile, JSON.stringify(validateVulnQuery));

	try {
		const cmd = `${process.env.VULN_REGEX_DETECTOR_ROOT}/src/validate/validate-vuln.pl ${tmpFile} 2>/dev/null`;
		const stdout = childProcess.execSync(cmd, {encoding: 'utf8'});
		const result = JSON.parse(stdout);
		log(JSON.stringify(result));
		return result.timedOut === 1;
	} catch (e) {
		log(`Error: ${JSON.stringify(e)}`);
		return false;
	} finally {
		fs.unlinkSync(tmpFile);
	}
}
463786
function() {
				var doc = this;
				var newDoc = {};
				_.forEach(this, function(v, k) {
					if (doc.hasOwnProperty(k) && !_.startsWith(k, '$')) newDoc[k] = _.clone(v);
				});

				return newDoc;
			}
1291946
function getDocument(element, callback) {
                        //Opera 12 seem to call the object.onload before the actual document has been created.
                        //So if it is not present, poll it with an timeout until it is present.
                        //TODO: Could maybe be handled better with object.onreadystatechange or similar.
                        if(!element.contentDocument) {
                            setTimeout(function checkForObjectDocument() {
                                getDocument(element, callback);
                            }, 100);

                            return;
                        }

                        callback(element.contentDocument);
                    }
1043948
function stringify(js, indent, indentUnit) {
    if (typeof indent === 'undefined') indent = '';
    if (typeof indentUnit === 'undefined') indentUnit = '  ';
    var t = typeof js;
    if (t === 'string') {
        return JSON.stringify(js);
    }
    if (t === 'number') {
        return js;
    }
    if (t === 'boolean') {
        return js ? "true" : "false";
    }
    var out = '', txt, small, lastIndent;
    if (Array.isArray(js)) {
        out = '[';
        txt = JSON.stringify(js);
        small = txt.length < 40;
        if (!small) out += "\n" + indent;
        js.forEach(
            function(itm, idx) {
                if (idx > 0) {
                    out += "," + (small ? " " : "\n" + indent);
                }
                out += stringify(itm, indent + indentUnit);
            }
        );
        out += ']';
        return out;
    }
    if (t === 'object') {
        lastIndent = indent;
        indent += indentUnit;
        out = '{';
        txt = JSON.stringify(js);
        small = txt.length < 40;
        if (!small) out += "\n" + indent;
        var k, v, idx = 0;
        for (k in js) {
            v = js[k];
            if (idx > 0) {
                out += "," + (small ? " " : "\n" + indent);
            }
            out += JSON.stringify(k) + ": " + stringify(v, indent);
            idx++;
        }
        out += (small ? "" : "\n" + lastIndent) + '}';
        return out;
    }
    return '"<' + t + '>"';
}
889020
function create (todoList, text) {
  // Hand waving here -- not showing how this interacts with XHR or persistent
  // server-side storage.
  // Using the current timestamp in place of a real id.
  var id = Date.now();
  _todos[id] = {
    id: id,
    todo_list_id: todoList.id,
    complete: false,
    text: text
  };
}
1253330
function stringJSON2JSON (doc, compact = false) {
  if (!doc || (typeof doc !== 'string' && typeof doc !== 'object')) {
    throw new TypeError('Argument must be a string or object, and not empty: ' + doc)
  }

  let obj = doc
  if (typeof doc === 'string') {
    obj = JSON.parse(doc)
  }

  return JSON.stringify(obj, undefined, compact ? undefined : 2)
}
2913
function goDoc() {
  _traverseDOM(document);
  // add standard footer
  var ftr = document.createElement("div");
  ftr.className = "footer";
  var msg = "Copyright &copy; 1998-2015 by Northwoods Software Corporation.";
  if (go && go.version) {
    msg = "GoJS&reg; version " + go.version + ". " + msg;
  }
  ftr.innerHTML = msg;
  document.body.appendChild(ftr);
}
790521
function ( arg ) {
		var obj = document.createDocumentFragment();

		if ( arg ) {
			array.each( array.cast( element.create( "div", {innerHTML: arg}, obj ).childNodes ), function ( i ) {
				obj.appendChild( i );
			});

			obj.removeChild( obj.childNodes[0] );
		}

		return obj;
	}
179875
function each(collection, callback) {
        if (utils.isNode(collection) || collection === window || collection === document) {
            collection = [collection];
        }
        if (!utils.isArrayLike(collection) && !utils.isObject(collection)) {
            collection = [collection];
        }
        if (utils.size(collection) == 0) {
            return;
        }

        if (utils.isArrayLike(collection) && !utils.isObject(collection)) {
            var l = collection.length,
                i = 0;
            for (; i < l; i++) {
                if (callback.call(collection[i], collection[i], i, collection) === false) {
                    break;
                }
            }
        } else if (utils.isObject(collection)) {
            for (var key in collection) {
                if (utils.has(collection, key)) {
                    if (callback.call(collection[key], collection[key], key, collection) === false) {
                        break;
                    }
                }
            }
        }
    }
238730
function (o) {
            var self = this;
            o = self.addFoundAt(o);
            Y.each(o, function (i, k1) {
                if (i && i.forEach) {
                    Y.each(i, function (a, k) {
                        if (!(a instanceof Object)) {
                            return;
                        }
                        if (!a.type) {
                            a.type = 'Object'; //Default type is Object
                        }
                        if (a.final === '') {
                            a.final = true;
                        }
                        if (!a.description) {
                            a.description = ' ';
                        } else {
                            //a.description = markdown(a.description, true, self.defaultTags);
                            a.description = self.markdown(a.description);
                        }
                        if (a.example) {
                            a.example = self.markdown(a.example);
                        }
                        a = self.addFoundAt(a);

                        Y.each(a, function (c, d) {
                            if (c.forEach || (c instanceof Object)) {
                                c = self.augmentData(c);
                                a[d] = c;
                            }
                        });

                        o[k1][k] = a;
                    });
                } else if (i instanceof Object) {
                    i = self.addFoundAt(i);
                    Y.each(i, function (v, k) {
                        if (k === 'final') {
                            o[k1][k] = true;
                        }
                        if (k === 'description' || k === 'example') {
                            if (k1 === 'return') {
                                o[k1][k] = self.markdown(v);
                            } else if (v.forEach || (v instanceof Object)) {
                                o[k1][k] = self.augmentData(v);
                            } else {
                                //o[k1][k] = markdown(v, true, self.defaultTags);
                                o[k1][k] = self.markdown(v);
                            }
                        }
                    });
                } else if (k1 === 'description' || k1 === 'example') {
                    //o[k1] = markdown(i, true, self.defaultTags);
                    o[k1] = self.markdown(i);
                }
            });
            return o;
        }
737830
function makeDocString(obj) {
        var docStr = obj
        if (Array.isArray(docStr)) {
            docStr = docStr.join('\n');
        }
        return docStr;
    }
1095975
function () {
            var t = this,
                documentSelection = t.doc.getSelection(),
                node = documentSelection.focusNode,
                text = new XMLSerializer().serializeToString(documentSelection.getRangeAt(0).cloneContents()),
                url,
                title,
                target;

            while (['A', 'DIV'].indexOf(node.nodeName) < 0) {
                node = node.parentNode;
            }

            if (node && node.nodeName === 'A') {
                var $a = $(node);
                text = $a.text();
                url = $a.attr('href');
                if (!t.o.minimalLinks) {
                    title = $a.attr('title');
                    target = $a.attr('target');
                }
                var range = t.doc.createRange();
                range.selectNode(node);
                documentSelection.removeAllRanges();
                documentSelection.addRange(range);
            }

            t.saveRange();

            var options = {
                url: {
                    label: 'URL',
                    required: true,
                    value: url
                },
                text: {
                    label: t.lang.text,
                    value: text
                }
            };
            if (!t.o.minimalLinks) {
                Object.assign(options, {
                    title: {
                        label: t.lang.title,
                        value: title
                    },
                    target: {
                        label: t.lang.target,
                        value: target
                    }
                });
            }

            t.openModalInsert(t.lang.createLink, options, function (v) { // v is value
                var url = t.prependUrlPrefix(v.url);
                if (!url.length) {
                    return false;
                }

                var link = $(['<a href="', url, '">', v.text || v.url, '</a>'].join(''));

                if (!t.o.minimalLinks) {
                    if (v.title.length > 0) {
                        link.attr('title', v.title);
                    }
                    if (v.target.length > 0) {
                        link.attr('target', v.target);
                    }
                }
                t.range.deleteContents();
                t.range.insertNode(link[0]);
                t.syncCode();
                t.$c.trigger('tbwchange');
                return true;
            });
        }