Skip to content

Instantly share code, notes, and snippets.

@jkasaudhan
Created May 26, 2019 12:42
Show Gist options
  • Save jkasaudhan/2be3fecf9696a88d1cfff7872dffadc3 to your computer and use it in GitHub Desktop.
Save jkasaudhan/2be3fecf9696a88d1cfff7872dffadc3 to your computer and use it in GitHub Desktop.
Internationalization ListFormat api
// English version
const formatter = new Intl.ListFormat('en');
formatter.format(['january', 'february', 'march'])
// january, february, and march
const formatterConj = new Intl.ListFormat('en', {type: 'conjunction'});
// january, february, and march => by defaut type is 'conjunction'
const formatterDisj = new Intl.ListFormat('en', {type: 'disjunction'});
formatterDisj.format(['january', 'february', 'march'])
formatterConj.format(['january', 'february', 'march'])
// january, february, or march
// For german version
const formatterde = new Intl.ListFormat('de');
formatterde.format(['january', 'february', 'march'])
// january, february und march
const formatterConjDe = new Intl.ListFormat('de', {type: 'conjunction'});
formatterConjDe.format(['january', 'february', 'march'])
// january, february und march => by defaut type is 'conjunction'
const formatterDisjDe = new Intl.ListFormat('de', {type: 'disjunction'});
formatterDisjDe.format(['january', 'february', 'march'])
// january, february oder march
// It can be applied to any supported character for Eg. chinese characters
const lf = new Intl.ListFormat('zh');
lf.format(['永鋒', '新宇', '芳遠']);
// 永鋒、新宇和芳遠
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment