Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions templates/custom-functions/Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* A function that takes a single input value and returns a single value.
* Returns a simple concatenation of Strings.
*
* @param {String} name A name to greet.
* @return {String} A greeting.
* @param {string} name A name to greet.
* @return {string} A greeting.
* @customfunction
*/
function SAY_HELLO(name) {
Expand All @@ -35,8 +35,8 @@ function SAY_HELLO(name) {
* range of cells.
* Returns a range with all the input values incremented by one.
*
* @param {Array} input The range of numbers to increment.
* @return {Array} The incremented values.
* @param {any} input The range of numbers to increment.
* @return {any} The incremented values.
* @customfunction
*/
function INCREMENT(input) {
Expand All @@ -55,8 +55,8 @@ function INCREMENT(input) {
* Returns the sum the corner values in the range; for a single cell,
* this is equal to (4 * the cell value).
*
* @param {Array} input The Range of numbers to sum the corners of.
* @return {Number} The calculated sum.
* @param {number | number[][]} input The Range of numbers to sum the corners of.
* @return {number} The calculated sum.
* @customfunction
*/
function CORNER_SUM(input) {
Expand All @@ -65,8 +65,8 @@ function CORNER_SUM(input) {
return CORNER_SUM([[input]]); // eslint-disable-line new-cap
}
// Range processing here.
var maxRowIndex = input.length - 1;
var maxColIndex = input[0].length - 1;
const maxRowIndex = input.length - 1;
const maxColIndex = input[0].length - 1;
return input[0][0] + input[0][maxColIndex] +
input[maxRowIndex][0] + input[maxRowIndex][maxColIndex];
}
Expand All @@ -76,20 +76,21 @@ function CORNER_SUM(input) {
* Returns a range consisting of the first 10 powers and roots of that
* number (with column headers).
*
* @param {Number} input The number to calculate from.
* @return {Array} The first ten powers and roots of that number,
* with associated labels.
* @param {number} input The number to calculate from.
* @return {Array<Array<string|number>>} The first ten powers and roots of that
* number, with associated labels.
* @customfunction
*/
function POWERS_AND_ROOTS(input) {
if (input instanceof Array) {
throw new Error('Invalid: Range input not permitted');
if (typeof input !== 'number') {
throw new Error('Invalid: A single number is required.');
}
// Value processing and range generation here.
var headers = ['x', input + '^x', input + '^(1/x)'];
var result = [headers];
for (var i = 1; i <= 10; i++) {
result.push([i, Math.pow(input, i), Math.pow(input, 1/i)]);
const headers = ['x', input.toString() + '^x', input.toString() + '^(1/x)'];
/** @type {Array<Array<string|number>>} */
const result = [headers];
for (let i = 1; i <= 10; i++) {
result.push([i, Math.pow(input, i), Math.pow(input, 1 / i)]);
}
return result;
}
Expand All @@ -99,17 +100,17 @@ function POWERS_AND_ROOTS(input) {
* Returns the day of the year represented by the provided date.
*
* @param {Date} date A Date to examine.
* @return {Number} The day of year for that date.
* @return {number} The day of year for that date.
* @customfunction
*/
function GET_DAY_OF_YEAR(date) {
if (!(date instanceof Date)) {
throw new Error('Invalid: Date input required');
}
// Date processing here.
var firstOfYear = new Date(date.getFullYear(), 0, 0);
var diff = date - firstOfYear;
var oneDay = 1000 * 60 * 60 * 24;
const firstOfYear = new Date(date.getFullYear(), 0, 0);
const diff = date.getTime() - firstOfYear.getTime();
const oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}

Expand All @@ -118,7 +119,7 @@ function GET_DAY_OF_YEAR(date) {
* Returns the number of seconds measured by that duration.
*
* @param {Date} duration A duration to convert.
* @return {Number} Number of seconds in that duration.
* @return {number} Number of seconds in that duration.
* @customfunction
*/
function CONVERT_DURATION_TO_SECONDS(duration) {
Expand Down
12 changes: 6 additions & 6 deletions templates/docs-addon/Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var SIDEBAR_TITLE = 'Example Sidebar';
/**
* Adds a custom menu with items to show the sidebar and dialog.
*
* @param {Object} e The event parameter for a simple onOpen trigger.
* @param {any} e The event parameter for a simple onOpen trigger.
*/
function onOpen(e) {
DocumentApp.getUi()
Expand All @@ -38,7 +38,7 @@ function onOpen(e) {
* Runs when the add-on is installed; calls onOpen() to ensure menu creation and
* any other initializion work is done immediately.
*
* @param {Object} e The event parameter for a simple onInstall trigger.
* @param {any} e The event parameter for a simple onInstall trigger.
*/
function onInstall(e) {
onOpen(e);
Expand Down Expand Up @@ -70,7 +70,7 @@ function showDialog() {
/**
* Returns the existing footer text (if any).
*
* @return {String} existing document footer text (as a plain string).
* @return {string} existing document footer text (as a plain string).
*/
function getFooterText() {
// Retrieve and return the information requested by the sidebar.
Expand All @@ -80,7 +80,7 @@ function getFooterText() {
/**
* Replaces the current document footer with the given text.
*
* @param {String} footerText text collected from the client-side
* @param {string} footerText text collected from the client-side
* sidebar.
*/
function setFooterText(footerText) {
Expand All @@ -91,7 +91,7 @@ function setFooterText(footerText) {
/**
* Returns the document title.
*
* @return {String} the current document title.
* @return {string} the current document title.
*/
function getDocTitle() {
// Retrieve and return the information requested by the dialog.
Expand All @@ -101,7 +101,7 @@ function getDocTitle() {
/**
* Changes the document title.
*
* @param {String} title the new title to use for the document.
* @param {string} title the new title to use for the document.
*/
function setDocTitle(title) {
// Use data collected from dialog to manipulate the document.
Expand Down
27 changes: 20 additions & 7 deletions templates/forms-addon/Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var SIDEBAR_TITLE = 'Example Sidebar';
/**
* Adds a custom menu with items to show the sidebar and dialog.
*
* @param {Object} e The event parameter for a simple onOpen trigger.
* @param {any} e The event parameter for a simple onOpen trigger.
*/
function onOpen(e) {
FormApp.getUi()
Expand All @@ -38,7 +38,7 @@ function onOpen(e) {
* Runs when the add-on is installed; calls onOpen() to ensure menu creation and
* any other initializion work is done immediately.
*
* @param {Object} e The event parameter for a simple onInstall trigger.
* @param {any} e The event parameter for a simple onInstall trigger.
*/
function onInstall(e) {
onOpen(e);
Expand Down Expand Up @@ -67,10 +67,17 @@ function showDialog() {
FormApp.getUi().showModalDialog(ui, DIALOG_TITLE);
}

/**
* @typedef {{
* type: string,
* name: string,
* }} ItemData
*/

/**
* Appends a new form item to the current form.
*
* @param {Object} itemData a collection of String data used to
* @param {ItemData} itemData a collection of String data used to
* determine the exact form item created.
*/
function addFormItem(itemData) {
Expand All @@ -93,7 +100,7 @@ function addFormItem(itemData) {
* Queries the form DocumentProperties to determine whether the formResponse
* trigger is enabled or not.
*
* @return {Boolean} True if the form submit trigger is enabled; false
* @return {boolean} True if the form submit trigger is enabled; false
* otherwise.
*/
function getTriggerState() {
Expand All @@ -105,7 +112,7 @@ function getTriggerState() {
/**
* Turns the form submit trigger on or off based on the given argument.
*
* @param {Boolean} enableTrigger whether to turn on the form submit
* @param {boolean} enableTrigger whether to turn on the form submit
* trigger or not
*/
function adjustFormSubmitTrigger(enableTrigger) {
Expand Down Expand Up @@ -136,12 +143,18 @@ function adjustFormSubmitTrigger(enableTrigger) {
}
}

/**
* @typedef {{
* response: GoogleAppsScript.Forms.FormResponse
* }} FormSubmitEvent
*/

/**
* Responds to form submit events if a form summit trigger is enabled.
* Collects some form information and sends it as an email to the form creator.
*
* @param {Object} e The event parameter created by a form
* submission; see
* @param {FormSubmitEvent} e The event parameter
* created by a form submission.
* https://developers.google.com/apps-script/understanding_events
*/
function respondToFormSubmit(e) {
Expand Down
10 changes: 5 additions & 5 deletions templates/sheets-addon/Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var SIDEBAR_TITLE = 'Example Sidebar';
/**
* Adds a custom menu with items to show the sidebar and dialog.
*
* @param {Object} e The event parameter for a simple onOpen trigger.
* @param {any} e The event parameter for a simple onOpen trigger.
*/
function onOpen(e) {
SpreadsheetApp.getUi()
Expand All @@ -38,7 +38,7 @@ function onOpen(e) {
* Runs when the add-on is installed; calls onOpen() to ensure menu creation and
* any other initializion work is done immediately.
*
* @param {Object} e The event parameter for a simple onInstall trigger.
* @param {any} e The event parameter for a simple onInstall trigger.
*/
function onInstall(e) {
onOpen(e);
Expand Down Expand Up @@ -70,7 +70,7 @@ function showDialog() {
/**
* Returns the value in the active cell.
*
* @return {String} The value of the active cell.
* @return {string} The value of the active cell.
*/
function getActiveValue() {
// Retrieve and return the information requested by the sidebar.
Expand All @@ -81,7 +81,7 @@ function getActiveValue() {
/**
* Replaces the active cell value with the given value.
*
* @param {Number} value A reference number to replace with.
* @param {number} value A reference number to replace with.
*/
function setActiveValue(value) {
// Use data collected from sidebar to manipulate the sheet.
Expand All @@ -93,7 +93,7 @@ function setActiveValue(value) {
* Executes the specified action (create a new sheet, copy the active sheet, or
* clear the current sheet).
*
* @param {String} action An identifier for the action to take.
* @param {string} action An identifier for the action to take.
*/
function modifySheets(action) {
// Use data collected from dialog to manipulate the spreadsheet.
Expand Down
22 changes: 15 additions & 7 deletions templates/sheets-import/APICode.gs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
/**
* Copyright Google LLC
*
Expand All @@ -14,10 +15,17 @@
* limitations under the License.
*/

/**
* @typedef {{
* id: string,
* label: string,
* }} ColumnOption
*/

/**
* Return an array of potential columns (identifiers to locate them in
* the data response object and the labels to use as column headers).
* @return {Array} list of potential columns.
* @return {ColumnOption[]} list of potential columns.
*/
function getColumnOptions() {
var columns = [];
Expand All @@ -37,15 +45,15 @@ function getColumnOptions() {
* Return a page of results from the data source as a 2D array of
* values (with columns corresponding to the columns specified). Return
* null if no data exists for the specified pageNumber.
* @param {Array} columns an array of Strings specifying the column ids
* @param {string[]} columns an array of Strings specifying the column ids
* to include in the output.
* @param {Number} pageNumber a number indicating what page of data to
* @param {number} pageNumber a number indicating what page of data to
* retrieve from the data source.
* @param {Number} pageSize a number indicating the maximum number of
* @param {number} pageSize a number indicating the maximum number of
* rows to return per call.
* @param {Object} opt_settings optional object containing any additional
* information needed to retrieve data from the data source.
* @return {object[]|null} Pages of data.
* @param {Object<string, string>} opt_settings optional object containing any
* additional information needed to retrieve data from the data source.
* @return {Object<string, any>|null} Pages of data.
*/
function getDataPage(columns, pageNumber, pageSize, opt_settings) {
var data = null;
Expand Down
Loading
Loading