nichtich / wikidata-taxonomy

command-line tool to extract taxonomies from Wikidata
https://www.npmjs.org/package/wikidata-taxonomy
MIT License
125 stars 11 forks source link

serializeTaxonomy txt error #42

Open kevincfz opened 6 years ago

kevincfz commented 6 years ago

serializeTaxonomy.txt(taxonomy, process.stdout, { colors: true });

has error

TypeError: Cannot read property 'delimiter' of undefined

I believe the error traces to (wikidata-taxonomy/lib/serialize-txt.js:24:25) where it is looking for env.chalk but none is specified.

nichtich commented 6 years ago

Yes, this is wrongly documented. The serializeTaxonomy.txt expects no colors option but option chalk:

options = { chalk: require('chalk') }
serializeTaxonomy.txt(taxonomy, process.stdout, options)

I'm not happy with this but unsure how to provide better. Coloring depends on the output format, e.g. for HTML and CSS classes I use:

var col = (c) => (
        (s) => '<span class="'+c+'">'+escapeHTML(s)+'</span>'
      )
      options = {
        chalk: {
          delimiter: col('text-secondary'),
          green: col('text-success'),
          white: col('text-white'),
          cyan: col('text-info'),
          yellow: col('text-warning'),
          red: col('text-danger'),
        }
      }
serializeTaxonomy.txt(taxonomy, process.stdout, options)

What are the use cases?

kevincfz commented 6 years ago

My use case was to display the txt result/command line output on a web view, because I think the it is nice enough and do not want to parse json again.

kevincfz commented 6 years ago

I can satisfy my use case by learning how you are processing this in the web app example. Feel free to resolve this issue.