All files / libs/amalia-lang/formula/evaluate/shared/src/functions/numbers/min index.ts

100% Statements 40/40
100% Branches 1/1
100% Functions 1/1
100% Lines 40/40

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 30 31 32 33 34 35 36 37 38 39 40 411x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
 
import { AmaliaFunctionDefault } from '../../AmaliaFunction';
 
export const numbersMin = new AmaliaFunctionDefault<number[], number>({
  name: AmaliaFunctionKeys.MIN,
  category: AmaliaFunctionCategory.NUMBERS,
  nbParamsRequired: 0,
  hasInfiniteParams: true,
  description: 'Return the minimum among parameters such as numbers, fields, properties, variables, formulas etc',
 
  exec: (...numbers) => Math.min(...numbers),
 
  params: [
    { name: 'param1', description: 'The first param to compare' },
    { name: 'param2', description: 'The second param to compare' },
    { name: 'paramN', description: 'The Nth param to compare' },
  ],
 
  examples: [
    {
      desc: 'Returns 3',
      formula: 'MIN(8, 3)' as AmaliaFormula,
      result: 3,
    },
    {
      desc: 'Returns 0',
      formula: 'MIN(10, 2, 0, 5, 623)' as AmaliaFormula,
      result: 0,
    },
    {
      desc: 'Returns the minimum between Commission and On Target Commission. This will cap the Commission.',
      formula: 'MIN(statement.onTargetCommission, statement.commission)',
    },
    {
      desc: 'Returns the oldest date between Close Date and Payment Date.',
      formula: 'MIN(opportunity.closeDate, statementPeriod.paymentDate)',
    },
  ],
});