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

markdown-table-columns-shifter

v1.0.0

Published

The library to changing the order and remove of the markdown-style columns

Downloads

3

Readme

Markdown Table Columns Shifter

GPL-3.0 license Build Status

This repository contains a script for manipulating the order of markdown-style table columns. You can shift, remove, or duplicate columns.

Install

npm install markdown-table-columns-shifter --save

Supported Tables

The function works on any table data set represented as text, where each column is separated by the | character.

| Country       | Capital City | Population (millions) | Area (km²)   |
|---------------|--------------|-----------------------|--------------|
| Canada        | Ottawa       | 38                    | 9,984,670    |
| Germany       | Berlin       | 83                    | 357,386      |
| Japan         | Tokyo        | 126                   | 377,975      |
| Australia     | Canberra     | 25                    | 7,692,024    |
| Brazil        | Brasília     | 213                   | 8,515,767    |

These are used in Markdown or Gerkin as parameters for the Scenario Outline.

The table can have an indent (a common feature in Gherkin scripts).

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |    12 |   5 |    7 |
    |    20 |   5 |   15 |

Works correctly for both filled tables as well as compressed ones (no filling spaces added for readability).

|Country|Capital City|Population (millions)|Area (km²)|
|---|---|---|---|
|Canada|Ottawa|38|9,984,670|
|Germany|Berlin|83|357,386|

Main Functionality

The markdownTableColumnsShift function which accept the layout of the new columns, and the table to convert. It returns the new table as a string value.

Import the function:

import { markdownTableColumnsShift } from "markdown-table-columns-shifter";

Column Layout

The first parameter for markdownTableColumnsShift is an array of numbers representing the intended layout of the columns. Each number represents the index of the original layout (which is: [0, 1, 2, 3, 4 ...]).

It is counted from 1. The number 0 represents the table indent, even if table doesn't have it (it is treated as empty string).

Column index:  0     1      2     3
Table body:        | abc  | def | ghi |
                   | bcd  | efg | hij |

Examples

More examples can be found in the source code of the package.

Shift column

markdownTableColumnsShift([1, 3, 4, 2], originalTable))

The result:

| Country       | Population (millions) | Area (km²)   | Capital City |
|---------------|-----------------------|--------------|--------------|
| Canada        | 38                    | 9,984,670    | Ottawa       |
| Germany       | 83                    | 357,386      | Berlin       |
| Japan         | 126                   | 377,975      | Tokyo        |
| Australia     | 25                    | 7,692,024    | Canberra     |
| Brazil        | 213                   | 8,515,767    | Brasília     |

Column Duplication

markdownTableColumnsShift([1, 2, 2, 3, 4], originalTable))

The result:

| Country       | Capital City | Capital City | Population (millions) | Area (km²)   |
|---------------|--------------|--------------|-----------------------|--------------|
| Canada        | Ottawa       | Ottawa       | 38                    | 9,984,670    |
| Germany       | Berlin       | Berlin       | 83                    | 357,386      |
| Japan         | Tokyo        | Tokyo        | 126                   | 377,975      |
| Australia     | Canberra     | Canberra     | 25                    | 7,692,024    |
| Brazil        | Brasília     | Brasília     | 213                   | 8,515,767    |

Remove Column

markdownTableColumnsShift([1, 2, 4], originalTable))

The result:

| Country       | Capital City | Area (km²)   |
|---------------|--------------|--------------|
| Canada        | Ottawa       | 9,984,670    |
| Germany       | Berlin       | 357,386      |
| Japan         | Tokyo        | 377,975      |
| Australia     | Canberra     | 7,692,024    |
| Brazil        | Brasília     | 8,515,767    |