1.0.1 • Published 2 years ago

markdown-grid v1.0.1

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

markdown-grid

Markdown Grid Generator

Install

npm i markdown-grid

Usage

const MG = require("markdown-grid");
const mg = MG({
    "columns": ["", "Name", "Value"],
    "rows": [
        [1, "Tom", "Value 1"],
        [2, "Jerry", "Value 2"]
    ]
});

console.log(mg);  

|   |Name|Value|
|---|----|-----|
|1  |Tom |Value 1|
|2  |Jerry|Value 2|  
NameValue
1TomValue 1
2JerryValue 2

With column width:

const MG = require("markdown-grid");
const mg = MG({
    "columns": ["", {
        "name": "Name",
        "width": 15
    }, {
        "name": "Value",
        "width": 35
    }],
    "rows": [
        [1, "Hello", "Long Text Value"],
        [2, "Hello There", "Long Text Value Long Text Value"]
    ]
});

console.log(mg);  

|   |Name           |Value                              |
|---|---------------|-----------------------------------|
|1  |Hello          |Long Text Value                    |
|2  |Hello There    |Long Text Value Long Text Value    |  
NameValue
1HelloLong Text Value
2Hello ThereLong Text Value Long Text Value

With column align and padding:

const MG = require("markdown-grid");
const mg = MG({
    "options": {
        "padding": 1
    },
    "columns": [{
        "id": "default",
        "name": "Default",
        "width": 10
    }, {
        "id": "left",
        "name": "Left",
        "width": 10,
        "align": "left"
    }, {
        "id": "center",
        "name": "Center",
        "width": 10,
        "align": "center"
    }, {
        "id": "right",
        "name": "Right",
        "width": 10,
        "align": "right"
    }],
    "rows": [{
        "default": "Cell",
        "left": "Markdown",
        "center": "Start",
        "right": "123.0"
    }, {
        "default": "Content",
        "left": "Grid",
        "center": "Complete",
        "right": "8.1"
    }]
});

console.log(mg);  

| Default    | Left       |   Center   |      Right |
| ---------- | :--------- | :--------: | ---------: |
| Cell       | Markdown   |    Start   |      123.0 |
| Content    | Grid       |  Complete  |        8.1 |  
DefaultLeftCenterRight
CellMarkdownStart123.0
ContentGridComplete8.1

With special character:

const MG = require("markdown-grid");
const mg = MG({
    "columns": [{
        "name": "Name",
        "width": 15
    }, {
        "name": "Character",
        "align": "center"
    }],
    "rows": [
        ["Backtick", "`"],
        ["Pipe", "|"],
        ["Escaped Pipes", "\\||\\|"],
        ["中文", "✅"]
    ]
});

console.log(mg);  

|Name           |Character|
|---------------|:-------:|
|Backtick       |    `    |
|Pipe           |    \|   |
|Escaped Pipes  |  \|\|\| |
|中文           |    ✅   |  
NameCharacter
Backtick`
Pipe|
Escaped Pipes|||
中文

With links, images, Codes and formatting:

const MG = require("markdown-grid");
const mg = MG({
    "columns": ["Name", "Version", "Install", "Description"],
    "rows": [
        ["[markdown-grid](https://github.com/cenfun/markdown-grid)", "![npm](https://badgen.net/npm/v/markdown-grid)", "`npm i markdown-grid`", "Generating a **Markdown** *Grid*"],
        ["[console-grid](https://github.com/cenfun/console-grid)", "![npm](https://badgen.net/npm/v/console-grid)", "`npm i console-grid`", "Log a *Grid* in **Console**"]
    ]
});

console.log(mg);  

|Name|Version|Install|Description|
|----|-------|-------|-----------|
|[markdown-grid](https://github.com/cenfun/markdown-grid)|![npm](https://badgen.net/npm/v/markdown-grid)|`npm i markdown-grid`|Generating a **Markdown** *Grid*|
|[console-grid](https://github.com/cenfun/console-grid)|![npm](https://badgen.net/npm/v/console-grid)|`npm i console-grid`|Log a *Grid* in **Console**|  
NameVersionInstallDescription
markdown-gridnpmnpm i markdown-gridGenerating a Markdown Grid
console-gridnpmnpm i console-gridLog a Grid in Console