-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathisCellGridRange.ts
More file actions
39 lines (33 loc) · 1.51 KB
/
isCellGridRange.ts
File metadata and controls
39 lines (33 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { InvalidGridRangeException } from "../../exception";
import { isObject, nonNil } from "../../lang";
import type { GridRange } from "./types";
/**
* Checks if a given <a href="./types/GridRange.ts"><code>GridRange</code></a> represents a single cell.
*
* @param {GridRange} gridRange - The <a href="./types/GridRange.ts"><code>GridRange</code></a> object to check.
* @returns {boolean} `true` if the range represents a single cell, `false` otherwise.
* @throws <a href="../../exception/IllegalArgumentException.ts"><code>IllegalArgumentException</code></a>
* @see <a href="./types/GridRange.ts"><code>GridRange</code></a>
* @see <a href="https://developers.google.com/apps-script/reference/spreadsheet/range"><code>Range</code></a>
* @see <a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet"><code>Sheet</code></a>
* @since 1.0.0
* @version 1.2.0
* @environment `Google Apps Script`, `Browser`
*/
export function isCellGridRange(gridRange: GridRange): boolean {
if (!isObject(gridRange)) {
throw new InvalidGridRangeException();
}
const { startRowIndex, endRowIndex, startColumnIndex, endColumnIndex } = gridRange;
if (
nonNil(startRowIndex) &&
nonNil(endRowIndex) &&
nonNil(startColumnIndex) &&
nonNil(endColumnIndex)
) {
const isSingleRow = endRowIndex - startRowIndex === 1;
const isSingleColumn = endColumnIndex - startColumnIndex === 1;
return isSingleRow && isSingleColumn;
}
return false;
}