-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireRange.ts
More file actions
23 lines (21 loc) · 1.22 KB
/
requireRange.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 { InvalidRangeException } from "../../exception";
import { isRange } from "./isRange";
/**
* Ensures that the provided value is a valid <a href="https://developers.google.com/apps-script/reference/spreadsheet/range"><code>Range</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/range"><code>Range</code></a> object.
* @param {string} [message] - Optional custom error message if the validation fails.
* @returns {GoogleAppsScript.Spreadsheet.Range} The validated <a href="https://developers.google.com/apps-script/reference/spreadsheet/range"><code>Range</code></a> object.
* @throws <a href="../../exception/appsscript/sheet/InvalidRangeException.ts"><code>InvalidRangeException</code></a>
* @see {@link isRange}
* @see {@link nonRange}
* @see <a href="https://developers.google.com/apps-script/reference/spreadsheet/range"><code>Range</code></a>
* @since 1.5.0
* @version 1.0.0
*/
export function requireRange(value: unknown, message?: string): GoogleAppsScript.Spreadsheet.Range {
if (!isRange(value)) {
throw new InvalidRangeException(message);
}
return value;
}