UNPKG

@odoo/o-spreadsheet

Version:
91 lines (90 loc) 3.93 kB
import { Immutable } from "../types"; import { AddFunctionDescription, ArgDefinition, ArgProposal, FunctionDescription } from "../types/functions"; export declare function arg(definition: string, description?: string, proposals?: ArgProposal[]): ArgDefinition; /** * This function adds on description more general information derived from the * arguments. * * This information is useful during compilation. */ export declare function addMetaInfoFromArg(name: string, addDescr: AddFunctionDescription): FunctionDescription; type ArgToFocus = Immutable<Record<number, { index: number; repeatingGroupIndex?: number; }>>; /** * Returns a function that maps the position of a value in a function to its corresponding argument index. * * In most cases, the task is straightforward: * * In the formula "=SUM(11, 55, 66)" which is defined like this "SUM(value1, [value2, ...])": * - 11 corresponds to the value1 argument => position will be 0 * - 55 and 66 correspond to the [value2, ...] argument => position will be 1 * * In other cases, optional arguments could be defined after repeatable arguments, * or even optional and required arguments could be mixed in unconventional ways. * * The next function has been designed to handle all possible configurations. * The only restriction is if repeatable arguments are present in the function definition: * - they must be defined consecutively * - they must be in a quantity greater than the optional arguments. * * The markdown tables below illustrate how values are mapped to positions based on the number of values supplied. * Each table represents a different function configuration, with columns representing the number of values supplied as arguments * and rows representing the correspondence with the argument index. * * The tables are built based on the following conventions: * - `m`: Mandatory argument (count as one argument) * - `o`: Optional argument (count as zero or one argument) * - `r`: Repeating argument (count as one or more arguments) * * * Configuration 1: (m, o) like the CEILING function * * | | 1 | 2 | * |---|---|---| * | m | 0 | 0 | * | o | | 1 | * * * Configuration 2: (m, m, m, r, r) like the SUMIFS function * * | | 5 | 7 | 3 + 2n | * |---|---|------|------------| * | m | 0 | 0 | 0 | * | m | 1 | 1 | 1 | * | m | 2 | 2 | 2 | * | r | 3 | 3, 5 | 3 + 2n | * | r | 4 | 4, 6 | 3 + 2n + 1 | * * * Configuration 3: (m, m, m, r, r, o) like the SWITCH function * * | | 5 | 6 | 7 | 8 | 3 + 2n | 3 + 2n + 1 | * |---|---|---|------|------|------------|----------------| * | m | 0 | 0 | 0 | 0 | 0 | 0 | * | m | 1 | 1 | 1 | 1 | 1 | 1 | * | m | 2 | 2 | 2 | 2 | 2 | 2 | * | r | 3 | 3 | 3, 5 | 3, 5 | 3 + 2n | 3 + 2n | * | r | 4 | 4 | 4, 6 | 4, 6 | 3 + 2n + 1 | 3 + 2n + 1 | * | o | | 5 | | 7 | | 3 + 2N + 2 | * * * Configuration 4: (m, o, m, o, r, r, r, m) a complex case to understand subtleties * * | | 6 | 7 | 8 | 9 | 10 | 11 | ... | * |---|---|---|---|------|------|------|-----| * | m | 0 | 0 | 0 | 0 | 0 | 0 | ... | * | o | | 1 | 1 | | 1 | 1 | ... | * | m | 1 | 2 | 2 | 1 | 2 | 2 | ... | * | o | | | 3 | | | 3 | ... | * | r | 2 | 3 | 4 | 2, 5 | 3, 6 | 4, 7 | ... | * | r | 3 | 4 | 5 | 3, 6 | 4, 7 | 5, 8 | ... | * | r | 4 | 5 | 6 | 4, 7 | 5, 8 | 6, 9 | ... | * | m | 5 | 6 | 7 | 8 | 9 | 10 | ... | * */ export declare function argTargeting(functionDescription: FunctionDescription, nbrArgSupplied: number): ArgToFocus; export declare function _argTargeting(functionDescription: FunctionDescription, nbrArgSupplied: number): ArgToFocus; export declare function validateArguments(descr: FunctionDescription): void; export {};