-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireSheet.ts
More file actions
23 lines (21 loc) · 1.22 KB
/
requireSheet.ts
File metadata and controls
23 lines (21 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { InvalidSheetException } from "../../exception";
import { isSheet } from "./isSheet";
/**
* Ensures that the provided value is a valid <a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet"><code>Sheet</code></a> object, throwing an exception otherwise.
*
* @param {unknown} value - The value to validate as a <a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet"><code>Sheet</code></a> object.
* @param {string} [message] - Optional custom error message if the validation fails.
* @returns {GoogleAppsScript.Spreadsheet.Sheet} The validated <a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet"><code>Sheet</code></a> object.
* @throws <a href="../../exception/appsscript/sheet/InvalidSheetException.ts"><code>InvalidSheetException</code></a>
* @see {@link isSheet}
* @see {@link nonSheet}
* @see <a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet"><code>Sheet</code></a>
* @since 1.5.0
* @version 1.0.0
*/
export function requireSheet(value: unknown, message?: string): GoogleAppsScript.Spreadsheet.Sheet {
if (!isSheet(value)) {
throw new InvalidSheetException(message);
}
return value;
}