Skip to content

Commit 30cbedb

Browse files
committed
Format a list with Intl.ListFormat
1 parent d378d7b commit 30cbedb

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/VariableDecoder/keyOf.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import * as RE from 'fp-ts/ReaderEither';
44
import { ask, validate, VariableDecoder } from './VariableDecoder';
55

66
const oneOf = (xs: string[]): string =>
7-
xs
8-
.slice(0, -1)
9-
.map((x) => `'${x}'`)
10-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11-
.join(', ') + `, or '${xs[xs.length - 1]!}'`;
7+
new Intl.ListFormat('en', {
8+
type: 'disjunction',
9+
}).format(xs.map((x) => `'${x}'`));
1210

1311
/**
1412
* Decodes a string that is a key of the given object.

0 commit comments

Comments
 (0)