rsnext/packages/next/lib/oxford-comma-list.ts
Joe Haddad a7ae54d7cc
refactor(typescript): extract preflight functions (#13510)
This pull request refactors our TypeScript preflight check in preparation for dropping the `fork-ts-checker-webpack-plugin` plugin.

This will make reviewing the subsequent PR much easier.

---

There is no behavior change, so the existing test should cover this adequately.
2020-05-28 23:39:46 +00:00

14 lines
306 B
TypeScript

export function getOxfordCommaList(items: string[]): string {
return items
.map(
(v, index, { length }) =>
(index > 0
? index === length - 1
? length > 2
? ', and '
: ' and '
: ', '
: '') + v
)
.join('')
}