All files / libs/amalia-lang/formula/evaluate/shared/src/functions/string/ends-with index.ts

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

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 41 42 43 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 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 { assert } from '@amalia/ext/typescript';
 
import { AmaliaFunctionDefault } from '../../AmaliaFunction';
 
export const stringEndsWith = new AmaliaFunctionDefault<[string | null | undefined, string], boolean>({
  name: AmaliaFunctionKeys.ENDS_WITH,
  category: AmaliaFunctionCategory.STRING,
 
  nbParamsRequired: 2,
  description: 'Return true when the given Source String ends with the given Search String',
 
  exec: (sourceString, searchString) => {
    assert(
      sourceString !== null && sourceString !== undefined,
      `${AmaliaFunctionKeys.ENDS_WITH}: source string is null or undefined`,
    );
 
    return sourceString.toString().endsWith(searchString);
  },
 
  params: [
    { name: 'sourceString', description: 'String to look into: array, variables, fields, properties, string' },
    { name: 'searchString', description: 'String to look for: array, variables, fields, properties, string' },
  ],
 
  examples: [
    {
      desc: 'Returns true if Opportunity type endsWith Renew.',
      formula: 'ENDS_WITH(opportunity.type, "Renew")' as AmaliaFormula,
    },
    {
      desc: 'Returns true.',
      formula: 'ENDS_WITH("Jean Dupont", "pont")' as AmaliaFormula,
      result: true,
    },
    {
      desc: 'Returns false since the check is case sensitive.',
      formula: 'ENDS_WITH("Opportunity - Renewal XYZ", "xyz")' as AmaliaFormula,
      result: false,
    },
  ],
});