Versions Compared

Key

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

...

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('add', function (value1: number, value2: number): number {
    return value1 + value2;
});

and

This function returns whether or not all passed arguments resolve to true:

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

attribute

This function renders an attribute or attribute value if the given condition resolves to true:

Code Block
languagetypescript
Hawksearch.handlebars.registerHelper('attribute', function (attribute: string, condition: any): string {
    return condition ? attribute : '';
});

concat

This function combines multiple values into a single string:

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
});

eq

This function returns whether two values are equivalent:

...

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 which would always resolve to truefunction
});

subtract

This function returns the difference of two values:

...