UNPKG

@serenity-js/core

Version:

The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure

29 lines 925 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.commaSeparated = commaSeparated; /** * Produces a comma-separated list based on the list provided. * * @param list * @param mappingFunction * @param [acc=''] * * @returns {string} */ function commaSeparated(list, mappingFunction = item => `${item}`.trim(), acc = '') { switch (list.length) { case 0: return acc; case 1: return commaSeparated(tail(list), mappingFunction, `${acc}${mappingFunction(head(list))}`); case 2: return commaSeparated(tail(list), mappingFunction, `${acc}${mappingFunction(head(list))} and `); default: return commaSeparated(tail(list), mappingFunction, `${acc}${mappingFunction(head(list))}, `); } } /** @package */ function head(list) { return list[0]; } /** @package */ function tail(list) { return list.slice(1); } //# sourceMappingURL=commaSeparated.js.map