rsformat
Version:
Formatting/printing library for JavaScript that takes after rust's string formatting
54 lines (53 loc) • 2.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.eprintln = exports.eprint = exports.println = exports.print = exports.Printer = void 0;
const node_process_1 = __importDefault(require("node:process"));
const format_1 = require("./format");
function Printer(outStream = node_process_1.default.stdout, errStream = node_process_1.default.stderr, options = { debugColors: true }) {
return {
/**
* Print a format string to an output stream (usually process.stdout).
*
* @param format_string String used for formatting
* @param params Parameters to be inserted into the format string
*/
print: function print(format_string, ...params) {
outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }));
},
/**
* Print a format string to an output stream (usually process.stdout)
* and append a newline.
*
* @param format_string String used for formatting
* @param params Parameters to be inserted into the format string
*/
println: function println(format_string, ...params) {
outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }) + '\n');
},
/**
* Print a format string to an error stream (usually process.stderr).
*
* @param format_string String used for formatting
* @param params Parameters to be inserted into the format string
*/
eprint: function eprint(format_string, ...params) {
errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }));
},
/**
* Print a format string to an error stream (usually process.stderr)
* and append a newline.
*
* @param format_string String used for formatting
* @param params Parameters to be inserted into the format string
*/
eprintln: function eprintln(format_string, ...params) {
errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }) + '\n');
},
};
}
exports.Printer = Printer;
_a = Printer(), exports.print = _a.print, exports.println = _a.println, exports.eprint = _a.eprint, exports.eprintln = _a.eprintln;