* Create a list string in the form like 'A and B' or 'A, B, ..., and Z'. * We cannot use Intl.ListFormat because it's not available in * --without-intl builds. * @param {string[]} array An array of strings. * @param {string} [type] The list type to be inserted before the last element. * @return
(array, type = 'and')
| 1064 | * @returns {string} |
| 1065 | */ |
| 1066 | function formatList(array, type = 'and') { |
| 1067 | switch (array.length) { |
| 1068 | case 0: return ''; |
| 1069 | case 1: return `${array[0]}`; |
| 1070 | case 2: return `${array[0]} ${type} ${array[1]}`; |
| 1071 | case 3: return `${array[0]}, ${array[1]}, ${type} ${array[2]}`; |
| 1072 | default: |
| 1073 | return `${ArrayPrototypeJoin(ArrayPrototypeSlice(array, 0, -1), ', ')}, ${type} ${array[array.length - 1]}`; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | module.exports = { |
| 1078 | AbortError, |
no outgoing calls
no test coverage detected
searching dependent graphs…