Skip to content

Instantly share code, notes, and snippets.

/**
* The time manager manages the time in your script. The timemanager keeps track of
* the time spend and can tell you how much time is left.
*
* This manager is usefull in background scripts that will be killed by apps script
* after some time. Every time before starting an operation you can see if you can
* acquire time to perform the operation. If there is not enough time left you can
* exit the program gracefully.
*
* @param {object} spec - specification for the construction of the object
steps:
- id: authenticate-clasp
name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: ['-c', "gcloud secrets versions access latest --secret=${_SECRET_ID} --format='get(payload.data)' | tr '_-' '/+' | base64 -d > ~/.clasprc.json" ]
- id: configure-clasp
name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: ['-c', 'echo {\"scriptId\":\"${_SCRIPT_ID}\"} > .clasp.json' ]
- id: install-clasp
function myTimer() {
// timing example
console.time("demo")
Utilities.sleep(50);
console.timeEnd("demo");
}
function myLogger() {
// console statements
console.error("Hi, I am an error");
console.warn("Hello, I am a warning");
console.info("Hi, this is information that can be useful");
console.log("Hello, this is FYI")
}
function myDebugger() {
// debugger example
const globalNumber = 0;
// when in debug mode the code will stop here
debugger;
// print the value of globalNumber to the log
console.log(globalNumber);
// create the customFunctions object
let customFunctions = sheetFunctions.customFunctions();
// fetch the custom function and pass the parameters
let customFunction = (f, ...params) => {
return customFunctions.getFunction(f, params);
}
/**
* Multiplies the input value by 2.
/**
* The customFunctions
* @return {Object} The customFunctions Object.
*/
function customFunctions() {
/**
* A custom function that converts meters to miles.
*
* @param {Number} meters The distance in meters.
* @return {Number} The distance in miles.
/**
* The appObjectV8
* @param {Object} specs the construction specifications in JSON format.
* @return {Object} The appObjectV8 object.
*/
const appObjectV8 = (specs) => {
'use strict';
const logManager = specs.logManager || console;
const objectName = 'appObjectV8';
const someParameter = specs.someParameter;
/**
* The appObjectV8
* @param {Object} specs the construction specifications in JSON format.
* @return {Object} The appObjectV8 object.
*/
const appObjectV8 = (specs) => {
'use strict';
const logManager = specs.logManager || console;
const objectName = 'appObjectV8';
const someParameter = specs.someParameter;
/**
* The appObjectV8
* @param {Object} specs the construction specifications in JSON format.
* @return {Object} The appObjectV8 object.
*/
const appObjectV8 = (specs) => {
'use strict';
const logManager = specs.logManager || console;
const objectName = 'appObjectV8';
const someParameter = specs.someParameter;