UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

14 lines (13 loc) 596 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.joinEnglish = joinEnglish; const assert_js_1 = require("./assert.js"); // https://stackoverflow.com/questions/53879088/join-an-array-by-commas-and-and/53879103#53879103 function joinEnglish(arr, conjunction, colorizer = (s) => s) { (0, assert_js_1.assert)(arr.length > 0); if (arr.length === 1) return colorizer(arr[0]); const firsts = arr.slice(0, arr.length - 1); const last = arr[arr.length - 1]; return firsts.map(colorizer).join(', ') + `, ${conjunction} ` + colorizer(last); }