FormulaHelpers

FormulaHelpers

Formula helpers.

Constructor

new FormulaHelpers()

Source:

Methods

accept(param, typeopt, defValueopt, flatopt, allowSingleValue) → {string|number|boolean|Object|Array}

Source:

Check if the param valid, return the parsed param. If type is not given, return the un-parsed param.

Parameters:
Name Type Attributes Default Description
param *
type number | null <optional>
null

The expected type NUMBER: Expect a single number, ARRAY: Expect an flatten array, BOOLEAN: Expect a single boolean, STRING: Expect a single string, COLLECTIONS: Expect an Array of the above types null: Do not parse the value, return it directly. The collection is not a flatted array.

defValue * <optional>

Default value if the param is not given. if undefined, this param is required, a Error will throw if not given. if null, and param is undefined, null will be returned.

flat boolean <optional>
true

If the array should be flattened, only applicable when type is ARRAY. If false, collection is disallowed.

allowSingleValue boolean false

If pack single value into 2d array, only applicable when type is ARRAY.

Returns:
Type
string | number | boolean | Object | Array

acceptNumber(obj, isArray, allowBoolean) → {number|FormulaError}

Source:
Parameters:
Name Type Default Description
obj
isArray true

if it is an array: [1,2,3], will extract the first element

allowBoolean true

Allow parse boolean into number

Returns:
Type
number | FormulaError

flattenDeep(arr1) → {*}

Source:

Flatten an array

Parameters:
Name Type Description
arr1 Array
Returns:
Type
*

flattenParams(params, valueType, allowUnion, hook, defValueopt, minSizeopt)

Source:
See:
  • FormulaHelpers.accept

Flatten parameters to 1D array.

Parameters:
Name Type Attributes Default Description
params Array

Parameter that needs to flatten.

valueType Types | null

The type each item should be, null if allows any type. This only applies to literals.

allowUnion boolean

Allow union, e.g. (A1:C1, E4:F3)

hook function

Invoked after parsing each item. of the array.

defValue * <optional>
null

The value if an param is omitted. i.e. SUM(1,2,,,,,)

minSize number <optional>
1

The minimum size of the parameters

retrieveRanges(context, range1, range2)

Source:

Helper function for SUMIF, AVERAGEIF,...

Parameters:
Name Type Description
context
range1
range2