Skip to content

Commit

Permalink
Format a list with Intl.ListFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-ka committed Jun 24, 2022
1 parent d378d7b commit 30cbedb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/VariableDecoder/keyOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import * as RE from 'fp-ts/ReaderEither';
import { ask, validate, VariableDecoder } from './VariableDecoder';

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

/**
* Decodes a string that is a key of the given object.
Expand Down

0 comments on commit 30cbedb

Please sign in to comment.