|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +// Dependency: This script requires Nodejs. |
| 4 | +// Install Node: https://nodejs.org/en/download/ |
| 5 | + |
| 6 | +// Required parameters: |
| 7 | +// @raycast.schemaVersion 1 |
| 8 | +// @raycast.title Markdown Table |
| 9 | +// @raycast.packageName Conversions |
| 10 | +// @raycast.mode silent |
| 11 | + |
| 12 | +// Optional parameters: |
| 13 | +// @raycast.icon 🧱 |
| 14 | +// @raycast.argument1 { "type": "text", "placeholder": "Columns" } |
| 15 | +// @raycast.argument2 { "type": "text", "placeholder": "Rows" } |
| 16 | + |
| 17 | +// Documentation: |
| 18 | +// @raycast.description Create a markdown table template |
| 19 | +// @raycast.author Ryan Nystrom |
| 20 | +// @raycast.authorURL https://github.com/rnystrom |
| 21 | + |
| 22 | +const child_process = require("child_process"); |
| 23 | + |
| 24 | +function pbcopy(data) { |
| 25 | + return new Promise(function (resolve, reject) { |
| 26 | + const child = child_process.spawn("pbcopy"); |
| 27 | + |
| 28 | + child.on("error", function (err) { |
| 29 | + reject(err); |
| 30 | + }); |
| 31 | + |
| 32 | + child.on("close", function (err) { |
| 33 | + resolve(data); |
| 34 | + }); |
| 35 | + |
| 36 | + child.stdin.write(data); |
| 37 | + child.stdin.end(); |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +let [columns, rows] = process.argv.slice(2); |
| 42 | +columns = Math.max(parseInt(columns), 1); |
| 43 | +rows = Math.max(parseInt(rows), 1); |
| 44 | + |
| 45 | +let emptyTemplate = " "; |
| 46 | +let headerTemplate = "---"; |
| 47 | +let rowArr = Array(columns + 1).fill("|"); |
| 48 | + |
| 49 | +let lines = []; |
| 50 | + |
| 51 | +// header |
| 52 | +lines.push(rowArr.join(emptyTemplate)); |
| 53 | +// header spacer |---| |
| 54 | +lines.push(rowArr.join(headerTemplate)); |
| 55 | + |
| 56 | +// rows |
| 57 | +for (let i = 0; i < rows; i++) { |
| 58 | + lines.push(rowArr.join(emptyTemplate)); |
| 59 | +} |
| 60 | + |
| 61 | +pbcopy(lines.join("\n")); |
0 commit comments