@jsb188/mday 1.1.11 → 1.1.12
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/package.json +58 -23
- package/src/constants/agentMemory.ts +14 -45
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +156 -47
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +12 -38
- package/src/constants/dataTableFieldTypes.generated.ts +3 -7
- package/src/constants/docAccess.ts +3 -2
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +114 -12
- package/src/constants/fieldDoc.ts +74 -4
- package/src/constants/graphqlReactivity.ts +108 -25
- package/src/constants/log.ts +9 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +1834 -730
- package/src/constants/organization.ts +13 -14
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +65 -101
- package/src/constants/sms.ts +18 -0
- package/src/constants/storage.ts +33 -9
- package/src/constants/usage.ts +3 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +106 -283
- package/src/schemas/inboundContact.ts +5 -5
- package/src/types/agentMemory.d.ts +38 -14
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1043 -193
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +102 -309
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +144 -55
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +579 -150
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +8 -0
- package/src/types/log.d.ts +94 -3
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +8 -3
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +180 -463
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +266 -27
- package/src/types/workflow.d.ts +196 -66
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +31 -14
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +642 -209
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +18 -556
- package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/email.ts +208 -1
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +81 -37
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +232 -141
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logStoreRead.ts +9 -13
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomyDisplay.ts +80 -124
- package/src/utils/noteDoc.ts +66 -284
- package/src/utils/organization.ts +117 -283
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +123 -4834
- package/src/utils/sheetAxisMove.ts +77 -291
- package/src/utils/sheetBootstrap.ts +771 -1138
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +23 -88
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +17 -69
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +388 -403
- package/src/utils/sheetFormulaEvaluator.ts +589 -444
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +140 -18
- package/src/utils/sheetNumberFormat.ts +68 -267
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +13 -43
- package/src/utils/sheetSnapshot.ts +176 -429
- package/src/utils/sheetStructureEdit.ts +537 -907
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/storage.ts +49 -3
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +199 -73
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +37 -192
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +49 -40
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +93 -200
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +4 -23
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +492 -37
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/src/constants/agentDoc.ts +0 -12
- package/src/constants/logActivityGroupColors.generated.ts +0 -19
- package/src/constants/schedule.ts +0 -220
- package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
- package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
- package/src/constants/sheetRegionSources.generated.ts +0 -578
- package/src/schemas/fieldDocsQuery.ts +0 -12
- package/src/schemas/organization.ts +0 -68
- package/src/types/agentDoc.d.ts +0 -64
- package/src/types/noteDoc.d.ts +0 -86
- package/src/types/schedule.d.ts +0 -391
- package/src/utils/agentDoc.ts +0 -109
- package/src/utils/campaignFormEditor.ts +0 -871
- package/src/utils/dataTableRealtimeAuthority.ts +0 -209
- package/src/utils/dataTableRealtimeSelection.ts +0 -134
- package/src/utils/dataTableRowDocument.ts +0 -508
- package/src/utils/dataTableSource.ts +0 -230
- package/src/utils/schedule.ts +0 -799
- package/src/utils/scheduleEvaluation.ts +0 -1994
- package/src/utils/scheduleICS.ts +0 -246
- package/src/utils/scheduleRuleTemplates.ts +0 -188
- package/src/utils/sheetRegion.ts +0 -374
- package/src/utils/sheetRegionFilter.ts +0 -1259
- package/src/utils/sheetRegionSourceRegistry.ts +0 -594
- package/tests/schedule.test.ts +0 -693
- package/tests/scheduleEvaluation.test.ts +0 -1970
- package/tests/scheduleICS.test.ts +0 -208
- package/tests/scheduleRuleTemplates.test.ts +0 -176
- package/tests/scheduleSweepInvariants.test.ts +0 -428
- package/tests/sheetRegionFilter.test.ts +0 -1135
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { SHEET_FORMULA_AT_PREFIX_BUILTIN_FUNCTION_NAMES } from '../constants/sheet.ts';
|
|
2
|
+
import type { SheetFormulaBuiltinFunctionName } from './sheetFormulaEvaluation.ts';
|
|
3
|
+
import { SHEET_FORMULA_AGGREGATE_REFERENCE } from './sheetFormulaReferenceAggregates.ts';
|
|
4
|
+
import { SHEET_FORMULA_DATE_REFERENCE } from './sheetFormulaReferenceDates.ts';
|
|
5
|
+
import { SHEET_FORMULA_LOGICAL_REFERENCE } from './sheetFormulaReferenceLogical.ts';
|
|
6
|
+
import { SHEET_FORMULA_LOOKUP_REFERENCE } from './sheetFormulaReferenceLookup.ts';
|
|
7
|
+
import { SHEET_FORMULA_MATH_REFERENCE } from './sheetFormulaReferenceMath.ts';
|
|
8
|
+
import { SHEET_FORMULA_TEXT_REFERENCE } from './sheetFormulaReferenceText.ts';
|
|
9
|
+
|
|
10
|
+
export type SheetFormulaReferenceScalar = string | number | boolean | null;
|
|
11
|
+
|
|
12
|
+
export type SheetFormulaReferenceExample = {
|
|
13
|
+
formula: string;
|
|
14
|
+
/* For an error example: the error display token (for example '#DIV/0!') */
|
|
15
|
+
expectedValue: SheetFormulaReferenceScalar;
|
|
16
|
+
/* Set on examples that document an error result */
|
|
17
|
+
expectedErrorCode?: string;
|
|
18
|
+
cells?: Record<string, SheetFormulaReferenceScalar>;
|
|
19
|
+
now?: string;
|
|
20
|
+
timeZone?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type SheetFormulaReferenceArg = {
|
|
24
|
+
key: string;
|
|
25
|
+
type: string;
|
|
26
|
+
description: string;
|
|
27
|
+
descriptionI18nKey?: string;
|
|
28
|
+
optional?: boolean;
|
|
29
|
+
repeatable?: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SheetFormulaFunctionReference = {
|
|
33
|
+
name: SheetFormulaBuiltinFunctionName;
|
|
34
|
+
topic: 'math' | 'aggregates' | 'logical' | 'dates' | 'lookup' | 'text';
|
|
35
|
+
signature: string;
|
|
36
|
+
args: readonly SheetFormulaReferenceArg[];
|
|
37
|
+
description: string;
|
|
38
|
+
descriptionI18nKey?: string;
|
|
39
|
+
returns: { type: string; description: string };
|
|
40
|
+
behavior: readonly string[];
|
|
41
|
+
errors: readonly string[];
|
|
42
|
+
examples: readonly SheetFormulaReferenceExample[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const FILE_CONSTANTS = {
|
|
46
|
+
atPrefixedNameSet: new Set<string>(SHEET_FORMULA_AT_PREFIX_BUILTIN_FUNCTION_NAMES),
|
|
47
|
+
roundingPrecisionBehavior:
|
|
48
|
+
'The scaled value is first rounded to 15 significant digits, so decimal inputs such as 1.005 round as written rather than by their binary approximation.',
|
|
49
|
+
numericBehavior: 'Numeric arguments flatten ranges, skip blanks, and coerce numeric strings and booleans (TRUE = 1, FALSE = 0).',
|
|
50
|
+
aggregateBehavior:
|
|
51
|
+
'Flattens ranges, skips blanks and nonnumeric range text, and coerces numeric strings and booleans. Nonnumeric scalar text is an error.',
|
|
52
|
+
numericError: 'INVALID_FORMULA when the nonblank numeric argument count or value is invalid.',
|
|
53
|
+
aggregateArgs: [
|
|
54
|
+
{
|
|
55
|
+
key: 'value',
|
|
56
|
+
type: 'scalar | range',
|
|
57
|
+
description: 'Values or cell ranges to combine; additional arguments are allowed.',
|
|
58
|
+
repeatable: true,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
numberArg: {
|
|
62
|
+
key: 'number',
|
|
63
|
+
type: 'number',
|
|
64
|
+
description: 'Number to calculate.',
|
|
65
|
+
},
|
|
66
|
+
precisionArg: {
|
|
67
|
+
key: 'places',
|
|
68
|
+
type: 'number',
|
|
69
|
+
description: 'Decimal places, truncated to an integer. Defaults to 0; negative places round to tens, hundreds, and so on.',
|
|
70
|
+
optional: true,
|
|
71
|
+
},
|
|
72
|
+
dateArg: {
|
|
73
|
+
key: 'date',
|
|
74
|
+
type: 'ISO date | ISO datetime',
|
|
75
|
+
description: 'One valid ISO date or datetime value. Numeric spreadsheet serials are not accepted.',
|
|
76
|
+
},
|
|
77
|
+
} satisfies Record<string, unknown>;
|
|
78
|
+
|
|
79
|
+
export const SHEET_FORMULA_REFERENCE: Record<SheetFormulaBuiltinFunctionName, SheetFormulaFunctionReference> = {
|
|
80
|
+
ABS: {
|
|
81
|
+
name: 'ABS',
|
|
82
|
+
topic: 'math',
|
|
83
|
+
signature: 'ABS(number)',
|
|
84
|
+
args: [FILE_CONSTANTS.numberArg],
|
|
85
|
+
description: 'Returns the absolute value of a number.',
|
|
86
|
+
returns: { type: 'number', description: 'The nonnegative magnitude.' },
|
|
87
|
+
behavior: [FILE_CONSTANTS.numericBehavior],
|
|
88
|
+
errors: [FILE_CONSTANTS.numericError],
|
|
89
|
+
examples: [{ formula: '=ABS(-3)', expectedValue: 3 }],
|
|
90
|
+
},
|
|
91
|
+
AVERAGE: {
|
|
92
|
+
name: 'AVERAGE',
|
|
93
|
+
topic: 'aggregates',
|
|
94
|
+
signature: 'AVERAGE(value, ...)',
|
|
95
|
+
args: FILE_CONSTANTS.aggregateArgs,
|
|
96
|
+
description: 'Returns the arithmetic mean of the numeric values.',
|
|
97
|
+
returns: {
|
|
98
|
+
type: 'number',
|
|
99
|
+
description: 'Sum divided by the number of included numeric values.',
|
|
100
|
+
},
|
|
101
|
+
behavior: [FILE_CONSTANTS.aggregateBehavior],
|
|
102
|
+
errors: ['DIVIDE_BY_ZERO when no numeric values remain.', 'INVALID_FORMULA for nonnumeric scalar text.'],
|
|
103
|
+
examples: [
|
|
104
|
+
{
|
|
105
|
+
formula: '=AVERAGE(A1:A3)',
|
|
106
|
+
cells: { A1: 2, A2: 'skip', A3: 4 },
|
|
107
|
+
expectedValue: 3,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
CEILING: {
|
|
112
|
+
name: 'CEILING',
|
|
113
|
+
topic: 'math',
|
|
114
|
+
signature: 'CEILING(number, [significance])',
|
|
115
|
+
args: [
|
|
116
|
+
FILE_CONSTANTS.numberArg,
|
|
117
|
+
{
|
|
118
|
+
key: 'significance',
|
|
119
|
+
type: 'number',
|
|
120
|
+
description: 'Rounding multiple. Omitted or zero uses 1.',
|
|
121
|
+
optional: true,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
description: 'Rounds using ceil(number / significance) multiplied by significance.',
|
|
125
|
+
returns: { type: 'number', description: 'A multiple of the significance.' },
|
|
126
|
+
behavior: [
|
|
127
|
+
FILE_CONSTANTS.numericBehavior,
|
|
128
|
+
'With positive significance, rounds toward positive infinity, including for negative numbers. Zero significance currently defaults to 1.',
|
|
129
|
+
],
|
|
130
|
+
errors: [FILE_CONSTANTS.numericError],
|
|
131
|
+
examples: [
|
|
132
|
+
{ formula: '=CEILING(4.2, 2)', expectedValue: 6 },
|
|
133
|
+
{ formula: '=CEILING(-4.2, 2)', expectedValue: -4 },
|
|
134
|
+
{ formula: '=CEILING(4.2, 0)', expectedValue: 5 },
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
COUNT: {
|
|
138
|
+
name: 'COUNT',
|
|
139
|
+
topic: 'aggregates',
|
|
140
|
+
signature: 'COUNT(value, ...)',
|
|
141
|
+
args: FILE_CONSTANTS.aggregateArgs,
|
|
142
|
+
description: 'Counts values that are actual finite numbers.',
|
|
143
|
+
returns: {
|
|
144
|
+
type: 'number',
|
|
145
|
+
description: 'Count of finite numeric values, or 0 when there are none.',
|
|
146
|
+
},
|
|
147
|
+
behavior: ['Flattens ranges. Numeric strings, booleans, dates, and blanks do not count.'],
|
|
148
|
+
errors: ['Errors from evaluated arguments propagate.'],
|
|
149
|
+
examples: [
|
|
150
|
+
{
|
|
151
|
+
formula: '=COUNT(A1:A4)',
|
|
152
|
+
cells: { A1: 2, A2: '3', A3: true, A4: null },
|
|
153
|
+
expectedValue: 1,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
COUNTA: {
|
|
158
|
+
name: 'COUNTA',
|
|
159
|
+
topic: 'aggregates',
|
|
160
|
+
signature: 'COUNTA(value, ...)',
|
|
161
|
+
args: FILE_CONSTANTS.aggregateArgs,
|
|
162
|
+
description: 'Counts nonblank values.',
|
|
163
|
+
returns: {
|
|
164
|
+
type: 'number',
|
|
165
|
+
description: 'Count of values other than null, undefined, and empty strings.',
|
|
166
|
+
},
|
|
167
|
+
behavior: ['Flattens ranges. Zero, FALSE, and whitespace-only text count as nonblank.'],
|
|
168
|
+
errors: ['Errors from evaluated arguments propagate.'],
|
|
169
|
+
examples: [
|
|
170
|
+
{
|
|
171
|
+
formula: '=COUNTA(A1:A4)',
|
|
172
|
+
cells: { A1: 0, A2: false, A3: '', A4: ' ' },
|
|
173
|
+
expectedValue: 3,
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
DATE: {
|
|
178
|
+
name: 'DATE',
|
|
179
|
+
topic: 'dates',
|
|
180
|
+
signature: 'DATE(year, month, day)',
|
|
181
|
+
args: [
|
|
182
|
+
{
|
|
183
|
+
key: 'year',
|
|
184
|
+
type: 'number',
|
|
185
|
+
description: 'Full year, truncated to an integer.',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: 'month',
|
|
189
|
+
type: 'number',
|
|
190
|
+
description: 'Month from 1 through 12, truncated to an integer.',
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: 'day',
|
|
194
|
+
type: 'number',
|
|
195
|
+
description: 'Valid day of the selected month, truncated to an integer.',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
description: 'Constructs a valid calendar date in the organization time zone.',
|
|
199
|
+
returns: {
|
|
200
|
+
type: 'date string',
|
|
201
|
+
description: 'A yyyy-MM-dd string, not a numeric date serial.',
|
|
202
|
+
},
|
|
203
|
+
behavior: [FILE_CONSTANTS.numericBehavior, 'Out-of-range months and days are rejected rather than rolled into another month.'],
|
|
204
|
+
errors: ['INVALID_FORMULA for invalid dates or an invalid numeric argument count.'],
|
|
205
|
+
examples: [{ formula: '=DATE(2026, 6, 5)', expectedValue: '2026-06-05' }],
|
|
206
|
+
},
|
|
207
|
+
DAY: {
|
|
208
|
+
name: 'DAY',
|
|
209
|
+
topic: 'dates',
|
|
210
|
+
signature: 'DAY(date)',
|
|
211
|
+
args: [FILE_CONSTANTS.dateArg],
|
|
212
|
+
description: 'Returns the day of the month from a date.',
|
|
213
|
+
returns: { type: 'number', description: 'Day from 1 through 31.' },
|
|
214
|
+
behavior: ['Parses the value in the organization time zone. Exactly one nonblank date value is required.'],
|
|
215
|
+
errors: ['INVALID_FORMULA for invalid dates, numeric serials, or an invalid argument count.'],
|
|
216
|
+
examples: [{ formula: '=DAY(DATE(2026, 6, 5))', expectedValue: 5 }],
|
|
217
|
+
},
|
|
218
|
+
FLOOR: {
|
|
219
|
+
name: 'FLOOR',
|
|
220
|
+
topic: 'math',
|
|
221
|
+
signature: 'FLOOR(number, [significance])',
|
|
222
|
+
args: [
|
|
223
|
+
FILE_CONSTANTS.numberArg,
|
|
224
|
+
{
|
|
225
|
+
key: 'significance',
|
|
226
|
+
type: 'number',
|
|
227
|
+
description: 'Rounding multiple. Omitted or zero uses 1.',
|
|
228
|
+
optional: true,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
description: 'Rounds using floor(number / significance) multiplied by significance.',
|
|
232
|
+
returns: { type: 'number', description: 'A multiple of the significance.' },
|
|
233
|
+
behavior: [
|
|
234
|
+
FILE_CONSTANTS.numericBehavior,
|
|
235
|
+
'With positive significance, rounds toward negative infinity, including for negative numbers. Zero significance currently defaults to 1.',
|
|
236
|
+
],
|
|
237
|
+
errors: [FILE_CONSTANTS.numericError],
|
|
238
|
+
examples: [
|
|
239
|
+
{ formula: '=FLOOR(4.2, 2)', expectedValue: 4 },
|
|
240
|
+
{ formula: '=FLOOR(-4.2, 2)', expectedValue: -6 },
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
IF: {
|
|
244
|
+
name: 'IF',
|
|
245
|
+
topic: 'logical',
|
|
246
|
+
signature: 'IF(condition, value_if_true, value_if_false)',
|
|
247
|
+
args: [
|
|
248
|
+
{
|
|
249
|
+
key: 'condition',
|
|
250
|
+
type: 'boolean-compatible scalar',
|
|
251
|
+
description: 'Comparison, boolean, number, or boolean-compatible text to test.',
|
|
252
|
+
descriptionI18nKey: 'sheet.formula_function_if_arg_condition_description',
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
key: 'value_if_true',
|
|
256
|
+
type: 'expression',
|
|
257
|
+
description: 'Value evaluated and returned only when the condition is true.',
|
|
258
|
+
descriptionI18nKey: 'sheet.formula_function_if_arg_value_if_true_description',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
key: 'value_if_false',
|
|
262
|
+
type: 'expression',
|
|
263
|
+
description: 'Value evaluated and returned only when the condition is false.',
|
|
264
|
+
descriptionI18nKey: 'sheet.formula_function_if_arg_value_if_false_description',
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
description: 'Returns one of two values according to a condition.',
|
|
268
|
+
descriptionI18nKey: 'sheet.formula_function_if_description',
|
|
269
|
+
returns: {
|
|
270
|
+
type: 'selected value',
|
|
271
|
+
description: 'The value of the selected branch.',
|
|
272
|
+
},
|
|
273
|
+
behavior: [
|
|
274
|
+
'Requires exactly three arguments. Only the selected branch is evaluated.',
|
|
275
|
+
'Zero, blanks, and FALSE are false; nonzero numeric values and TRUE are true. Other nonnumeric text is invalid.',
|
|
276
|
+
],
|
|
277
|
+
errors: [
|
|
278
|
+
'INVALID_FORMULA for wrong arity or a condition that cannot be converted to a boolean. Condition and selected-branch errors propagate.',
|
|
279
|
+
],
|
|
280
|
+
examples: [{ formula: '=IF(2 > 1, 5, 1/0)', expectedValue: 5 }],
|
|
281
|
+
},
|
|
282
|
+
IFERROR: {
|
|
283
|
+
name: 'IFERROR',
|
|
284
|
+
topic: 'logical',
|
|
285
|
+
signature: 'IFERROR(value, fallback)',
|
|
286
|
+
args: [
|
|
287
|
+
{
|
|
288
|
+
key: 'value',
|
|
289
|
+
type: 'expression',
|
|
290
|
+
description: 'Expression evaluated first.',
|
|
291
|
+
descriptionI18nKey: 'sheet.formula_function_iferror_arg_value_description',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
key: 'fallback',
|
|
295
|
+
type: 'expression',
|
|
296
|
+
description: 'Expression evaluated only if the first expression returns any formula error.',
|
|
297
|
+
descriptionI18nKey: 'sheet.formula_function_iferror_arg_fallback_description',
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
description: 'Returns a fallback when the first expression has any formula error.',
|
|
301
|
+
descriptionI18nKey: 'sheet.formula_function_iferror_description',
|
|
302
|
+
returns: {
|
|
303
|
+
type: 'value | fallback value',
|
|
304
|
+
description: 'The original value on success, otherwise the fallback.',
|
|
305
|
+
},
|
|
306
|
+
behavior: [
|
|
307
|
+
'Requires exactly two arguments. Skips the fallback when the first expression succeeds.',
|
|
308
|
+
'Literal text such as "#ERROR!" is a value, not a formula error.',
|
|
309
|
+
],
|
|
310
|
+
errors: ['INVALID_FORMULA for wrong arity. An evaluated fallback can itself return an error.'],
|
|
311
|
+
examples: [
|
|
312
|
+
{ formula: '=IFERROR(1/0, 9)', expectedValue: 9 },
|
|
313
|
+
{ formula: '=IFERROR(5, 1/0)', expectedValue: 5 },
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
IFNA: {
|
|
317
|
+
name: 'IFNA',
|
|
318
|
+
topic: 'logical',
|
|
319
|
+
signature: 'IFNA(value, fallback)',
|
|
320
|
+
args: [
|
|
321
|
+
{
|
|
322
|
+
key: 'value',
|
|
323
|
+
type: 'expression',
|
|
324
|
+
description: 'Expression evaluated first.',
|
|
325
|
+
descriptionI18nKey: 'sheet.formula_function_ifna_arg_value_description',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
key: 'fallback',
|
|
329
|
+
type: 'expression',
|
|
330
|
+
description: 'Expression evaluated only for a NOT_FOUND formula error.',
|
|
331
|
+
descriptionI18nKey: 'sheet.formula_function_ifna_arg_fallback_description',
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
description: 'Returns a fallback only when a referenced value cannot be found.',
|
|
335
|
+
descriptionI18nKey: 'sheet.formula_function_ifna_description',
|
|
336
|
+
returns: {
|
|
337
|
+
type: 'value | fallback value',
|
|
338
|
+
description: 'The original value unless it returns NOT_FOUND (#N/A).',
|
|
339
|
+
},
|
|
340
|
+
behavior: [
|
|
341
|
+
'Requires exactly two arguments. Does not catch divide-by-zero, invalid syntax, or other error codes.',
|
|
342
|
+
'Literal text "#N/A" is a value and does not trigger the fallback.',
|
|
343
|
+
],
|
|
344
|
+
errors: ['INVALID_FORMULA for wrong arity. Errors other than NOT_FOUND propagate, as do errors from the evaluated fallback.'],
|
|
345
|
+
examples: [
|
|
346
|
+
{
|
|
347
|
+
formula: '=IFNA(REGEXMATCH(A1:A2, "pear"), "missing")',
|
|
348
|
+
cells: { A1: 'apple', A2: 'banana' },
|
|
349
|
+
expectedValue: 'missing',
|
|
350
|
+
},
|
|
351
|
+
{ formula: '=IFNA("#N/A", "missing")', expectedValue: '#N/A' },
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
INCLUDES: {
|
|
355
|
+
name: 'INCLUDES',
|
|
356
|
+
topic: 'lookup',
|
|
357
|
+
signature: 'INCLUDES(value, range, [value_if_true, value_if_false])',
|
|
358
|
+
args: [
|
|
359
|
+
{
|
|
360
|
+
key: 'value',
|
|
361
|
+
type: 'scalar',
|
|
362
|
+
description: 'Nonblank value to look for.',
|
|
363
|
+
descriptionI18nKey: 'sheet.formula_function_includes_arg_needle_description',
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
key: 'range',
|
|
367
|
+
type: 'range',
|
|
368
|
+
description: 'Cell range to search.',
|
|
369
|
+
descriptionI18nKey: 'sheet.formula_function_includes_arg_range_description',
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
key: 'value_if_true',
|
|
373
|
+
type: 'expression',
|
|
374
|
+
description: 'Branch evaluated only for a match; supply both branches or neither.',
|
|
375
|
+
optional: true,
|
|
376
|
+
descriptionI18nKey: 'sheet.formula_function_includes_arg_value_if_true_description',
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
key: 'value_if_false',
|
|
380
|
+
type: 'expression',
|
|
381
|
+
description: 'Branch evaluated only without a match; supply both branches or neither.',
|
|
382
|
+
optional: true,
|
|
383
|
+
descriptionI18nKey: 'sheet.formula_function_includes_arg_value_if_false_description',
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
description: 'Tests range membership, optionally returning one of two values.',
|
|
387
|
+
descriptionI18nKey: 'sheet.formula_function_includes_description',
|
|
388
|
+
returns: {
|
|
389
|
+
type: 'boolean | selected value',
|
|
390
|
+
description: 'Boolean with two arguments; selected branch with four arguments.',
|
|
391
|
+
},
|
|
392
|
+
behavior: [
|
|
393
|
+
'Uses numeric comparison when both values can be numeric, otherwise case-sensitive string comparison.',
|
|
394
|
+
'Blank needles and blank range entries never match. Four-argument form evaluates only the selected branch.',
|
|
395
|
+
],
|
|
396
|
+
errors: ['INVALID_FORMULA unless there are exactly two or four arguments and the second argument is a range.'],
|
|
397
|
+
examples: [
|
|
398
|
+
{
|
|
399
|
+
formula: '=INCLUDES("2", A1:A2)',
|
|
400
|
+
cells: { A1: 1, A2: 2 },
|
|
401
|
+
expectedValue: true,
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
formula: '=INCLUDES("apple", A1:A2, "found", 1/0)',
|
|
405
|
+
cells: { A1: 'apple', A2: 'pear' },
|
|
406
|
+
expectedValue: 'found',
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
MAX: {
|
|
411
|
+
name: 'MAX',
|
|
412
|
+
topic: 'aggregates',
|
|
413
|
+
signature: 'MAX(value, ...)',
|
|
414
|
+
args: FILE_CONSTANTS.aggregateArgs,
|
|
415
|
+
description: 'Returns the largest numeric value, also converting parseable dates to numeric date serials.',
|
|
416
|
+
returns: {
|
|
417
|
+
type: 'number',
|
|
418
|
+
description: 'The maximum numeric value or converted spreadsheet date serial.',
|
|
419
|
+
},
|
|
420
|
+
behavior: [
|
|
421
|
+
FILE_CONSTANTS.aggregateBehavior,
|
|
422
|
+
'Unlike MIN, MAX converts valid date strings and date values to spreadsheet serials. Prefer ISO dates for deterministic parsing.',
|
|
423
|
+
],
|
|
424
|
+
errors: ['INVALID_FORMULA when no numeric/date values remain, or a scalar cannot be converted.'],
|
|
425
|
+
examples: [
|
|
426
|
+
{ formula: '=MAX(3, 8, 2)', expectedValue: 8 },
|
|
427
|
+
{ formula: '=MAX("2026-01-02") - MAX("2026-01-01")', expectedValue: 1 },
|
|
428
|
+
],
|
|
429
|
+
},
|
|
430
|
+
MIN: {
|
|
431
|
+
name: 'MIN',
|
|
432
|
+
topic: 'aggregates',
|
|
433
|
+
signature: 'MIN(value, ...)',
|
|
434
|
+
args: FILE_CONSTANTS.aggregateArgs,
|
|
435
|
+
description: 'Returns the smallest numeric value.',
|
|
436
|
+
returns: {
|
|
437
|
+
type: 'number',
|
|
438
|
+
description: 'The minimum included numeric value.',
|
|
439
|
+
},
|
|
440
|
+
behavior: [FILE_CONSTANTS.aggregateBehavior, 'Does not convert date strings to spreadsheet serials.'],
|
|
441
|
+
errors: ['INVALID_FORMULA when no numeric values remain or scalar text is nonnumeric.'],
|
|
442
|
+
examples: [{ formula: '=MIN(3, -2, 8)', expectedValue: -2 }],
|
|
443
|
+
},
|
|
444
|
+
MOD: {
|
|
445
|
+
name: 'MOD',
|
|
446
|
+
topic: 'math',
|
|
447
|
+
signature: 'MOD(number, divisor)',
|
|
448
|
+
args: [FILE_CONSTANTS.numberArg, { key: 'divisor', type: 'number', description: 'Nonzero divisor.' }],
|
|
449
|
+
description: "Returns the modulo remainder with the divisor's sign.",
|
|
450
|
+
returns: { type: 'number', description: 'Remainder after division.' },
|
|
451
|
+
behavior: [FILE_CONSTANTS.numericBehavior, 'Uses ((number % divisor) + divisor) % divisor.'],
|
|
452
|
+
errors: [FILE_CONSTANTS.numericError, 'DIVIDE_BY_ZERO for a zero divisor.'],
|
|
453
|
+
examples: [{ formula: '=MOD(-5, 3)', expectedValue: 1 }],
|
|
454
|
+
},
|
|
455
|
+
MONTH: {
|
|
456
|
+
name: 'MONTH',
|
|
457
|
+
topic: 'dates',
|
|
458
|
+
signature: 'MONTH(date)',
|
|
459
|
+
args: [FILE_CONSTANTS.dateArg],
|
|
460
|
+
description: 'Returns the month from a date.',
|
|
461
|
+
returns: { type: 'number', description: 'Month from 1 through 12.' },
|
|
462
|
+
behavior: ['Parses the value in the organization time zone. Exactly one nonblank date value is required.'],
|
|
463
|
+
errors: ['INVALID_FORMULA for invalid dates, numeric serials, or an invalid argument count.'],
|
|
464
|
+
examples: [{ formula: '=MONTH("2026-06-05")', expectedValue: 6 }],
|
|
465
|
+
},
|
|
466
|
+
NOW: {
|
|
467
|
+
name: 'NOW',
|
|
468
|
+
topic: 'dates',
|
|
469
|
+
signature: 'NOW()',
|
|
470
|
+
args: [],
|
|
471
|
+
description: 'Returns the current datetime in the organization time zone.',
|
|
472
|
+
returns: {
|
|
473
|
+
type: 'ISO datetime string',
|
|
474
|
+
description: 'Datetime including its time-zone offset, not a numeric serial.',
|
|
475
|
+
},
|
|
476
|
+
behavior: ['Volatile: the result depends on evaluation time. Persisted cells change when recalculated, not continuously.'],
|
|
477
|
+
errors: ['INVALID_FORMULA if any arguments are supplied.'],
|
|
478
|
+
examples: [
|
|
479
|
+
{
|
|
480
|
+
formula: '=NOW()',
|
|
481
|
+
now: '2026-01-02T03:04:05.000Z',
|
|
482
|
+
timeZone: 'UTC',
|
|
483
|
+
expectedValue: '2026-01-02T03:04:05.000Z',
|
|
484
|
+
},
|
|
485
|
+
],
|
|
486
|
+
},
|
|
487
|
+
POWER: {
|
|
488
|
+
name: 'POWER',
|
|
489
|
+
topic: 'math',
|
|
490
|
+
signature: 'POWER(number, exponent)',
|
|
491
|
+
args: [
|
|
492
|
+
FILE_CONSTANTS.numberArg,
|
|
493
|
+
{
|
|
494
|
+
key: 'exponent',
|
|
495
|
+
type: 'number',
|
|
496
|
+
description: 'Exponent applied to the number.',
|
|
497
|
+
},
|
|
498
|
+
],
|
|
499
|
+
description: 'Raises a number to a power.',
|
|
500
|
+
returns: { type: 'number', description: 'number raised to exponent.' },
|
|
501
|
+
behavior: [FILE_CONSTANTS.numericBehavior, 'The ^ operator computes the same value: =2^3 is 8.'],
|
|
502
|
+
errors: [
|
|
503
|
+
FILE_CONSTANTS.numericError,
|
|
504
|
+
'DIVIDE_BY_ZERO (#DIV/0!) when zero is raised to a negative power.',
|
|
505
|
+
'INVALID_NUMBER (#NUM!) when the result is not a finite real number, such as a fractional power of a negative number or an overflow.',
|
|
506
|
+
],
|
|
507
|
+
examples: [
|
|
508
|
+
{ formula: '=POWER(2, 3)', expectedValue: 8 },
|
|
509
|
+
{
|
|
510
|
+
formula: '=POWER(0, -1)',
|
|
511
|
+
expectedValue: '#DIV/0!',
|
|
512
|
+
expectedErrorCode: 'DIVIDE_BY_ZERO',
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
formula: '=POWER(-8, 1/3)',
|
|
516
|
+
expectedValue: '#NUM!',
|
|
517
|
+
expectedErrorCode: 'INVALID_NUMBER',
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
},
|
|
521
|
+
ROUND: {
|
|
522
|
+
name: 'ROUND',
|
|
523
|
+
topic: 'math',
|
|
524
|
+
signature: 'ROUND(number, [places])',
|
|
525
|
+
args: [FILE_CONSTANTS.numberArg, FILE_CONSTANTS.precisionArg],
|
|
526
|
+
description: 'Rounds to the nearest value at the selected decimal precision.',
|
|
527
|
+
returns: { type: 'number', description: 'The rounded number.' },
|
|
528
|
+
behavior: [
|
|
529
|
+
FILE_CONSTANTS.numericBehavior,
|
|
530
|
+
'Halfway values round away from zero, as in Excel: ROUND(2.5) is 3 and ROUND(-2.5) is -3.',
|
|
531
|
+
FILE_CONSTANTS.roundingPrecisionBehavior,
|
|
532
|
+
],
|
|
533
|
+
errors: [FILE_CONSTANTS.numericError],
|
|
534
|
+
examples: [
|
|
535
|
+
{ formula: '=ROUND(3.14159, 2)', expectedValue: 3.14 },
|
|
536
|
+
{ formula: '=ROUND(-1.5)', expectedValue: -2 },
|
|
537
|
+
{ formula: '=ROUND(1.005, 2)', expectedValue: 1.01 },
|
|
538
|
+
{ formula: '=ROUND(123, -1)', expectedValue: 120 },
|
|
539
|
+
],
|
|
540
|
+
},
|
|
541
|
+
ROUNDDOWN: {
|
|
542
|
+
name: 'ROUNDDOWN',
|
|
543
|
+
topic: 'math',
|
|
544
|
+
signature: 'ROUNDDOWN(number, [places])',
|
|
545
|
+
args: [FILE_CONSTANTS.numberArg, FILE_CONSTANTS.precisionArg],
|
|
546
|
+
description: 'Rounds toward zero at the selected decimal precision.',
|
|
547
|
+
returns: { type: 'number', description: 'The rounded number.' },
|
|
548
|
+
behavior: [FILE_CONSTANTS.numericBehavior, FILE_CONSTANTS.roundingPrecisionBehavior],
|
|
549
|
+
errors: [FILE_CONSTANTS.numericError],
|
|
550
|
+
examples: [{ formula: '=ROUNDDOWN(-3.149, 2)', expectedValue: -3.14 }],
|
|
551
|
+
},
|
|
552
|
+
ROUNDUP: {
|
|
553
|
+
name: 'ROUNDUP',
|
|
554
|
+
topic: 'math',
|
|
555
|
+
signature: 'ROUNDUP(number, [places])',
|
|
556
|
+
args: [FILE_CONSTANTS.numberArg, FILE_CONSTANTS.precisionArg],
|
|
557
|
+
description: 'Rounds away from zero at the selected decimal precision.',
|
|
558
|
+
returns: { type: 'number', description: 'The rounded number.' },
|
|
559
|
+
behavior: [FILE_CONSTANTS.numericBehavior, FILE_CONSTANTS.roundingPrecisionBehavior],
|
|
560
|
+
errors: [FILE_CONSTANTS.numericError],
|
|
561
|
+
examples: [{ formula: '=ROUNDUP(-3.141, 2)', expectedValue: -3.15 }],
|
|
562
|
+
},
|
|
563
|
+
REGEXMATCH: {
|
|
564
|
+
name: 'REGEXMATCH',
|
|
565
|
+
topic: 'lookup',
|
|
566
|
+
signature: 'REGEXMATCH(range, pattern)',
|
|
567
|
+
args: [
|
|
568
|
+
{
|
|
569
|
+
key: 'range',
|
|
570
|
+
type: 'range',
|
|
571
|
+
description: 'Cell range to search in row-major order.',
|
|
572
|
+
descriptionI18nKey: 'sheet.formula_function_regexmatch_arg_range_description',
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
key: 'pattern',
|
|
576
|
+
type: 'nonblank scalar',
|
|
577
|
+
description: 'Case-insensitive regular expression; invalid regex falls back to literal substring matching.',
|
|
578
|
+
descriptionI18nKey: 'sheet.formula_function_regexmatch_arg_pattern_description',
|
|
579
|
+
},
|
|
580
|
+
],
|
|
581
|
+
description: 'Returns the first matching cell value from a range, not a boolean.',
|
|
582
|
+
descriptionI18nKey: 'sheet.formula_function_regexmatch_description',
|
|
583
|
+
returns: {
|
|
584
|
+
type: 'matched scalar',
|
|
585
|
+
description: 'The original typed value of the first matching nonblank cell.',
|
|
586
|
+
},
|
|
587
|
+
behavior: [
|
|
588
|
+
'Nebula-specific behavior: searches range cells in row-major order and returns a value rather than a TRUE/FALSE match result.',
|
|
589
|
+
'Matching is case-insensitive. An invalid regular expression is treated as a literal substring.',
|
|
590
|
+
],
|
|
591
|
+
errors: [
|
|
592
|
+
'NOT_FOUND (#N/A) when nothing matches; IFNA can supply a fallback.',
|
|
593
|
+
'INVALID_FORMULA unless there are two arguments, the first is a range, and the second is a nonblank scalar.',
|
|
594
|
+
],
|
|
595
|
+
examples: [
|
|
596
|
+
{
|
|
597
|
+
formula: '=REGEXMATCH(A1:A3, "^ap")',
|
|
598
|
+
cells: { A1: 'pear', A2: 'Apple', A3: 'apricot' },
|
|
599
|
+
expectedValue: 'Apple',
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
formula: '=REGEXMATCH(A1:A2, "[")',
|
|
603
|
+
cells: { A1: 'plain', A2: '[saved]' },
|
|
604
|
+
expectedValue: '[saved]',
|
|
605
|
+
},
|
|
606
|
+
],
|
|
607
|
+
},
|
|
608
|
+
SUM: {
|
|
609
|
+
name: 'SUM',
|
|
610
|
+
topic: 'aggregates',
|
|
611
|
+
signature: 'SUM(value, ...)',
|
|
612
|
+
args: FILE_CONSTANTS.aggregateArgs,
|
|
613
|
+
description: 'Adds numeric values from scalars and ranges.',
|
|
614
|
+
returns: {
|
|
615
|
+
type: 'number',
|
|
616
|
+
description: 'Sum of included values, or 0 when none remain.',
|
|
617
|
+
},
|
|
618
|
+
behavior: [
|
|
619
|
+
FILE_CONSTANTS.aggregateBehavior,
|
|
620
|
+
'A data-table lookup supplies one scalar; SUM does not make that lookup aggregate every matching row.',
|
|
621
|
+
],
|
|
622
|
+
errors: ['INVALID_FORMULA for nonnumeric scalar text.'],
|
|
623
|
+
examples: [
|
|
624
|
+
{
|
|
625
|
+
formula: '=SUM(A1:A4)',
|
|
626
|
+
cells: { A1: 2, A2: 'skip', A3: '4', A4: true },
|
|
627
|
+
expectedValue: 7,
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
},
|
|
631
|
+
TODAY: {
|
|
632
|
+
name: 'TODAY',
|
|
633
|
+
topic: 'dates',
|
|
634
|
+
signature: 'TODAY()',
|
|
635
|
+
args: [],
|
|
636
|
+
description: 'Returns the current calendar date in the organization time zone.',
|
|
637
|
+
returns: {
|
|
638
|
+
type: 'date string',
|
|
639
|
+
description: 'A yyyy-MM-dd string, not a numeric serial.',
|
|
640
|
+
},
|
|
641
|
+
behavior: ['Volatile: the date depends on evaluation time and time zone. Persisted cells change when recalculated.'],
|
|
642
|
+
errors: ['INVALID_FORMULA if any arguments are supplied.'],
|
|
643
|
+
examples: [
|
|
644
|
+
{
|
|
645
|
+
formula: '=TODAY()',
|
|
646
|
+
now: '2026-01-02T03:04:05.000Z',
|
|
647
|
+
timeZone: 'America/Toronto',
|
|
648
|
+
expectedValue: '2026-01-01',
|
|
649
|
+
},
|
|
650
|
+
],
|
|
651
|
+
},
|
|
652
|
+
YEAR: {
|
|
653
|
+
name: 'YEAR',
|
|
654
|
+
topic: 'dates',
|
|
655
|
+
signature: 'YEAR(date)',
|
|
656
|
+
args: [FILE_CONSTANTS.dateArg],
|
|
657
|
+
description: 'Returns the full year from a date.',
|
|
658
|
+
returns: { type: 'number', description: 'Calendar year.' },
|
|
659
|
+
behavior: ['Parses the value in the organization time zone. Exactly one nonblank date value is required.'],
|
|
660
|
+
errors: ['INVALID_FORMULA for invalid dates, numeric serials, or an invalid argument count.'],
|
|
661
|
+
examples: [{ formula: '=YEAR("2026-06-05")', expectedValue: 2026 }],
|
|
662
|
+
},
|
|
663
|
+
...SHEET_FORMULA_AGGREGATE_REFERENCE,
|
|
664
|
+
...SHEET_FORMULA_LOGICAL_REFERENCE,
|
|
665
|
+
...SHEET_FORMULA_LOOKUP_REFERENCE,
|
|
666
|
+
...SHEET_FORMULA_TEXT_REFERENCE,
|
|
667
|
+
...SHEET_FORMULA_DATE_REFERENCE,
|
|
668
|
+
...SHEET_FORMULA_MATH_REFERENCE,
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
/* Return shared built-in documentation using the evaluator's case-insensitive
|
|
672
|
+
* spelling; the '@name' spelling resolves only for the legacy builtins, as in
|
|
673
|
+
* getSheetFormulaBuiltinFunctionName. */
|
|
674
|
+
export function getSheetFormulaFunctionReference(name: string): SheetFormulaFunctionReference | null {
|
|
675
|
+
const trimmedName = name.trim();
|
|
676
|
+
const normalized = trimmedName.replace(/^@/, '').toUpperCase();
|
|
677
|
+
if (trimmedName.startsWith('@') && !FILE_CONSTANTS.atPrefixedNameSet.has(normalized)) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return Object.prototype.hasOwnProperty.call(SHEET_FORMULA_REFERENCE, normalized)
|
|
682
|
+
? SHEET_FORMULA_REFERENCE[normalized as SheetFormulaBuiltinFunctionName]
|
|
683
|
+
: null;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/*
|
|
687
|
+
* Return the builtin function references whose names start with one typed
|
|
688
|
+
* identifier (letters only, case-insensitive) for editor autocomplete: an
|
|
689
|
+
* exact name first, then the others alphabetically, at most `limit`. An
|
|
690
|
+
* identifier with digits or underscores (such as the A1 in =A1) never
|
|
691
|
+
* suggests anything.
|
|
692
|
+
*/
|
|
693
|
+
export function getSheetFormulaFunctionNameSuggestions(prefix: string, limit = 8): SheetFormulaFunctionReference[] {
|
|
694
|
+
if (!/^[A-Za-z]+$/.test(prefix)) {
|
|
695
|
+
return [];
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const normalized = prefix.toUpperCase();
|
|
699
|
+
return Object.values(SHEET_FORMULA_REFERENCE)
|
|
700
|
+
.filter((reference) => reference.name.startsWith(normalized))
|
|
701
|
+
.sort((left, right) => (left.name === normalized ? -1 : right.name === normalized ? 1 : left.name < right.name ? -1 : 1))
|
|
702
|
+
.slice(0, limit);
|
|
703
|
+
}
|