UNPKG

@graphql-tools/executor

Version:

Fork of GraphQL.js' execute function

32 lines (31 loc) 741 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.orList = orList; exports.andList = andList; /** * Given [A, B, C] return 'A, B, or C'. * * @internal */ function orList(items) { return formatList('or', items); } /** * Given [A, B, C] return 'A, B, and C'. * * @internal */ function andList(items) { return formatList('and', items); } function formatList(conjunction, items) { switch (items.length) { case 1: return items[0]; case 2: return items[0] + ' ' + conjunction + ' ' + items[1]; } const allButLast = items.slice(0, -1); const lastItem = items.at(-1); return allButLast.join(', ') + ', ' + conjunction + ' ' + lastItem; }