Created
February 23, 2022 14:03
-
-
Save tinovyatkin/29482f9316c57e3393e6c7c314b3ba5d to your computer and use it in GitHub Desktop.
list format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function namesList(names: string | readonly string[]): string { | |
if (typeof names === 'string') return names; | |
if (names instanceof Array) return names.join(', '); | |
throw new TypeError( | |
`Invalid parameter, expected a string or array of strings, received: ${names}`, | |
); | |
} | |
const nameList2 = (names: string | Iterable<string>) => | |
typeof names === 'string' | |
? names | |
: new Intl.ListFormat('en-GB', { type: 'unit' }).format(names); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment