-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireSpreadsheet.ts
More file actions
22 lines (20 loc) · 1 KB
/
requireSpreadsheet.ts
File metadata and controls
22 lines (20 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { InvalidSpreadsheetException } from "../../exception";
import { isSpreadsheet } from "./isSpreadsheet";
/**
* Ensures that the given value is a {@link GoogleAppsScript.Spreadsheet.Spreadsheet|Spreadsheet} object.
*
* @param {unknown} value The value to check.
* @param {string} [message="Required Spreadsheet object is missing or invalid."] The error message to throw if the value is not a {@link GoogleAppsScript.Spreadsheet.Spreadsheet|Spreadsheet}.
* @returns {GoogleAppsScript.Spreadsheet.Spreadsheet} The {@link GoogleAppsScript.Spreadsheet.Spreadsheet|Spreadsheet} object.
* @throws {InvalidSpreadsheetException} If the value is not a {@link GoogleAppsScript.Spreadsheet.Spreadsheet|Spreadsheet}.
* @since 1.5.0
*/
export function requireSpreadsheet(
value: unknown,
message: string = "Required Spreadsheet object is missing or invalid."
): GoogleAppsScript.Spreadsheet.Spreadsheet {
if (!isSpreadsheet(value)) {
throw new InvalidSpreadsheetException(message);
}
return value;
}