npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@plesk-tools/tablemark

v2.0.1

Published

Generate markdown tables from JSON data.

Downloads

3

Readme

tablemark

Generate markdown tables from JSON data.

Parses arrays of objects into markdown tables, complete with configuration for renaming columns and left, center, or right-aligning them.

This is a patched version of citycide/tablemark library which can be used in NX/React/ReduxToolkit/TypeScript stack.

installation

yarn add @plesk-tools/tablemark

usage

const tablemark = require('tablemark')
tablemark([
  { name: 'Bob', age: 21, isCool: false },
  { name: 'Sarah', age: 22, isCool: true },
  { name: 'Lee', age: 23, isCool: true }
])

// | Name  | Age   | Is cool |
// | ----- | ----- | ------- |
// | Bob   | 21    | false   |
// | Sarah | 22    | true    |
// | Lee   | 23    | true    |

... displays as:

| Name | Age | Is cool | | ----- | ----- | ------- | | Bob | 21 | false | | Sarah | 22 | true | | Lee | 23 | true |

api

tablemark(input[, options = {}])

Arguments

  • {Array<Object>} input: the data to table-ify
  • {Object} [options = {}]

| key | type | default | description | | :------------: | :----------: | :--------: | ---------------------------------------------- | | columns | <Array> | - | Array of column descriptors. | | caseHeaders | <Boolean> | true | Sentence case headers derived from keys. | | stringify | <Function> | - | Provide a custom "toString" function. | | wrap.width | <Number> | Infinity | Wrap texts at this length. | | wrap.gutters | <Boolean> | false | Add sides (\| <content> \|) to wrapped rows. |

The columns array can either contain objects, in which case their name and align properties will be used to alter the display of the column in the table, or any other type which will be coerced to a string if necessary and used as a replacement for the column name.

columns

tablemark([
  { name: 'Bob', age: 21, isCool: false },
  { name: 'Sarah', age: 22, isCool: true },
  { name: 'Lee', age: 23, isCool: true }
], {
  columns: [
    'first name',
    { name: 'how old', align: 'center' },
    'are they cool'
  ]
})

// | first name | how old | are they cool |
// | ---------- | :-----: | ------------- |
// | Bob        |   21    | false         |
// | Sarah      |   22    | true          |
// | Lee        |   23    | true          |

... displays as:

| first name | how old | are they cool | | ---------- | :-----: | ------------- | | Bob | 21 | false | | Sarah | 22 | true | | Lee | 23 | true |

stringify

tablemark([
  { name: 'Bob', pet_owner: true, studying: false },
  { name: 'Sarah', pet_owner: false, studying: true },
  { name: 'Sarah', pet_owner: true, studying: true }
], {
  stringify,
  columns: [
    { align: 'left' },
    { align: 'center' },
    { align: 'center' }
  ]
})

function stringify (v) {
  if (v === true) return '✔'
  if (!v) return ''
  return v
}

// | Name  | Pet owner | Studying |
// | :---- | :-------: | :------: |
// | Bob   |     ✔︎     |          |
// | Sarah |           |    ✔     |
// | Lee   |     ✔     |    ✔     |

wrap

To output valid GitHub Flavored Markdown a cell must not contain newlines. Consider replacing those with <br /> (e.g. using the stringify option).

Set the wrap.width option to wrap any content at that length onto a new adjacent line:

tablemark([
  { star: false, name: 'Benjamin' },
  { star: true, name: 'Jet Li' }
], { wrap: { width: 5 } })

// | Star  | Name  |
// | ----- | ----- |
// | false | Benja |
//           min
// | true  | Jet   |
//           Li

Enable wrap.gutters to add pipes on all lines:

tablemark([
  { star: false, name: 'Benjamin' },
  { star: true, name: 'Jet Li' }
], { wrap: { width: 5, gutters: true } })

// | Star  | Name  |
// | ----- | ----- |
// | false | Benja |
// |       | min   |
// | true  | Jet   |
// |       | Li    |

see also

contributing

Search the issues if you come across any trouble, open a new one if it hasn't been posted, or, if you're able, open a pull request. Contributions of any kind are welcome in this project.

The following people have already contributed their time and effort:

Thank you!

license

MIT © Bo Lingen / citycide