Last active
July 20, 2022 23:21
-
-
Save mark05e/9a20224a3b262256409f9030b28c7276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check if we are inside GAS | |
// source - https://github.com/WildH0g/UnitTestingApp/blob/master/UnitTestingApp.js | |
function inGas() { | |
return typeof ScriptApp !== 'undefined'; | |
} | |
// get the sheet ID from a url | |
// source - https://stackoverflow.com/questions/16840038/easiest-way-to-get-file-id-from-url-on-google-apps-script | |
function getIdFromUrl(url) { | |
try { | |
return url.match(/[-\w]{25,}/)[0]; | |
} catch (error) { | |
return null | |
} | |
} | |
// get the next alphabet to use in a sheet | |
// source - https://stackoverflow.com/questions/32157500/increment-alphabet-characters-to-next-character-using-javascript | |
function nextAlphabetString(str) { | |
if (! str) | |
return 'A' // return 'A' if str is empty or null | |
let tail = '' | |
let i = str.length -1 | |
let char = str[i] | |
// find the index of the first character from the right that is not a 'Z' | |
while (char === 'Z' && i > 0) { | |
i-- | |
char = str[i] | |
tail = 'A' + tail // tail contains a string of 'A' | |
} | |
if (char === 'Z') // the string was made only of 'Z' | |
return 'AA' + tail | |
// increment the character that was not a 'Z' | |
return str.slice(0, i) + String.fromCharCode(char.charCodeAt(0) + 1) + tail | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment