rsformat 0.2.0 → 0.2.1

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 CHANGED
@@ -5,3 +5,14 @@
5
5
  * @param params Parameters to be inserted into the format string
6
6
  */
7
7
  export declare function format(str: string, ...params: any[]): string;
8
+ /**
9
+ * Raw formatting behaviour function called by `format` and printing functions.
10
+ *
11
+ * @param str String used for formatting
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
15
+ */
16
+ export declare function fmt_raw(str: string, params: any[], options?: {
17
+ colors: boolean;
18
+ }): string;
package/lib/format.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.format = void 0;
3
+ exports.fmt_raw = exports.format = void 0;
4
4
  const node_util_1 = require("node:util");
5
5
  /**
6
6
  * Regex to match for possible formatting insertion points.
@@ -27,6 +27,18 @@ const FORMAT_REGEX = (/\{{2}|\}{2}|\{(\d*?)(?::(?:(.?)(\^|>|<))?(\+)?(#)?(0)?(\d
27
27
  * @param params Parameters to be inserted into the format string
28
28
  */
29
29
  function format(str, ...params) {
30
+ return fmt_raw(str, params);
31
+ }
32
+ exports.format = format;
33
+ /**
34
+ * Raw formatting behaviour function called by `format` and printing functions.
35
+ *
36
+ * @param str String used for formatting
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
40
+ */
41
+ function fmt_raw(str, params, options = { colors: false }) {
30
42
  // Counter used for insertion of unnumbered values
31
43
  let param_counter = 0;
32
44
  str = str.replace(FORMAT_REGEX, ($, $param_number, $fill_character, $align_direction, $sign, $pretty, $pad_zeroes, $width, $precision, $type) => {
@@ -94,7 +106,7 @@ function format(str, ...params) {
94
106
  case "?":
95
107
  param = (0, node_util_1.inspect)(param, {
96
108
  depth: Infinity,
97
- colors: true,
109
+ colors: options.colors,
98
110
  compact: $pretty !== '#'
99
111
  });
100
112
  break;
@@ -184,4 +196,4 @@ function format(str, ...params) {
184
196
  });
185
197
  return str;
186
198
  }
187
- exports.format = format;
199
+ exports.fmt_raw = fmt_raw;
package/lib/print.js CHANGED
@@ -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.format)(format_string, ...params));
19
+ outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }));
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.format)(format_string, ...params) + "\n");
29
+ outStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }) + '\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.format)(format_string, ...params));
38
+ errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }));
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.format)(format_string, ...params) + "\n");
48
+ errStream.write((0, format_1.fmt_raw)(format_string, params, { colors: true }) + '\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.0",
3
+ "version": "0.2.1",
4
4
  "description": "Formatting/printing library for JavaScript that takes after rust's string formatting ",
5
5
  "files": [
6
6
  "lib",
@@ -28,11 +28,13 @@
28
28
  "println",
29
29
  "printf",
30
30
  "console",
31
- "log"
31
+ "log",
32
+ "console.log"
32
33
  ],
33
34
  "author": "Alfio (https://github.com/p2js)",
34
35
  "license": "ISC",
35
36
  "devDependencies": {
36
37
  "@types/node": "^22.8.6"
37
- }
38
+ },
39
+ "packageManager": "pnpm@9.14.2+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387"
38
40
  }