rsformat 0.2.2 → 0.2.3

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/README.md CHANGED
@@ -90,7 +90,7 @@ format('{:.>7}', [1,2]); // '....1,2'
90
90
 
91
91
  #### Pretty Printing
92
92
 
93
- In some instances (namely debug and hexadecimal formatting), adding a `#` before the format specifier will use an alternative 'pretty' printing style. This amounts to using non-compact `util.inspect` for debug printing (spanning multiple lines), and adding 0x to hexadecimal numbers.
93
+ In some instances (namely debug, binary, octal and hexadecimal formatting), adding a `#` before the format specifier will use an alternative 'pretty' printing style. This amounts to using non-compact `util.inspect` for debug printing (spanning multiple lines), and adding 0b/0o/0x as a prefix for the numbers formatted as powers of two.
94
94
 
95
95
  ```js
96
96
  format('{:#X}', 255); // '0xFF'
package/lib/format.js CHANGED
@@ -165,9 +165,20 @@ function fmt_raw(str, params, options = { colors: false }) {
165
165
  else {
166
166
  maybe_sign = '';
167
167
  }
168
- //If the type is x or X and pretty printing enabled, add 0x
169
- if ((($type === 'x') || ($type === 'X')) && ($pretty === '#')) {
170
- maybe_sign += '0x';
168
+ // If pretty printing is enabled and the formating calls for a prefix, add it
169
+ if ($pretty === '#') {
170
+ switch ($type) {
171
+ case 'o':
172
+ maybe_sign += "0o";
173
+ break;
174
+ case 'x':
175
+ case 'X':
176
+ maybe_sign += "0x";
177
+ break;
178
+ case 'b':
179
+ maybe_sign += "0b";
180
+ break;
181
+ }
171
182
  }
172
183
  //pad with zeroes if specified
173
184
  if ($pad_zeroes === '0') {
package/lib/print.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { Writable } from 'node:stream';
3
- export declare function Printer(outStream?: Writable, errStream?: Writable): {
3
+ export declare function Printer(outStream?: Writable, errStream?: Writable, options?: {
4
+ debugColors: boolean;
5
+ }): {
4
6
  /**
5
7
  * Print a format string to an output stream (usually process.stdout).
6
8
  *
package/lib/print.js CHANGED
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.eprintln = exports.eprint = exports.println = exports.print = exports.Printer = void 0;
8
8
  const node_process_1 = __importDefault(require("node:process"));
9
9
  const format_1 = require("./format");
10
- function Printer(outStream = node_process_1.default.stdout, errStream = node_process_1.default.stderr) {
10
+ function Printer(outStream = node_process_1.default.stdout, errStream = node_process_1.default.stderr, options = { debugColors: true }) {
11
11
  return {
12
12
  /**
13
13
  * Print a format string to an output stream (usually process.stdout).
@@ -16,7 +16,7 @@ function Printer(outStream = node_process_1.default.stdout, errStream = node_pro
16
16
  * @param params Parameters to be inserted into the format string
17
17
  */
18
18
  print: function print(format_string, ...params) {
19
- outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }));
19
+ outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }));
20
20
  },
21
21
  /**
22
22
  * Print a format string to an output stream (usually process.stdout)
@@ -26,7 +26,7 @@ function Printer(outStream = node_process_1.default.stdout, errStream = node_pro
26
26
  * @param params Parameters to be inserted into the format string
27
27
  */
28
28
  println: function println(format_string, ...params) {
29
- outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }) + '\n');
29
+ outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }) + '\n');
30
30
  },
31
31
  /**
32
32
  * Print a format string to an error stream (usually process.stderr).
@@ -35,7 +35,7 @@ function Printer(outStream = node_process_1.default.stdout, errStream = node_pro
35
35
  * @param params Parameters to be inserted into the format string
36
36
  */
37
37
  eprint: function eprint(format_string, ...params) {
38
- errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }));
38
+ errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }));
39
39
  },
40
40
  /**
41
41
  * Print a format string to an error stream (usually process.stderr)
@@ -45,7 +45,7 @@ function Printer(outStream = node_process_1.default.stdout, errStream = node_pro
45
45
  * @param params Parameters to be inserted into the format string
46
46
  */
47
47
  eprintln: function eprintln(format_string, ...params) {
48
- errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }) + '\n');
48
+ errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: options.debugColors }) + '\n');
49
49
  },
50
50
  };
51
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsformat",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Formatting/printing library for JavaScript that takes after rust's string formatting ",
5
5
  "files": [
6
6
  "lib",