<commit_before>// form obj 

var form = FormApp.getActiveForm();

//   | Forms
//   | - Form Management
// - | -- Array of Form Items
// - | -- Get Form Item by Name
//   | -- Set Choices from Array
// - | -- Get Destination Sheet
//   | - Form Responses
//   | -- Get Last Form Response
//   | -- Timestamps in Forms

function testEverything() {}

// Forms

// - Form Management

// -- Array of Form Items

function arrItemsIn(formObj) {
  var _arr  = [];
  var items = formObj.getItems()
  for (var i = 0; i < items.length; i++) {
    var j = {}; 
    j.index = i;
    j.title = items[i].getTitle();
    j.id    = items[i].getId();
    j.item  = items[i];
    _arr.push(j);
  }
  return _arr;
}

var items = arrItemsIn(form);
// Logger.log(items);

// -- Get Form Item by Name
// from source.js

function findObjValIn(arrObj, pQuery, val, pReturn) {
	for (var i = 0; i < arrObj.length; i++) {
		var obj = arrObj[i];
		for (var prop in obj) {
			if (obj.hasOwnProperty(pQuery) && prop == pQuery && obj[prop] == val) {
				return obj[pReturn];
			}
		}
	}
}

// var ex_fovi = findObjValIn(items, "title", "Multiple Choice Example", "item");
// Logger.log(form.getItemById(ex_fovi).getTitle());

// -- Set Item Dropdown Choices
var choices   = ["1", "2", "3", "4", "5"];

// --- Multiple Choice

var multi = findObjValIn(items, "title", "Multiple Choice Example", "item").asMultipleChoiceItem();
multi.setChoiceValues(choices);

// --- Dropdown Choices

var drop = findObjValIn(items, "title", "Dropdown Example", "item").asListItem();
drop.setChoiceValues(choices);

// --- Checkbox Choices

var chkbox = findObjValIn(items, "title", "Checkbox Example", "item").asCheckboxItem();
chkbox.setChoiceValues(choices);

// -- Get Destination Sheet

// var destSheet = SpreadsheetApp.openById(form.getDestinationId());
// Logger.log(destSheet.getName());

// - Form Responses

// -- Get Last Form Response

function lastResponse(formObj) {
  var allRsp  = form.getResponses();
  var lastRsp = allRsp[allRsp.length - 1];
  var itemRsp = lastRsp.getItemResponses();
  var lastObj = {};
  for (var i = 0; i < itemRsp.length; i++) {
    var item = itemRsp[i];
    var prop = item.getItem().getTitle();
    var val  = item.getResponse();
    if (val !== "") {
      lastObj[prop] = val;
    } else {
      lastObj[prop] = undefined;
    }
  }
  lastObj["Email"]     = lastRsp.getRespondentEmail();
  lastObj["Timestamp"] = lastRsp.getTimestamp();
  return lastObj;
}
<commit_msg>complete. will scrub through before adding to README<commit_after>// form obj 

var form = FormApp.getActiveForm();

// * | Forms
// * | - Form Management
// * | -- Array of Form Items
// * | -- Get Form Item by Name
// * | -- Set Item Choices 
// * | -- Get Destination Sheet
// * | - Form Responses
// * | -- Get Last Form Response

function testEverything() {}

// Forms

// - Form Management

// -- Array of Form Items

function arrItemsIn(formObj) {
  var _arr  = [];
  var items = formObj.getItems()
  for (var i = 0; i < items.length; i++) {
    var j = {}; 
    j.index = i;
    j.title = items[i].getTitle();
    j.id    = items[i].getId();
    j.item  = items[i];
    _arr.push(j);
  }
  return _arr;
}

var items = arrItemsIn(form);
// Logger.log(items);

// -- Get Form Item by Name
// note: from source.js

function findObjValIn(arrObj, pQuery, val, pReturn) {
	for (var i = 0; i < arrObj.length; i++) {
		var obj = arrObj[i];
		for (var prop in obj) {
			if (obj.hasOwnProperty(pQuery) && prop == pQuery && obj[prop] == val) {
				return obj[pReturn];
			}
		}
	}
}

// var ex_fovi = findObjValIn(items, "title", "Multiple Choice Example", "item");
// Logger.log(form.getItemById(ex_fovi).getTitle());

// -- Set Item Choices
var choices   = ["1", "2", "3", "4", "5"];

// --- Multiple Choice

var multi = findObjValIn(items, "title", "Multiple Choice Example", "item").asMultipleChoiceItem();
multi.setChoiceValues(choices);

// --- Dropdown

var drop = findObjValIn(items, "title", "Dropdown Example", "item").asListItem();
drop.setChoiceValues(choices);

// --- Checkbox

var chkbox = findObjValIn(items, "title", "Checkbox Example", "item").asCheckboxItem();
chkbox.setChoiceValues(choices);

// -- Get Destination Sheet

// var destSheet = SpreadsheetApp.openById(form.getDestinationId());
// Logger.log(destSheet.getName());

// - Form Responses

// -- Get Last Form Response

function lastResponse(formObj) {
  var all  = form.getResponses();
  var last = all[all.length - 1];
  var rsps = last.getItemResponses();
  var j = {};
  for (var i = 0; i < rsps.length; i++) {
    var rsp  = rsps[i];
    var prop = rsp.getItem().getTitle();
    var val  = rsp.getResponse();
    if (val !== "") {
      j[prop] = val;
    } else {
      j[prop] = undefined;
    }
  }
  j.email     = last.getRespondentEmail();
  j.timestamp = last.getTimestamp();
  return j;
}

// var last = lastResponse(form);
// Logger.log(last);

{'fraction_non_alphanumeric': 0.1771067129157315, 'fraction_numerical': 0.003672719853091206, 'mean_word_length': 2.9373493975903613, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6007391', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1713, 'n_words': 437}