MCPcopy Index your code
hub / github.com/nodejs/node / formatList

Function formatList

lib/internal/errors.js:1066–1075  ·  view source on GitHub ↗

* 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')

Source from the content-addressed store, hash-verified

1064 * @returns {string}
1065 */
1066function 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
1077module.exports = {
1078 AbortError,

Callers 3

errors.jsFile · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…