Skip to content

Commit 81887f7

Browse files
Merge pull request #15 from MaksymStoianov/max/next
Max/next
2 parents 526afbc + 669987f commit 81887f7

26 files changed

+267
-67
lines changed

README.md

Lines changed: 74 additions & 57 deletions
Large diffs are not rendered by default.

src/appsscript/admin/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { isAdmin } from "./isAdmin";

src/appsscript/admin/isAdmin.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { nonFunction } from "../../base";
2+
3+
/**
4+
* ## isAdmin
5+
*
6+
* Checks if the current user is an administrator of the Google Workspace domain.
7+
*
8+
* **Note:** Requires the `Admin SDK Directory Service` to be enabled.
9+
*
10+
* @returns `true` if the user is an administrator; otherwise, `false`.
11+
*/
12+
export function isAdmin(): boolean {
13+
try {
14+
if (nonFunction(AdminDirectory?.Users?.get)) {
15+
throw new Error(
16+
"Admin SDK Directory Service is not available or not enabled."
17+
);
18+
}
19+
20+
const email = Session.getActiveUser().getEmail();
21+
const user = AdminDirectory.Users.get(email);
22+
23+
return !!user.isAdmin;
24+
} catch (err: unknown) {
25+
console.warn(`[Error]: ${err}`);
26+
return false;
27+
}
28+
}

src/appsscript/docs/index.ts

Whitespace-only changes.

src/appsscript/drive/index.ts

Whitespace-only changes.

src/appsscript/forms/index.ts

Whitespace-only changes.

src/appsscript/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
export * from "./admin";
2+
export * from "./docs";
3+
export * from "./drive";
4+
export * from "./forms";
15
export * from "./sheets";
6+
export * from "./slides";
27

38
export { checkMultipleAccount } from "./checkMultipleAccount";
49
export { getByteSize } from "./getByteSize";

src/appsscript/sheets/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export { getColumnIndexByLetter } from "./getColumnIndexByLetter";
1212
export { getColumnLetterByIndex } from "./getColumnLetterByIndex";
1313
export { getSheetById } from "./getSheetById";
1414
export { highlightHtml } from "./highlightHtml";
15+
export { sortSheets } from "./sortSheets";
1516

1617
export { isCellGridRange } from "./isCellGridRange";
1718
export { isGridRangeContainedIn } from "./isGridRangeContainedIn";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { isSpreadsheet } from "./isSpreadsheet";
2+
3+
/**
4+
* Sorts all sheets in a spreadsheet alphabetically by name.
5+
*
6+
* @param spreadsheet - The spreadsheet object.
7+
* @param [callback] - An optional callback function for custom sorting.
8+
*/
9+
export function sortSheets(
10+
spreadsheet: GoogleAppsScript.Spreadsheet.Spreadsheet,
11+
callback?: (a: string, b: string) => number
12+
): void {
13+
if (!isSpreadsheet(spreadsheet)) {
14+
throw new Error("Spreadsheet object is not valid.");
15+
}
16+
17+
try {
18+
const sheets = spreadsheet.getSheets();
19+
20+
if (sheets.length < 2) {
21+
return;
22+
}
23+
24+
const sheetNames = sheets.map(sheet => sheet.getName());
25+
sheetNames.sort(callback);
26+
27+
sheetNames.forEach(function (name, i) {
28+
const sheet = spreadsheet.getSheetByName(name);
29+
30+
if (sheet && sheet.getIndex() !== i + 1) {
31+
spreadsheet.setActiveSheet(sheet);
32+
spreadsheet.moveActiveSheet(i + 1);
33+
}
34+
});
35+
} catch (err: unknown) {
36+
console.error(`Failed to sort sheets: ${err}`);
37+
}
38+
}

src/appsscript/slides/index.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)