UNPKG

md-html-to-pdf

Version:

CLI tool for converting Markdown files or Html files to PDF.

37 lines (36 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setProcessAndTermTitle = exports.getMarginObject = exports.getDir = void 0; const path_1 = require("path"); /** * Get the directory that a file is in. */ const getDir = (filePath) => (0, path_1.resolve)((0, path_1.parse)(filePath).dir); exports.getDir = getDir; /** * Get a margin object from a CSS-like margin string. */ const getMarginObject = (margin) => { if (typeof margin !== 'string') { throw new TypeError(`margin needs to be a string.`); } const [top, right, bottom, left, ...remaining] = margin.split(' '); if (remaining.length > 0) { throw new Error(`invalid margin input "${margin}": can have max 4 values.`); } return left ? { top, right, bottom, left } : bottom ? { top, right, bottom, left: right } : right ? { top, right, bottom: top, left: right } : top ? { top, right: top, bottom: top, left: top } : undefined; }; exports.getMarginObject = getMarginObject; const setProcessAndTermTitle = (title) => { process.title = title; process.stdout.write(`${String.fromCharCode(27)}]0;${title}${String.fromCharCode(7)}`); }; exports.setProcessAndTermTitle = setProcessAndTermTitle;