microsoft-graph 2.2.5 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +2 -1
- package/dist/errors/NeverError.d.ts +1 -1
- package/dist/errors/NeverError.d.ts.map +1 -1
- package/dist/errors/UnsupportedAddressTypeError.d.ts +4 -0
- package/dist/errors/UnsupportedAddressTypeError.d.ts.map +1 -0
- package/dist/errors/UnsupportedAddressTypeError.js +6 -0
- package/dist/models/ColumnOffset.d.ts +4 -0
- package/dist/models/ColumnOffset.d.ts.map +1 -0
- package/dist/models/ColumnOffset.js +1 -0
- package/dist/models/RowOffset.d.ts +4 -0
- package/dist/models/RowOffset.d.ts.map +1 -0
- package/dist/models/RowOffset.js +1 -0
- package/dist/operations/drive/createFolder.d.ts +8 -1
- package/dist/operations/drive/createFolder.d.ts.map +1 -1
- package/dist/operations/drive/createFolder.js +8 -1
- package/dist/operations/drive/listDrives.d.ts +8 -2
- package/dist/operations/drive/listDrives.d.ts.map +1 -1
- package/dist/operations/drive/listDrives.js +8 -3
- package/dist/operations/drive/listDrives.test.js +3 -1
- package/dist/operations/driveItem/deleteDriveItem.d.ts +7 -1
- package/dist/operations/driveItem/deleteDriveItem.d.ts.map +1 -1
- package/dist/operations/driveItem/deleteDriveItem.js +7 -1
- package/dist/operations/driveItem/getDriveItem.d.ts +7 -1
- package/dist/operations/driveItem/getDriveItem.d.ts.map +1 -1
- package/dist/operations/driveItem/getDriveItem.js +7 -1
- package/dist/operations/driveItem/getDriveItemByPath.d.ts +8 -1
- package/dist/operations/driveItem/getDriveItemByPath.d.ts.map +1 -1
- package/dist/operations/driveItem/getDriveItemByPath.js +8 -1
- package/dist/operations/driveItem/getDriveItemContent.d.ts +8 -1
- package/dist/operations/driveItem/getDriveItemContent.d.ts.map +1 -1
- package/dist/operations/driveItem/getDriveItemContent.js +8 -1
- package/dist/operations/driveItem/initiateCopyDriveItem.d.ts +9 -1
- package/dist/operations/driveItem/initiateCopyDriveItem.d.ts.map +1 -1
- package/dist/operations/driveItem/initiateCopyDriveItem.js +9 -1
- package/dist/operations/driveItem/listDriveItems.d.ts +8 -2
- package/dist/operations/driveItem/listDriveItems.d.ts.map +1 -1
- package/dist/operations/driveItem/listDriveItems.js +8 -3
- package/dist/operations/site/getSite.d.ts +7 -1
- package/dist/operations/site/getSite.d.ts.map +1 -1
- package/dist/operations/site/getSite.js +7 -1
- package/dist/operations/site/getSiteByName.d.ts +9 -1
- package/dist/operations/site/getSiteByName.d.ts.map +1 -1
- package/dist/operations/site/getSiteByName.js +9 -1
- package/dist/operations/site/listSites.d.ts +7 -1
- package/dist/operations/site/listSites.d.ts.map +1 -1
- package/dist/operations/site/listSites.js +7 -1
- package/dist/operations/site/searchSites.d.ts +8 -1
- package/dist/operations/site/searchSites.d.ts.map +1 -1
- package/dist/operations/site/searchSites.js +8 -1
- package/dist/operations/user/userSendMail.d.ts +10 -1
- package/dist/operations/user/userSendMail.d.ts.map +1 -1
- package/dist/operations/user/userSendMail.js +10 -1
- package/dist/operations/workbook/calculateWorkbook.d.ts +14 -2
- package/dist/operations/workbook/calculateWorkbook.d.ts.map +1 -1
- package/dist/operations/workbook/calculateWorkbook.js +14 -2
- package/dist/operations/workbook/createWorkbook.d.ts +9 -1
- package/dist/operations/workbook/createWorkbook.d.ts.map +1 -1
- package/dist/operations/workbook/createWorkbook.js +9 -1
- package/dist/operations/workbook/deleteWorkbook.d.ts +7 -1
- package/dist/operations/workbook/deleteWorkbook.d.ts.map +1 -1
- package/dist/operations/workbook/deleteWorkbook.js +7 -1
- package/dist/operations/workbookRange/clearWorkbookRange.d.ts +8 -1
- package/dist/operations/workbookRange/clearWorkbookRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/clearWorkbookRange.js +8 -1
- package/dist/operations/workbookRange/deleteWorkbookRange.d.ts +8 -1
- package/dist/operations/workbookRange/deleteWorkbookRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/deleteWorkbookRange.js +8 -1
- package/dist/operations/workbookRange/getWorkbookNamedRange.d.ts +7 -1
- package/dist/operations/workbookRange/getWorkbookNamedRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/getWorkbookNamedRange.js +7 -1
- package/dist/operations/workbookRange/getWorkbookRangeFormat.d.ts +7 -1
- package/dist/operations/workbookRange/getWorkbookRangeFormat.d.ts.map +1 -1
- package/dist/operations/workbookRange/getWorkbookRangeFormat.js +7 -1
- package/dist/operations/workbookRange/getWorkbookUsedRange.d.ts +7 -1
- package/dist/operations/workbookRange/getWorkbookUsedRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/getWorkbookUsedRange.js +7 -1
- package/dist/operations/workbookRange/getWorkbookVisibleRange.d.ts +7 -1
- package/dist/operations/workbookRange/getWorkbookVisibleRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/getWorkbookVisibleRange.js +7 -1
- package/dist/operations/workbookRange/getWorkbookWorksheetRange.d.ts +7 -1
- package/dist/operations/workbookRange/getWorkbookWorksheetRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/getWorkbookWorksheetRange.js +7 -1
- package/dist/operations/workbookRange/insertWorkbookCells.d.ts +9 -1
- package/dist/operations/workbookRange/insertWorkbookCells.d.ts.map +1 -1
- package/dist/operations/workbookRange/insertWorkbookCells.js +9 -1
- package/dist/operations/workbookRange/updateWorkbookNamedRange.d.ts +8 -1
- package/dist/operations/workbookRange/updateWorkbookNamedRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/updateWorkbookNamedRange.js +8 -1
- package/dist/operations/workbookRange/updateWorkbookRange.d.ts +8 -1
- package/dist/operations/workbookRange/updateWorkbookRange.d.ts.map +1 -1
- package/dist/operations/workbookRange/updateWorkbookRange.js +8 -1
- package/dist/operations/workbookSession/closeWorkbookSession.d.ts +8 -1
- package/dist/operations/workbookSession/closeWorkbookSession.d.ts.map +1 -1
- package/dist/operations/workbookSession/closeWorkbookSession.js +8 -1
- package/dist/operations/workbookSession/createWorkbookSession.d.ts +9 -1
- package/dist/operations/workbookSession/createWorkbookSession.d.ts.map +1 -1
- package/dist/operations/workbookSession/createWorkbookSession.js +9 -1
- package/dist/operations/workbookSession/refreshWorkbookSession.d.ts +8 -1
- package/dist/operations/workbookSession/refreshWorkbookSession.d.ts.map +1 -1
- package/dist/operations/workbookSession/refreshWorkbookSession.js +8 -1
- package/dist/operations/workbookTable/createWorkbookTable.d.ts +8 -1
- package/dist/operations/workbookTable/createWorkbookTable.d.ts.map +1 -1
- package/dist/operations/workbookTable/createWorkbookTable.js +8 -1
- package/dist/operations/workbookTable/getWorkbookTable.d.ts +7 -1
- package/dist/operations/workbookTable/getWorkbookTable.d.ts.map +1 -1
- package/dist/operations/workbookTable/getWorkbookTable.js +7 -1
- package/dist/operations/workbookTable/getWorkbookTableBodyRange.d.ts +7 -1
- package/dist/operations/workbookTable/getWorkbookTableBodyRange.d.ts.map +1 -1
- package/dist/operations/workbookTable/getWorkbookTableBodyRange.js +7 -1
- package/dist/operations/workbookTable/getWorkbookTableHeaderRange.d.ts +7 -1
- package/dist/operations/workbookTable/getWorkbookTableHeaderRange.d.ts.map +1 -1
- package/dist/operations/workbookTable/getWorkbookTableHeaderRange.js +7 -1
- package/dist/operations/workbookTable/listWorkbookTableColumns.d.ts +7 -1
- package/dist/operations/workbookTable/listWorkbookTableColumns.d.ts.map +1 -1
- package/dist/operations/workbookTable/listWorkbookTableColumns.js +7 -1
- package/dist/operations/workbookTable/listWorkbookTableRows.d.ts +7 -1
- package/dist/operations/workbookTable/listWorkbookTableRows.d.ts.map +1 -1
- package/dist/operations/workbookTable/listWorkbookTableRows.js +7 -1
- package/dist/operations/workbookTable/listWorkbookTables.d.ts +7 -1
- package/dist/operations/workbookTable/listWorkbookTables.d.ts.map +1 -1
- package/dist/operations/workbookTable/listWorkbookTables.js +7 -1
- package/dist/operations/workbookWorksheet/createWorkbookWorksheet.d.ts +8 -1
- package/dist/operations/workbookWorksheet/createWorkbookWorksheet.d.ts.map +1 -1
- package/dist/operations/workbookWorksheet/createWorkbookWorksheet.js +8 -1
- package/dist/operations/workbookWorksheet/deleteWorkbookWorksheet.d.ts +7 -1
- package/dist/operations/workbookWorksheet/deleteWorkbookWorksheet.d.ts.map +1 -1
- package/dist/operations/workbookWorksheet/deleteWorkbookWorksheet.js +7 -1
- package/dist/operations/workbookWorksheet/listWorkbookWorksheets.d.ts +7 -1
- package/dist/operations/workbookWorksheet/listWorkbookWorksheets.d.ts.map +1 -1
- package/dist/operations/workbookWorksheet/listWorkbookWorksheets.js +7 -1
- package/dist/operations/workbookWorksheet/updateWorkbookWorksheet.d.ts +11 -1
- package/dist/operations/workbookWorksheet/updateWorkbookWorksheet.d.ts.map +1 -1
- package/dist/operations/workbookWorksheet/updateWorkbookWorksheet.js +11 -1
- package/dist/services/accessToken.d.ts +9 -1
- package/dist/services/accessToken.d.ts.map +1 -1
- package/dist/services/accessToken.js +9 -1
- package/dist/services/addressManipulation.d.ts +87 -0
- package/dist/services/addressManipulation.d.ts.map +1 -0
- package/dist/services/addressManipulation.js +226 -0
- package/dist/services/addressManipulation.test.d.ts +2 -0
- package/dist/services/addressManipulation.test.d.ts.map +1 -0
- package/dist/services/addressManipulation.test.js +310 -0
- package/dist/services/addressOffset.d.ts +28 -0
- package/dist/services/addressOffset.d.ts.map +1 -0
- package/dist/services/addressOffset.js +43 -0
- package/dist/services/addressOffset.test.d.ts +2 -0
- package/dist/services/addressOffset.test.d.ts.map +1 -0
- package/dist/services/addressOffset.test.js +38 -0
- package/dist/services/context.d.ts +19 -2
- package/dist/services/context.d.ts.map +1 -1
- package/dist/services/context.js +19 -2
- package/dist/services/drive.d.ts +12 -1
- package/dist/services/drive.d.ts.map +1 -1
- package/dist/services/drive.js +12 -1
- package/dist/services/driveItem.d.ts +13 -1
- package/dist/services/driveItem.d.ts.map +1 -1
- package/dist/services/driveItem.js +13 -1
- package/dist/services/environmentVariable.d.ts +13 -0
- package/dist/services/environmentVariable.d.ts.map +1 -1
- package/dist/services/environmentVariable.js +13 -0
- package/dist/services/httpAgent.d.ts +5 -0
- package/dist/services/httpAgent.d.ts.map +1 -1
- package/dist/services/httpAgent.js +5 -0
- package/dist/services/httpStatus.d.ts +15 -0
- package/dist/services/httpStatus.d.ts.map +1 -1
- package/dist/services/httpStatus.js +15 -0
- package/dist/services/operationId.d.ts +10 -0
- package/dist/services/operationId.d.ts.map +1 -1
- package/dist/services/operationId.js +10 -0
- package/dist/services/random.d.ts +5 -0
- package/dist/services/random.d.ts.map +1 -1
- package/dist/services/random.js +5 -0
- package/dist/services/sharepointUrl.d.ts +6 -1
- package/dist/services/sharepointUrl.d.ts.map +1 -1
- package/dist/services/sharepointUrl.js +6 -1
- package/dist/services/site.d.ts +12 -1
- package/dist/services/site.d.ts.map +1 -1
- package/dist/services/site.js +12 -1
- package/dist/services/sleep.d.ts +5 -0
- package/dist/services/sleep.d.ts.map +1 -1
- package/dist/services/sleep.js +5 -0
- package/dist/services/stringCaseConversion.d.ts +5 -0
- package/dist/services/stringCaseConversion.d.ts.map +1 -1
- package/dist/services/stringCaseConversion.js +5 -0
- package/dist/services/templatedPaths.d.ts +7 -1
- package/dist/services/templatedPaths.d.ts.map +1 -1
- package/dist/services/templatedPaths.js +7 -1
- package/dist/services/temporaryFiles.d.ts +5 -0
- package/dist/services/temporaryFiles.d.ts.map +1 -1
- package/dist/services/temporaryFiles.js +5 -0
- package/dist/services/workbookRange.d.ts +6 -0
- package/dist/services/workbookRange.d.ts.map +1 -1
- package/dist/services/workbookRange.js +6 -0
- package/dist/services/workbookTable.d.ts +7 -0
- package/dist/services/workbookTable.d.ts.map +1 -1
- package/dist/services/workbookTable.js +7 -0
- package/dist/services/workbookWorksheet.d.ts +12 -0
- package/dist/services/workbookWorksheet.d.ts.map +1 -1
- package/dist/services/workbookWorksheet.js +12 -0
- package/dist/tasks/createWorkbookAndStartSession.d.ts +7 -1
- package/dist/tasks/createWorkbookAndStartSession.d.ts.map +1 -1
- package/dist/tasks/createWorkbookAndStartSession.js +7 -1
- package/dist/tasks/deleteDriveItemWithRetry.d.ts +6 -1
- package/dist/tasks/deleteDriveItemWithRetry.d.ts.map +1 -1
- package/dist/tasks/deleteDriveItemWithRetry.js +6 -2
- package/dist/tasks/downloadDriveItemContent.d.ts +7 -1
- package/dist/tasks/downloadDriveItemContent.d.ts.map +1 -1
- package/dist/tasks/downloadDriveItemContent.js +7 -1
- package/dist/tasks/getRangeLastUsedCell.d.ts +7 -3
- package/dist/tasks/getRangeLastUsedCell.d.ts.map +1 -1
- package/dist/tasks/getRangeLastUsedCell.js +11 -6
- package/dist/tasks/getRangeLastUsedCell.test.js +0 -4
- package/dist/tasks/getWorkbookTableVisibleBody.d.ts +6 -1
- package/dist/tasks/getWorkbookTableVisibleBody.d.ts.map +1 -1
- package/dist/tasks/getWorkbookTableVisibleBody.js +6 -1
- package/dist/tasks/getWorkbookWorksheetByName.d.ts +8 -1
- package/dist/tasks/getWorkbookWorksheetByName.d.ts.map +1 -1
- package/dist/tasks/getWorkbookWorksheetByName.js +8 -1
- package/dist/tasks/safeDeleteWorkbook.d.ts +7 -1
- package/dist/tasks/safeDeleteWorkbook.d.ts.map +1 -1
- package/dist/tasks/safeDeleteWorkbook.js +7 -1
- package/dist/tasks/setColumnHidden.d.ts +7 -1
- package/dist/tasks/setColumnHidden.d.ts.map +1 -1
- package/dist/tasks/setColumnHidden.js +7 -1
- package/dist/tasks/setRowHidden.d.ts +7 -1
- package/dist/tasks/setRowHidden.d.ts.map +1 -1
- package/dist/tasks/setRowHidden.js +7 -1
- package/dist/tasks/setWorkbookTableBodyVisibleRows.d.ts +9 -1
- package/dist/tasks/setWorkbookTableBodyVisibleRows.d.ts.map +1 -1
- package/dist/tasks/setWorkbookTableBodyVisibleRows.js +24 -22
- package/dist/tasks/setWorkbookTableBodyVisibleRows.test.js +2 -0
- package/package.json +21 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import InvalidArgumentError from "../errors/InvalidArgumentError.js";
|
|
2
|
+
import UnsupportedAddressTypeError from "../errors/UnsupportedAddressTypeError.js";
|
|
3
|
+
import { columnAddressToOffset, offsetToColumnAddress, offsetToRowAddress, rowAddressToOffset } from "./addressOffset.js";
|
|
4
|
+
const firstColumn = "A";
|
|
5
|
+
const lastColumn = "XFD";
|
|
6
|
+
const firstRow = "1";
|
|
7
|
+
const lastRow = "1048576";
|
|
8
|
+
const addressPattern = /^(?<sheet>[A-Za-z0-9_]+!)?(?:(?<startColumn>[A-Z]+)?(?<startRow>\d+)?(?::(?<endColumn>[A-Z]+)?(?<endRow>\d+)?)?)$/;
|
|
9
|
+
/**
|
|
10
|
+
* Decomposes an address into its components (start and end columns/rows).
|
|
11
|
+
* @param address - The address to decompose.
|
|
12
|
+
* @returns The decomposed address components.
|
|
13
|
+
* @throws InvalidArgumentError if the address format is invalid.
|
|
14
|
+
*/
|
|
15
|
+
export function decomposeAddress(address) {
|
|
16
|
+
const match = address.match(addressPattern);
|
|
17
|
+
if (!match?.groups) {
|
|
18
|
+
throw new InvalidArgumentError(`Invalid address format. Must match pattern '${addressPattern}'`);
|
|
19
|
+
}
|
|
20
|
+
const groups = match.groups;
|
|
21
|
+
return {
|
|
22
|
+
startColumn: groups.startColumn ?? firstColumn,
|
|
23
|
+
startRow: groups.startRow ?? firstRow,
|
|
24
|
+
endColumn: groups.endColumn ?? groups.startColumn ?? lastColumn,
|
|
25
|
+
endRow: groups.endRow ?? groups.startRow ?? lastRow,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Composes an address from its components.
|
|
30
|
+
* @param components - The address components.
|
|
31
|
+
* @returns The composed address.
|
|
32
|
+
* @throws InvalidArgumentError if the components are invalid.
|
|
33
|
+
*/
|
|
34
|
+
export function composeAddress(components) {
|
|
35
|
+
if (isSingleColumn(components) && isMaxRows(components)) {
|
|
36
|
+
return composeColumnAddress(components.startColumn);
|
|
37
|
+
}
|
|
38
|
+
if (isSingleRow(components) && isMaxColumns(components)) {
|
|
39
|
+
return composeRowAddress(components.startRow);
|
|
40
|
+
}
|
|
41
|
+
if (isMaxRows(components)) {
|
|
42
|
+
return composeColumnRangeAddress(components.startColumn, components.endColumn);
|
|
43
|
+
}
|
|
44
|
+
if (isMaxColumns(components)) {
|
|
45
|
+
return composeRowRangeAddress(components.startRow, components.endRow);
|
|
46
|
+
}
|
|
47
|
+
if (isSingleColumn(components) && isSingleRow(components)) {
|
|
48
|
+
return composeCellAddress(components.startColumn, components.startRow);
|
|
49
|
+
}
|
|
50
|
+
if (components.startColumn > components.endColumn) {
|
|
51
|
+
throw new InvalidArgumentError("Invalid address. End column is before start column.");
|
|
52
|
+
}
|
|
53
|
+
if (components.startRow > components.endRow) {
|
|
54
|
+
throw new InvalidArgumentError("Invalid address. End row is before start row.");
|
|
55
|
+
}
|
|
56
|
+
return composeCellRangeAddress(components.startColumn, components.startRow, components.endColumn, components.endRow);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the first cell address from a given address.
|
|
60
|
+
* @param address - The address to analyze.
|
|
61
|
+
* @returns The first cell address.
|
|
62
|
+
*/
|
|
63
|
+
export function getFirstCellAddress(address) {
|
|
64
|
+
const components = decomposeAddress(address);
|
|
65
|
+
return composeCellAddress(components.startColumn, components.startRow);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the last cell address from a given address.
|
|
69
|
+
* @param address - The address to analyze.
|
|
70
|
+
* @returns The last cell address.
|
|
71
|
+
*/
|
|
72
|
+
export function getLastCellAddress(address) {
|
|
73
|
+
const components = decomposeAddress(address);
|
|
74
|
+
return composeCellAddress(components.endColumn, components.endRow);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Gets the first row address from a given address.
|
|
78
|
+
* @param address - The address to analyze.
|
|
79
|
+
* @returns The first row address.
|
|
80
|
+
*/
|
|
81
|
+
export function getFirstRowAddress(address) {
|
|
82
|
+
const components = decomposeAddress(address);
|
|
83
|
+
return composeAddress({
|
|
84
|
+
startColumn: components.startColumn,
|
|
85
|
+
startRow: components.startRow,
|
|
86
|
+
endColumn: components.endColumn,
|
|
87
|
+
endRow: components.startRow,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Gets the last row address from a given address.
|
|
92
|
+
* @param address - The address to analyze.
|
|
93
|
+
* @returns The last row address.
|
|
94
|
+
*/
|
|
95
|
+
export function getLastRowAddress(address) {
|
|
96
|
+
const components = decomposeAddress(address);
|
|
97
|
+
return composeAddress({
|
|
98
|
+
startColumn: components.startColumn,
|
|
99
|
+
startRow: components.endRow,
|
|
100
|
+
endColumn: components.endColumn,
|
|
101
|
+
endRow: components.endRow,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Gets the first column address from a given address.
|
|
106
|
+
* @param address - The address to analyze.
|
|
107
|
+
* @returns The first column address.
|
|
108
|
+
*/
|
|
109
|
+
export function getFirstColumnAddress(address) {
|
|
110
|
+
const components = decomposeAddress(address);
|
|
111
|
+
return composeAddress({
|
|
112
|
+
startColumn: components.startColumn,
|
|
113
|
+
startRow: components.startRow,
|
|
114
|
+
endColumn: components.startColumn,
|
|
115
|
+
endRow: components.endRow,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets the last column address from a given address.
|
|
120
|
+
* @param address - The address to analyze.
|
|
121
|
+
* @returns The last column address.
|
|
122
|
+
*/
|
|
123
|
+
export function getLastColumnAddress(address) {
|
|
124
|
+
const components = decomposeAddress(address);
|
|
125
|
+
return composeAddress({
|
|
126
|
+
startColumn: components.endColumn,
|
|
127
|
+
startRow: components.startRow,
|
|
128
|
+
endColumn: components.endColumn,
|
|
129
|
+
endRow: components.endRow,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Offsets an address by the specified column and row offsets.
|
|
134
|
+
* @param address - The address to offset.
|
|
135
|
+
* @param columnOffset - The column offset.
|
|
136
|
+
* @param rowOffset - The row offset.
|
|
137
|
+
* @returns The offset address.
|
|
138
|
+
* @throws UnsupportedAddressTypeError if the address cannot be offset.
|
|
139
|
+
* @throws InvalidArgumentError if the offset is out of bounds.
|
|
140
|
+
*/
|
|
141
|
+
export function offsetAddress(address, columnOffset, rowOffset) {
|
|
142
|
+
const components = decomposeAddress(address);
|
|
143
|
+
if (isMaxRows(components) && rowOffset !== 0) {
|
|
144
|
+
throw new UnsupportedAddressTypeError("All rows are selected. Cannot offset rows.");
|
|
145
|
+
}
|
|
146
|
+
if (isMaxColumns(components) && columnOffset !== 0) {
|
|
147
|
+
throw new UnsupportedAddressTypeError("All columns are selected. Cannot offset columns.");
|
|
148
|
+
}
|
|
149
|
+
const newStartRowIndex = rowAddressToOffset(components.startRow) + rowOffset;
|
|
150
|
+
const newEndRowIndex = rowAddressToOffset(components.endRow) + rowOffset;
|
|
151
|
+
if (newStartRowIndex < rowAddressToOffset(firstRow) || newEndRowIndex > rowAddressToOffset(lastRow)) {
|
|
152
|
+
throw new InvalidArgumentError(`Row offset out of bounds: ${newStartRowIndex + 1} to ${newEndRowIndex + 1}`);
|
|
153
|
+
}
|
|
154
|
+
const newStartRow = offsetToRowAddress(newStartRowIndex);
|
|
155
|
+
const newEndRow = offsetToRowAddress(newEndRowIndex);
|
|
156
|
+
const newStartColumnIndex = columnAddressToOffset(components.startColumn) + columnOffset;
|
|
157
|
+
const newEndColumnIndex = columnAddressToOffset(components.endColumn) + columnOffset;
|
|
158
|
+
if (newStartColumnIndex < columnAddressToOffset(firstColumn) || newEndColumnIndex > columnAddressToOffset(lastColumn)) {
|
|
159
|
+
throw new InvalidArgumentError(`Column offset out of bounds: ${newStartColumnIndex + 1} to ${newEndColumnIndex + 1}`);
|
|
160
|
+
}
|
|
161
|
+
const newStartColumn = offsetToColumnAddress(newStartColumnIndex);
|
|
162
|
+
const newEndColumn = offsetToColumnAddress(newEndColumnIndex);
|
|
163
|
+
return composeAddress({
|
|
164
|
+
startColumn: newStartColumn,
|
|
165
|
+
endColumn: newEndColumn,
|
|
166
|
+
startRow: newStartRow,
|
|
167
|
+
endRow: newEndRow,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Increments the row address by one.
|
|
172
|
+
* @param address - The address to increment.
|
|
173
|
+
* @returns The incremented address.
|
|
174
|
+
*/
|
|
175
|
+
export function incrementRowAddress(address) {
|
|
176
|
+
return offsetAddress(address, 0, +1);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Decrements the row address by one.
|
|
180
|
+
* @param address - The address to decrement.
|
|
181
|
+
* @returns The decremented address.
|
|
182
|
+
*/
|
|
183
|
+
export function decrementRowAddress(address) {
|
|
184
|
+
return offsetAddress(address, 0, -1);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Checks if two addresses overlap.
|
|
188
|
+
* @param address1 - The first address.
|
|
189
|
+
* @param address2 - The second address.
|
|
190
|
+
* @returns True if the addresses overlap, otherwise false.
|
|
191
|
+
*/
|
|
192
|
+
export function isAddressOverlapping(address1, address2) {
|
|
193
|
+
const components1 = decomposeAddress(address1);
|
|
194
|
+
const components2 = decomposeAddress(address2);
|
|
195
|
+
return components1.startColumn <= components2.endColumn && components1.endColumn >= components2.startColumn && rowAddressToOffset(components1.startRow) <= rowAddressToOffset(components2.endRow) && rowAddressToOffset(components1.endRow) >= rowAddressToOffset(components2.startRow);
|
|
196
|
+
}
|
|
197
|
+
function composeCellRangeAddress(startColumn, startRow, endColumn, endRow) {
|
|
198
|
+
return `${startColumn}${startRow}:${endColumn}${endRow}`;
|
|
199
|
+
}
|
|
200
|
+
function composeCellAddress(startColumn, startRow) {
|
|
201
|
+
return `${startColumn}${startRow}`;
|
|
202
|
+
}
|
|
203
|
+
function composeRowRangeAddress(startRow, endRow) {
|
|
204
|
+
return `${startRow}:${endRow}`;
|
|
205
|
+
}
|
|
206
|
+
function composeColumnRangeAddress(startColumn, endColumn) {
|
|
207
|
+
return `${startColumn}:${endColumn}`;
|
|
208
|
+
}
|
|
209
|
+
function composeRowAddress(startRow) {
|
|
210
|
+
return startRow;
|
|
211
|
+
}
|
|
212
|
+
function composeColumnAddress(startColumn) {
|
|
213
|
+
return startColumn;
|
|
214
|
+
}
|
|
215
|
+
function isSingleRow(components) {
|
|
216
|
+
return components.startRow === components.endRow;
|
|
217
|
+
}
|
|
218
|
+
function isSingleColumn(components) {
|
|
219
|
+
return components.startColumn === components.endColumn;
|
|
220
|
+
}
|
|
221
|
+
function isMaxColumns(components) {
|
|
222
|
+
return components.startColumn === firstColumn && components.endColumn === lastColumn;
|
|
223
|
+
}
|
|
224
|
+
function isMaxRows(components) {
|
|
225
|
+
return components.startRow === firstRow && components.endRow === lastRow;
|
|
226
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addressManipulation.test.d.ts","sourceRoot":"","sources":["../../src/services/addressManipulation.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import InvalidArgumentError from "../errors/InvalidArgumentError.js";
|
|
3
|
+
import { composeAddress, decomposeAddress, decrementRowAddress, getFirstCellAddress, getFirstColumnAddress, getFirstRowAddress, getLastCellAddress, getLastColumnAddress, getLastRowAddress, incrementRowAddress, isAddressOverlapping, offsetAddress } from "./addressManipulation.js";
|
|
4
|
+
describe("getFirstCellAddress", () => {
|
|
5
|
+
it("should return the start cell of a range address", () => {
|
|
6
|
+
expect(getFirstCellAddress("C3:D4")).toBe("C3");
|
|
7
|
+
expect(getFirstCellAddress("Sheet!A1:B2")).toBe("A1");
|
|
8
|
+
expect(getFirstCellAddress("E5")).toBe("E5"); // Single cell address
|
|
9
|
+
expect(getFirstCellAddress("Sheet!E5")).toBe("E5"); // Single cell address
|
|
10
|
+
expect(getFirstCellAddress("C")).toBe("C1"); // ColumnAddress
|
|
11
|
+
expect(getFirstCellAddress("Sheet!C")).toBe("C1"); // ColumnAddress
|
|
12
|
+
expect(getFirstCellAddress("3")).toBe("A3"); // RowAddress
|
|
13
|
+
expect(getFirstCellAddress("Sheet!3")).toBe("A3"); // RowAddress
|
|
14
|
+
expect(getFirstCellAddress("A:Z")).toBe("A1"); // ColumnRangeAddress
|
|
15
|
+
expect(getFirstCellAddress("Sheet!A:Z")).toBe("A1"); // ColumnRangeAddress
|
|
16
|
+
expect(getFirstCellAddress("1:10")).toBe("A1"); // RowRangeAddress
|
|
17
|
+
expect(getFirstCellAddress("Sheet!1:10")).toBe("A1"); // RowRangeAddress
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe("getLastCellAddress", () => {
|
|
21
|
+
it("should return the end cell of a range address", () => {
|
|
22
|
+
expect(getLastCellAddress("C3:D4")).toBe("D4");
|
|
23
|
+
expect(getLastCellAddress("Sheet!A1:B2")).toBe("B2");
|
|
24
|
+
expect(getLastCellAddress("E5")).toBe("E5"); // Single cell address
|
|
25
|
+
expect(getLastCellAddress("Sheet!E5")).toBe("E5"); // Single cell address
|
|
26
|
+
expect(getLastCellAddress("C")).toBe("C1048576"); // ColumnAddress
|
|
27
|
+
expect(getLastCellAddress("Sheet!C")).toBe("C1048576"); // ColumnAddress
|
|
28
|
+
expect(getLastCellAddress("3")).toBe("XFD3"); // RowAddress
|
|
29
|
+
expect(getLastCellAddress("Sheet!3")).toBe("XFD3"); // RowAddress
|
|
30
|
+
expect(getLastCellAddress("A:Z")).toBe("Z1048576"); // ColumnRangeAddress
|
|
31
|
+
expect(getLastCellAddress("Sheet!A:Z")).toBe("Z1048576"); // ColumnRangeAddress
|
|
32
|
+
expect(getLastCellAddress("1:10")).toBe("XFD10"); // RowRangeAddress
|
|
33
|
+
expect(getLastCellAddress("Sheet!1:10")).toBe("XFD10"); // RowRangeAddress
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("getFirstRowAddress", () => {
|
|
37
|
+
it("should return the first row of a row range", () => {
|
|
38
|
+
expect(getFirstRowAddress("1:5")).toBe("1");
|
|
39
|
+
expect(getFirstRowAddress("Sheet!1:10")).toBe("1");
|
|
40
|
+
});
|
|
41
|
+
it("should return the first row of a column range", () => {
|
|
42
|
+
expect(getFirstRowAddress("A")).toBe("A1");
|
|
43
|
+
expect(getFirstRowAddress("A:C")).toBe("A1:C1");
|
|
44
|
+
});
|
|
45
|
+
it("should handle cell ranges", () => {
|
|
46
|
+
expect(getFirstRowAddress("A1:C5")).toBe("A1:C1");
|
|
47
|
+
});
|
|
48
|
+
it("should return the first row of a single cell address", () => {
|
|
49
|
+
expect(getFirstRowAddress("A1")).toBe("A1");
|
|
50
|
+
expect(getFirstRowAddress("Sheet!B2")).toBe("B2");
|
|
51
|
+
});
|
|
52
|
+
it("should handle cell ranges", () => {
|
|
53
|
+
expect(getFirstRowAddress("A1:C5")).toBe("A1:C1");
|
|
54
|
+
});
|
|
55
|
+
it("should return the same cell address for a single cell", () => {
|
|
56
|
+
expect(getFirstRowAddress("C1")).toBe("C1");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("getLastRowAddress", () => {
|
|
60
|
+
it("should return the last row of a row range", () => {
|
|
61
|
+
expect(getLastRowAddress("1:5")).toBe("5");
|
|
62
|
+
expect(getLastRowAddress("Sheet!1:10")).toBe("10");
|
|
63
|
+
});
|
|
64
|
+
it("should return the last row of a column range", () => {
|
|
65
|
+
expect(getLastRowAddress("A")).toBe("A1048576");
|
|
66
|
+
expect(getLastRowAddress("A:C")).toBe("A1048576:C1048576");
|
|
67
|
+
});
|
|
68
|
+
it("should handle cell ranges", () => {
|
|
69
|
+
expect(getLastRowAddress("A1:C5")).toBe("A5:C5");
|
|
70
|
+
});
|
|
71
|
+
it("should return the last row of a single cell address", () => {
|
|
72
|
+
expect(getLastRowAddress("A1")).toBe("A1");
|
|
73
|
+
expect(getLastRowAddress("Sheet!B2")).toBe("B2");
|
|
74
|
+
});
|
|
75
|
+
it("should handle cell ranges", () => {
|
|
76
|
+
expect(getLastRowAddress("A1:C5")).toBe("A5:C5");
|
|
77
|
+
});
|
|
78
|
+
it("should return the same cell address for a single cell", () => {
|
|
79
|
+
expect(getLastRowAddress("C1")).toBe("C1");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("getFirstColumnAddress", () => {
|
|
83
|
+
it("should return the first column of a column range", () => {
|
|
84
|
+
expect(getFirstColumnAddress("A:C")).toBe("A");
|
|
85
|
+
expect(getFirstColumnAddress("Sheet!A:Z")).toBe("A");
|
|
86
|
+
});
|
|
87
|
+
it("should return the first column of a row range", () => {
|
|
88
|
+
expect(getFirstColumnAddress("1")).toBe("A1");
|
|
89
|
+
expect(getFirstColumnAddress("1:5")).toBe("A1:A5");
|
|
90
|
+
});
|
|
91
|
+
it("should handle cell ranges", () => {
|
|
92
|
+
expect(getFirstColumnAddress("A1:C5")).toBe("A1:A5");
|
|
93
|
+
});
|
|
94
|
+
it("should return the first column of a single cell address", () => {
|
|
95
|
+
expect(getFirstColumnAddress("A1")).toBe("A1");
|
|
96
|
+
expect(getFirstColumnAddress("Sheet!B2")).toBe("B2");
|
|
97
|
+
});
|
|
98
|
+
it("should handle cell ranges", () => {
|
|
99
|
+
expect(getFirstColumnAddress("A1:C5")).toBe("A1:A5");
|
|
100
|
+
});
|
|
101
|
+
it("should return the same cell address for a single cell", () => {
|
|
102
|
+
expect(getFirstColumnAddress("C1")).toBe("C1");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("getLastColumnAddress", () => {
|
|
106
|
+
it("should return the last column of a column range", () => {
|
|
107
|
+
expect(getLastColumnAddress("A:C")).toBe("C");
|
|
108
|
+
expect(getLastColumnAddress("Sheet!A:Z")).toBe("Z");
|
|
109
|
+
});
|
|
110
|
+
it("should return the last column of a row range", () => {
|
|
111
|
+
expect(getLastColumnAddress("1")).toBe("XFD1");
|
|
112
|
+
expect(getLastColumnAddress("1:5")).toBe("XFD1:XFD5");
|
|
113
|
+
});
|
|
114
|
+
it("should handle cell ranges", () => {
|
|
115
|
+
expect(getLastColumnAddress("A1:C5")).toBe("C1:C5");
|
|
116
|
+
});
|
|
117
|
+
it("should return the last column of a single cell address", () => {
|
|
118
|
+
expect(getLastColumnAddress("A1")).toBe("A1");
|
|
119
|
+
expect(getLastColumnAddress("Sheet!B2")).toBe("B2");
|
|
120
|
+
});
|
|
121
|
+
it("should handle cell ranges", () => {
|
|
122
|
+
expect(getLastColumnAddress("A1:C5")).toBe("C1:C5");
|
|
123
|
+
});
|
|
124
|
+
it("should return the same cell address for a single cell", () => {
|
|
125
|
+
expect(getLastColumnAddress("C1")).toBe("C1");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe("offsetAddress", () => {
|
|
129
|
+
it("should offset rows and columns in a cell range", () => {
|
|
130
|
+
expect(offsetAddress("A1:C5", 2, 2)).toBe("C3:E7");
|
|
131
|
+
expect(offsetAddress("Sheet!B2:C5", 2, 2)).toBe("D4:E7");
|
|
132
|
+
});
|
|
133
|
+
it("should offset rows only", () => {
|
|
134
|
+
expect(offsetAddress("A1:C5", 0, 2)).toBe("A3:C7");
|
|
135
|
+
expect(offsetAddress("Sheet!B1:C5", 0, 2)).toBe("B3:C7");
|
|
136
|
+
});
|
|
137
|
+
it("should offset columns only", () => {
|
|
138
|
+
expect(offsetAddress("A1:C5", 2, 0)).toBe("C1:E5");
|
|
139
|
+
expect(offsetAddress("Sheet!A2:C5", 2, 0)).toBe("C2:E5");
|
|
140
|
+
});
|
|
141
|
+
it("should throw if offset exceeds valid range", () => {
|
|
142
|
+
expect(() => offsetAddress("A1:C5", 0, 1048577)).toThrow(InvalidArgumentError);
|
|
143
|
+
expect(() => offsetAddress("A1:C5", 16385, 0)).toThrow(InvalidArgumentError);
|
|
144
|
+
});
|
|
145
|
+
it("should offset rows and columns in a single cell address", () => {
|
|
146
|
+
expect(offsetAddress("A1", 2, 2)).toBe("C3");
|
|
147
|
+
expect(offsetAddress("Sheet!B2", 2, 2)).toBe("D4");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("incrementRowAddress", () => {
|
|
151
|
+
it("should increment the row of a row range", () => {
|
|
152
|
+
expect(incrementRowAddress("1:5")).toBe("2:6");
|
|
153
|
+
});
|
|
154
|
+
it("should increment the row of a cell range", () => {
|
|
155
|
+
expect(incrementRowAddress("A1:C5")).toBe("A2:C6");
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe("decrementRowAddress", () => {
|
|
159
|
+
it("should decrement the row of a row range", () => {
|
|
160
|
+
expect(decrementRowAddress("2:6")).toBe("1:5");
|
|
161
|
+
});
|
|
162
|
+
it("should decrement the row of a cell range", () => {
|
|
163
|
+
expect(decrementRowAddress("A2:C6")).toBe("A1:C5");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe("decomposeAddress", () => {
|
|
167
|
+
it("should parse a column address", () => {
|
|
168
|
+
expect(decomposeAddress("A")).toEqual({
|
|
169
|
+
startColumn: "A",
|
|
170
|
+
endColumn: "A",
|
|
171
|
+
startRow: "1",
|
|
172
|
+
endRow: "1048576",
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it("should parse a row address", () => {
|
|
176
|
+
expect(decomposeAddress("5")).toEqual({
|
|
177
|
+
startColumn: "A",
|
|
178
|
+
endColumn: "XFD",
|
|
179
|
+
startRow: "5",
|
|
180
|
+
endRow: "5",
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
it("should parse a cell address", () => {
|
|
184
|
+
expect(decomposeAddress("B3")).toEqual({
|
|
185
|
+
startColumn: "B",
|
|
186
|
+
endColumn: "B",
|
|
187
|
+
startRow: "3",
|
|
188
|
+
endRow: "3",
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
it("should parse a column range address", () => {
|
|
192
|
+
expect(decomposeAddress("A:C")).toEqual({
|
|
193
|
+
startColumn: "A",
|
|
194
|
+
endColumn: "C",
|
|
195
|
+
startRow: "1",
|
|
196
|
+
endRow: "1048576",
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
it("should parse a row range address", () => {
|
|
200
|
+
expect(decomposeAddress("1:10")).toEqual({
|
|
201
|
+
startColumn: "A",
|
|
202
|
+
endColumn: "XFD",
|
|
203
|
+
startRow: "1",
|
|
204
|
+
endRow: "10",
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
it("should parse a cell range address", () => {
|
|
208
|
+
expect(decomposeAddress("A1:C5")).toEqual({
|
|
209
|
+
startColumn: "A",
|
|
210
|
+
endColumn: "C",
|
|
211
|
+
startRow: "1",
|
|
212
|
+
endRow: "5",
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
it("should throw an error for invalid addresses", () => {
|
|
216
|
+
expect(() => decomposeAddress("InvalidAddress")).toThrow(InvalidArgumentError);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
describe("composeAddress", () => {
|
|
220
|
+
it("should create a column address", () => {
|
|
221
|
+
expect(composeAddress({
|
|
222
|
+
startColumn: "A",
|
|
223
|
+
endColumn: "A",
|
|
224
|
+
startRow: "1",
|
|
225
|
+
endRow: "1048576",
|
|
226
|
+
})).toBe("A");
|
|
227
|
+
});
|
|
228
|
+
it("should create a row address", () => {
|
|
229
|
+
expect(composeAddress({
|
|
230
|
+
startColumn: "A",
|
|
231
|
+
endColumn: "XFD",
|
|
232
|
+
startRow: "5",
|
|
233
|
+
endRow: "5",
|
|
234
|
+
})).toBe("5");
|
|
235
|
+
});
|
|
236
|
+
it("should create a cell address", () => {
|
|
237
|
+
expect(composeAddress({
|
|
238
|
+
startColumn: "B",
|
|
239
|
+
endColumn: "B",
|
|
240
|
+
startRow: "3",
|
|
241
|
+
endRow: "3",
|
|
242
|
+
})).toBe("B3");
|
|
243
|
+
});
|
|
244
|
+
it("should create a column range address", () => {
|
|
245
|
+
expect(composeAddress({
|
|
246
|
+
startColumn: "A",
|
|
247
|
+
endColumn: "C",
|
|
248
|
+
startRow: "1",
|
|
249
|
+
endRow: "1048576",
|
|
250
|
+
})).toBe("A:C");
|
|
251
|
+
});
|
|
252
|
+
it("should create a row range address", () => {
|
|
253
|
+
expect(composeAddress({
|
|
254
|
+
startColumn: "A",
|
|
255
|
+
endColumn: "XFD",
|
|
256
|
+
startRow: "1",
|
|
257
|
+
endRow: "10",
|
|
258
|
+
})).toBe("1:10");
|
|
259
|
+
});
|
|
260
|
+
it("should create a cell range address", () => {
|
|
261
|
+
expect(composeAddress({
|
|
262
|
+
startColumn: "A",
|
|
263
|
+
endColumn: "C",
|
|
264
|
+
startRow: "1",
|
|
265
|
+
endRow: "5",
|
|
266
|
+
})).toBe("A1:C5");
|
|
267
|
+
});
|
|
268
|
+
it("should throw an error for invalid address components", () => {
|
|
269
|
+
expect(() => composeAddress({
|
|
270
|
+
startColumn: "C",
|
|
271
|
+
endColumn: "A",
|
|
272
|
+
startRow: "5",
|
|
273
|
+
endRow: "1",
|
|
274
|
+
})).toThrow(InvalidArgumentError);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
describe("isAddressOverlapping", () => {
|
|
278
|
+
it("should return true for overlapping cell ranges", () => {
|
|
279
|
+
expect(isAddressOverlapping("A1:C3", "B2:D4")).toBe(true);
|
|
280
|
+
expect(isAddressOverlapping("A1:B2", "A1:B2")).toBe(true); // Exact overlap
|
|
281
|
+
expect(isAddressOverlapping("A1:D4", "B2:C3")).toBe(true); // Nested overlap
|
|
282
|
+
});
|
|
283
|
+
it("should return false for non-overlapping cell ranges", () => {
|
|
284
|
+
expect(isAddressOverlapping("A1:B2", "C3:D4")).toBe(false);
|
|
285
|
+
expect(isAddressOverlapping("A1:A1", "B1:B1")).toBe(false);
|
|
286
|
+
expect(isAddressOverlapping("A1:A10", "B11:B20")).toBe(false);
|
|
287
|
+
});
|
|
288
|
+
it("should return true for overlapping row ranges", () => {
|
|
289
|
+
expect(isAddressOverlapping("1:5", "3:7")).toBe(true);
|
|
290
|
+
expect(isAddressOverlapping("1:10", "5:15")).toBe(true);
|
|
291
|
+
});
|
|
292
|
+
it("should return false for non-overlapping row ranges", () => {
|
|
293
|
+
expect(isAddressOverlapping("1:5", "6:10")).toBe(false);
|
|
294
|
+
expect(isAddressOverlapping("1:1", "2:2")).toBe(false);
|
|
295
|
+
});
|
|
296
|
+
it("should return true for overlapping column ranges", () => {
|
|
297
|
+
expect(isAddressOverlapping("A:C", "B:D")).toBe(true);
|
|
298
|
+
expect(isAddressOverlapping("A:Z", "M:N")).toBe(true);
|
|
299
|
+
});
|
|
300
|
+
it("should return false for non-overlapping column ranges", () => {
|
|
301
|
+
expect(isAddressOverlapping("A:C", "D:F")).toBe(false);
|
|
302
|
+
expect(isAddressOverlapping("A:A", "B:B")).toBe(false);
|
|
303
|
+
});
|
|
304
|
+
it("should handle single cell addresses", () => {
|
|
305
|
+
expect(isAddressOverlapping("A1", "A1")).toBe(true); // Exact match
|
|
306
|
+
expect(isAddressOverlapping("A1", "B2")).toBe(false); // No overlap
|
|
307
|
+
expect(isAddressOverlapping("A1", "A2")).toBe(false); // Different rows
|
|
308
|
+
expect(isAddressOverlapping("A1", "B1")).toBe(false); // Different columns
|
|
309
|
+
});
|
|
310
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ColumnAddress, RowAddress } from "../models/Address.ts";
|
|
2
|
+
import type { ColumnOffset } from "../models/ColumnOffset.ts";
|
|
3
|
+
import type { RowOffset } from "../models/RowOffset.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Converts a column address (e.g., "A") to a zero-based column offset.
|
|
6
|
+
* @param column - The column address.
|
|
7
|
+
* @returns The zero-based column offset.
|
|
8
|
+
*/
|
|
9
|
+
export declare function columnAddressToOffset(column: ColumnAddress): ColumnOffset;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a zero-based column offset to a column address (e.g., "A").
|
|
12
|
+
* @param offset - The zero-based column offset.
|
|
13
|
+
* @returns The column address.
|
|
14
|
+
*/
|
|
15
|
+
export declare function offsetToColumnAddress(offset: ColumnOffset): ColumnAddress;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a row address (e.g., "1") to a zero-based row offset.
|
|
18
|
+
* @param row - The row address.
|
|
19
|
+
* @returns The zero-based row offset.
|
|
20
|
+
*/
|
|
21
|
+
export declare function rowAddressToOffset(row: RowAddress): RowOffset;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a zero-based row offset to a row address (e.g., "1").
|
|
24
|
+
* @param offset - The zero-based row offset.
|
|
25
|
+
* @returns The row address.
|
|
26
|
+
*/
|
|
27
|
+
export declare function offsetToRowAddress(offset: RowOffset): RowAddress;
|
|
28
|
+
//# sourceMappingURL=addressOffset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addressOffset.d.ts","sourceRoot":"","sources":["../../src/services/addressOffset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAMzE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,CASzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAEhE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a column address (e.g., "A") to a zero-based column offset.
|
|
3
|
+
* @param column - The column address.
|
|
4
|
+
* @returns The zero-based column offset.
|
|
5
|
+
*/
|
|
6
|
+
export function columnAddressToOffset(column) {
|
|
7
|
+
let offset = 0;
|
|
8
|
+
for (let i = 0; i < column.length; i++) {
|
|
9
|
+
offset = offset * 26 + (column.charCodeAt(i) - 65 + 1);
|
|
10
|
+
}
|
|
11
|
+
return (offset - 1);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Converts a zero-based column offset to a column address (e.g., "A").
|
|
15
|
+
* @param offset - The zero-based column offset.
|
|
16
|
+
* @returns The column address.
|
|
17
|
+
*/
|
|
18
|
+
export function offsetToColumnAddress(offset) {
|
|
19
|
+
let result = "";
|
|
20
|
+
let currentOffset = offset + 1;
|
|
21
|
+
while (currentOffset > 0) {
|
|
22
|
+
currentOffset -= 1;
|
|
23
|
+
result = String.fromCharCode((currentOffset % 26) + 65) + result;
|
|
24
|
+
currentOffset = Math.floor(currentOffset / 26);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts a row address (e.g., "1") to a zero-based row offset.
|
|
30
|
+
* @param row - The row address.
|
|
31
|
+
* @returns The zero-based row offset.
|
|
32
|
+
*/
|
|
33
|
+
export function rowAddressToOffset(row) {
|
|
34
|
+
return (Number.parseInt(row, 10) - 1);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Converts a zero-based row offset to a row address (e.g., "1").
|
|
38
|
+
* @param offset - The zero-based row offset.
|
|
39
|
+
* @returns The row address.
|
|
40
|
+
*/
|
|
41
|
+
export function offsetToRowAddress(offset) {
|
|
42
|
+
return (offset + 1).toString();
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addressOffset.test.d.ts","sourceRoot":"","sources":["../../src/services/addressOffset.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { columnAddressToOffset, offsetToColumnAddress, offsetToRowAddress, rowAddressToOffset } from "./addressOffset.js";
|
|
3
|
+
describe("columnAddressToOffset", () => {
|
|
4
|
+
it("should convert column address to offset", () => {
|
|
5
|
+
expect(columnAddressToOffset("A")).toBe(0);
|
|
6
|
+
expect(columnAddressToOffset("B")).toBe(1);
|
|
7
|
+
expect(columnAddressToOffset("Z")).toBe(25);
|
|
8
|
+
expect(columnAddressToOffset("AA")).toBe(26);
|
|
9
|
+
expect(columnAddressToOffset("AB")).toBe(27);
|
|
10
|
+
expect(columnAddressToOffset("AZ")).toBe(51);
|
|
11
|
+
expect(columnAddressToOffset("BA")).toBe(52);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe("offsetToColumnAddress", () => {
|
|
15
|
+
it("should convert offset to column address", () => {
|
|
16
|
+
expect(offsetToColumnAddress(0)).toBe("A");
|
|
17
|
+
expect(offsetToColumnAddress(1)).toBe("B");
|
|
18
|
+
expect(offsetToColumnAddress(25)).toBe("Z");
|
|
19
|
+
expect(offsetToColumnAddress(26)).toBe("AA");
|
|
20
|
+
expect(offsetToColumnAddress(27)).toBe("AB");
|
|
21
|
+
expect(offsetToColumnAddress(51)).toBe("AZ");
|
|
22
|
+
expect(offsetToColumnAddress(52)).toBe("BA");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe("rowAddressToOffset", () => {
|
|
26
|
+
it("should convert row address to offset", () => {
|
|
27
|
+
expect(rowAddressToOffset("1")).toBe(0);
|
|
28
|
+
expect(rowAddressToOffset("2")).toBe(1);
|
|
29
|
+
expect(rowAddressToOffset("10")).toBe(9);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("offsetToRowAddress", () => {
|
|
33
|
+
it("should convert offset to row address", () => {
|
|
34
|
+
expect(offsetToRowAddress(0)).toBe("1");
|
|
35
|
+
expect(offsetToRowAddress(1)).toBe("2");
|
|
36
|
+
expect(offsetToRowAddress(9)).toBe("10");
|
|
37
|
+
});
|
|
38
|
+
});
|