rsformat 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/format.d.ts +1 -2
- package/lib/format.js +13 -13
- package/lib/print.d.ts +39 -1
- package/lib/print.js +40 -2
- package/package.json +1 -1
package/lib/format.d.ts
CHANGED
|
@@ -10,8 +10,7 @@ export declare function format(str: string, ...params: any[]): string;
|
|
|
10
10
|
*
|
|
11
11
|
* @param str String used for formatting
|
|
12
12
|
* @param params Parameters to be inserted into the format string
|
|
13
|
-
* @param options Options passed into formatting
|
|
14
|
-
* @param options.colors Whether to use colors in debug formatting
|
|
13
|
+
* @param options Options passed into formatting (Whether to use colors in debug formatting - false by default)
|
|
15
14
|
*/
|
|
16
15
|
export declare function fmt_raw(str: string, params: any[], options?: {
|
|
17
16
|
colors: boolean;
|
package/lib/format.js
CHANGED
|
@@ -35,8 +35,7 @@ exports.format = format;
|
|
|
35
35
|
*
|
|
36
36
|
* @param str String used for formatting
|
|
37
37
|
* @param params Parameters to be inserted into the format string
|
|
38
|
-
* @param options Options passed into formatting
|
|
39
|
-
* @param options.colors Whether to use colors in debug formatting
|
|
38
|
+
* @param options Options passed into formatting (Whether to use colors in debug formatting - false by default)
|
|
40
39
|
*/
|
|
41
40
|
function fmt_raw(str, params, options = { colors: false }) {
|
|
42
41
|
// Counter used for insertion of unnumbered values
|
|
@@ -105,8 +104,9 @@ function fmt_raw(str, params, options = { colors: false }) {
|
|
|
105
104
|
}
|
|
106
105
|
break;
|
|
107
106
|
case '?':
|
|
108
|
-
// Do not force sign or align to precision when using
|
|
107
|
+
// Do not force sign, pad with zeroes or align to precision when using debug formatting
|
|
109
108
|
$sign = undefined;
|
|
109
|
+
$pad_zeroes = undefined;
|
|
110
110
|
$precision = undefined;
|
|
111
111
|
true_length = (0, node_util_1.inspect)(param, {
|
|
112
112
|
depth: Infinity,
|
|
@@ -130,18 +130,16 @@ function fmt_raw(str, params, options = { colors: false }) {
|
|
|
130
130
|
// Compute radix-point precision on numbers
|
|
131
131
|
if (param_type == 'number' && $precision) {
|
|
132
132
|
let [pre, post] = param.split('.');
|
|
133
|
-
if (post === undefined) {
|
|
134
|
-
post = '';
|
|
135
|
-
}
|
|
136
133
|
let precision = +$precision.substring(1, $precision.length);
|
|
137
|
-
if (
|
|
138
|
-
|
|
134
|
+
if (!precision) { // precision = 0, do not include radix point
|
|
135
|
+
param = pre;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
post = ((post || '') + '0'.repeat(precision)).slice(0, precision);
|
|
139
|
+
param = pre + '.' + post;
|
|
140
|
+
// Update true length for fill/align
|
|
141
|
+
true_length = param.length;
|
|
139
142
|
}
|
|
140
|
-
else
|
|
141
|
-
while (post.length < precision) {
|
|
142
|
-
post = post + '0';
|
|
143
|
-
}
|
|
144
|
-
param = pre + '.' + post;
|
|
145
143
|
}
|
|
146
144
|
let width;
|
|
147
145
|
if ($width === undefined) {
|
|
@@ -185,8 +183,10 @@ function fmt_raw(str, params, options = { colors: false }) {
|
|
|
185
183
|
filled = true;
|
|
186
184
|
while (param.length < width - maybe_sign.length) {
|
|
187
185
|
param = '0' + param;
|
|
186
|
+
true_length++;
|
|
188
187
|
}
|
|
189
188
|
}
|
|
189
|
+
true_length += maybe_sign.length;
|
|
190
190
|
param = maybe_sign + param;
|
|
191
191
|
}
|
|
192
192
|
if (!filled && width > true_length) {
|
package/lib/print.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Writable } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Create format printer functions with custom output/error streams.
|
|
5
|
+
*
|
|
6
|
+
* @param outStream Output stream (used by print and println - process.stdout by default)
|
|
7
|
+
* @param errStream Error stream (used by eprint and eprintln - process.stderr by default)
|
|
8
|
+
* @param options Options for the printer functions (Whether to color the debug formatting in the output - true by default)
|
|
9
|
+
*
|
|
10
|
+
* @returns an object with print, println, eprint and eprintln functions that print to the specified streams
|
|
11
|
+
*/
|
|
3
12
|
export declare function Printer(outStream?: Writable, errStream?: Writable, options?: {
|
|
4
13
|
debugColors: boolean;
|
|
5
14
|
}): {
|
|
@@ -34,4 +43,33 @@ export declare function Printer(outStream?: Writable, errStream?: Writable, opti
|
|
|
34
43
|
*/
|
|
35
44
|
eprintln: (format_string: string, ...params: any[]) => void;
|
|
36
45
|
};
|
|
37
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Print a format string to process.stdout.
|
|
48
|
+
*
|
|
49
|
+
* @param format_string String used for formatting
|
|
50
|
+
* @param params Parameters to be inserted into the format string
|
|
51
|
+
*/
|
|
52
|
+
export declare const print: (format_string: string, ...params: any[]) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Print a format string to process.stdout
|
|
55
|
+
* and append a newline.
|
|
56
|
+
*
|
|
57
|
+
* @param format_string String used for formatting
|
|
58
|
+
* @param params Parameters to be inserted into the format string
|
|
59
|
+
*/
|
|
60
|
+
export declare const println: (format_string: string, ...params: any[]) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Print a format string to process.stderr.
|
|
63
|
+
*
|
|
64
|
+
* @param format_string String used for formatting
|
|
65
|
+
* @param params Parameters to be inserted into the format string
|
|
66
|
+
*/
|
|
67
|
+
export declare const eprint: (format_string: string, ...params: any[]) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Print a format string to process.stderr
|
|
70
|
+
* and append a newline.
|
|
71
|
+
*
|
|
72
|
+
* @param format_string String used for formatting
|
|
73
|
+
* @param params Parameters to be inserted into the format string
|
|
74
|
+
*/
|
|
75
|
+
export declare const eprintln: (format_string: string, ...params: any[]) => void;
|
package/lib/print.js
CHANGED
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
var _a;
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
exports.eprintln = exports.eprint = exports.println = exports.print = exports.Printer = void 0;
|
|
8
7
|
const node_process_1 = __importDefault(require("node:process"));
|
|
9
8
|
const format_1 = require("./format");
|
|
9
|
+
/**
|
|
10
|
+
* Create format printer functions with custom output/error streams.
|
|
11
|
+
*
|
|
12
|
+
* @param outStream Output stream (used by print and println - process.stdout by default)
|
|
13
|
+
* @param errStream Error stream (used by eprint and eprintln - process.stderr by default)
|
|
14
|
+
* @param options Options for the printer functions (Whether to color the debug formatting in the output - true by default)
|
|
15
|
+
*
|
|
16
|
+
* @returns an object with print, println, eprint and eprintln functions that print to the specified streams
|
|
17
|
+
*/
|
|
10
18
|
function Printer(outStream = node_process_1.default.stdout, errStream = node_process_1.default.stderr, options = { debugColors: true }) {
|
|
11
19
|
return {
|
|
12
20
|
/**
|
|
@@ -50,4 +58,34 @@ function Printer(outStream = node_process_1.default.stdout, errStream = node_pro
|
|
|
50
58
|
};
|
|
51
59
|
}
|
|
52
60
|
exports.Printer = Printer;
|
|
53
|
-
|
|
61
|
+
const default_printer = Printer();
|
|
62
|
+
/**
|
|
63
|
+
* Print a format string to process.stdout.
|
|
64
|
+
*
|
|
65
|
+
* @param format_string String used for formatting
|
|
66
|
+
* @param params Parameters to be inserted into the format string
|
|
67
|
+
*/
|
|
68
|
+
exports.print = default_printer.print;
|
|
69
|
+
/**
|
|
70
|
+
* Print a format string to process.stdout
|
|
71
|
+
* and append a newline.
|
|
72
|
+
*
|
|
73
|
+
* @param format_string String used for formatting
|
|
74
|
+
* @param params Parameters to be inserted into the format string
|
|
75
|
+
*/
|
|
76
|
+
exports.println = default_printer.println;
|
|
77
|
+
/**
|
|
78
|
+
* Print a format string to process.stderr.
|
|
79
|
+
*
|
|
80
|
+
* @param format_string String used for formatting
|
|
81
|
+
* @param params Parameters to be inserted into the format string
|
|
82
|
+
*/
|
|
83
|
+
exports.eprint = default_printer.eprint;
|
|
84
|
+
/**
|
|
85
|
+
* Print a format string to process.stderr
|
|
86
|
+
* and append a newline.
|
|
87
|
+
*
|
|
88
|
+
* @param format_string String used for formatting
|
|
89
|
+
* @param params Parameters to be inserted into the format string
|
|
90
|
+
*/
|
|
91
|
+
exports.eprintln = default_printer.eprintln;
|