Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('concat', function (...values: Array<any>): string {
    if (values.length < 2) {
        return '';
    }

    return values.slice(0, -1).join(''); // Omit last argument as that is the Handlebars options function
});

currency

This function formats a value as currency:

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('currency', (value: number | Array<number> | undefined, decimals: number, defaultValue?: number): string | undefined => {
    if (typeof defaultValue === 'object') {
        defaultValue = undefined;
    }

    if (value instanceof Array) {
        value = value[0];
    }

    return formatCurrency(value ?? defaultValue ?? 0, decimals);
});

eq

This function returns whether two values are equivalent:

...

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('gte', function (value1: any, value2: any): boolean {
    return value1 >= value2;
});

number

This function formats a number:

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('number', (value: number | Array<number> | undefined, decimals: number, defaultValue?: number): string | undefined => {
    if (typeof defaultValue === 'object') {
        defaultValue = undefined;
    }

    if (value instanceof Array) {
        value = value[0];
    }

    return formatNumber(value ?? defaultValue ?? 0, decimals);
});

or

This function returns whether either provided value resolves to true:

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('or', function (...values: Array<any>): boolean {
    return values.slice(0, -1).some((v) => !!v); // Omit last argument as that is the Handlebars options function
});

string

This function displays a specified string with an optional default value:

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('string', (value: string | Array<string> | undefined, defaultValue?: string): string | undefined => {
    if (typeof defaultValue === 'object') {
        defaultValue = undefined;
    }

    if (value instanceof Array) {
        value = value[0];
    }

    return value ?? defaultValue;
});
Info

This is most likely to be used in the context of the Search Results Item Component.

subtract

This function returns the difference of two values:

...