nichtich/wikidata-taxonomy

serializeTaxonomy txt error

kevincfz opened this issue · 3 comments

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.

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?

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.

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