项目作者: stscoundrel

项目描述 :
Print arrays with commas and conjunctions for human consumption
高级语言: JavaScript
项目地址: git://github.com/stscoundrel/teljari.git
创建时间: 2020-09-13T10:44:56Z
项目社区:https://github.com/stscoundrel/teljari

开源协议:MIT License

下载


Teljari

Print arrays with commas and conjunctions for human consumption

Array.join(',') might bring you far when printing contents for humans. Yet you often want the last entry not be preceded by comma, but by the word ‘and’ or maybe ‘or’. Teljari does this for you.

Install

yarn add teljari

Usage

  1. const { joinWithConj } = require('teljari');
  2. const languages = ['Finnish', 'Swedish', 'Norwegian', 'Danish']
  3. const withAnd = joinWithConj(languages, 'and')
  4. const withOr = joinWithConj(languages, 'or')
  5. const withOrWorse = joinWithConj(languages, 'or worse,' )
  6. console.log(withAnd) // Finnish, Swedish, Norwegian and Danish
  7. console.log(withOr) // Finnish, Swedish, Norwegian or Danish
  8. console.log(withOrWorse) // Finnish, Swedish, Norwegian or worse, Danish

What’s in the name?

“Teljari” comes from Old Norse verb for “telja” (to count, tell). It has same origins as English verb “tell”. Verb + ari structure, which makes it a noun, “someone who tells”. Teljari tells what’s in your array as a human would want to hear it.