All files / libs/amalia-lang/formula/evaluate/shared/src/functions/array/count index.ts

100% Statements 29/29
50% Branches 1/2
100% Functions 1/1
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
import { FormatsEnum } from '@amalia/data-capture/fields/types';
import { type ComputeEngineResult } from '@amalia/payout-calculation/types';
 
import { AmaliaFunctionDefault } from '../../AmaliaFunction';
 
export const arrayCount = new AmaliaFunctionDefault<[ComputeEngineResult], number>({
  name: AmaliaFunctionKeys.COUNT,
  category: AmaliaFunctionCategory.ARRAY,
 
  exec: (array) => (Array.isArray(array) ? array.length : 0),
 
  nbParamsRequired: 1,
 
  description: 'Get the number of records in an array',
 
  params: [{ name: 'array', description: 'Array, Filters or Links', validFormats: [FormatsEnum.table] }],
 
  examples: [
    {
      desc: 'Returns 2',
      formula: 'COUNT([0, 1])' as AmaliaFormula,
    },
    {
      desc: 'Returns the number of records in the filtered dataset',
      formula: 'COUNT(filter.closedOppsInPeriod)' as AmaliaFormula,
    },
  ],
});