spooder 5.1.1 → 5.1.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.
Files changed (3) hide show
  1. package/README.md +21 -4
  2. package/package.json +1 -1
  3. package/src/api.ts +4 -5
package/README.md CHANGED
@@ -474,8 +474,8 @@ In addition to the information provided by the developer, `spooder` also include
474
474
 
475
475
  ```ts
476
476
  // logging
477
- log(message: string);
478
- log_error(message: string);
477
+ log(message: string, ...params: any[]);
478
+ log_error(message: string, ...params: any[]);
479
479
  log_create_logger(prefix: string, color: ColorInput);
480
480
  log_list(input: any[], delimiter = ', ');
481
481
 
@@ -595,7 +595,7 @@ HTTP_STATUS_CODE: { OK_200: 200, NotFound_404: 404, ... };
595
595
  <a id="api-logging"></a>
596
596
  ## API > Logging
597
597
 
598
- ### 🔧 `log(message: string)`
598
+ ### 🔧 `log(message: string, ...params: any[])`
599
599
  Print a message to the console using the default logger. Wrapping text segments in curly braces will highlight those segments with colour.
600
600
 
601
601
  ```ts
@@ -603,7 +603,24 @@ log('Hello, {world}!');
603
603
  // > [info] Hello, world!
604
604
  ```
605
605
 
606
- ### 🔧 `log_error(message: string)`
606
+ Formatting parameters are supported using standard console logging formatters.
607
+
608
+ ```ts
609
+ log('My object: %o', { foo: 'bar' });
610
+ // > [info] My object: { foo: 'bar' }
611
+ ```
612
+
613
+ | Specifier | Description |
614
+ |-----------|-------------|
615
+ | `%s` | String |
616
+ | `%d` | Integer |
617
+ | `%i` | Integer (same as %d) |
618
+ | `%f` | Floating point |
619
+ | `%o` | Object (pretty-printed) |
620
+ | `%O` | Object (expanded/detailed) |
621
+ | `%j` | JSON string |
622
+
623
+ ### 🔧 `log_error(message: string, ...params: any[])`
607
624
  Print an error message to the console. Wrapping text segments in curly braces will highlight those segments. This works the same as `log()` except it's red, so you know it's bad.
608
625
 
609
626
  ```ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spooder",
3
3
  "type": "module",
4
- "version": "5.1.1",
4
+ "version": "5.1.3",
5
5
  "module": "./src/api.ts",
6
6
  "bin": {
7
7
  "spooder": "./src/cli.ts"
package/src/api.ts CHANGED
@@ -106,8 +106,8 @@ export function log_create_logger(label: string, color: ColorInput = 'blue') {
106
106
  const ansi = Bun.color(color, 'ansi-256') ?? '\x1b[38;5;6m';
107
107
  const prefix = `[${ansi}${label}\x1b[0m] `;
108
108
 
109
- return (message: string) => {
110
- process.stdout.write(prefix + message.replace(/\{([^}]+)\}/g, `${ansi}$1\x1b[0m`) + '\n');
109
+ return (message: string, ...params: any[]) => {
110
+ console.log(prefix + message.replace(/\{([^}]+)\}/g, `${ansi}$1\x1b[0m`), ...params);
111
111
  };
112
112
  }
113
113
 
@@ -366,7 +366,7 @@ async function handle_error(prefix: string, err_message_or_obj: string | object,
366
366
  if (process.env.SPOODER_ENV === 'dev') {
367
367
  log_spooder(`[{dev}] dispatch_report ${prefix + error_message}`);
368
368
  log_spooder('[{dev}] without {--dev}, this would raise a canary report');
369
- log_spooder(`[{dev}] ${final_err}`);
369
+ log_spooder('[{dev}] %O', final_err);
370
370
  } else {
371
371
  await dispatch_report(prefix + error_message, final_err);
372
372
  }
@@ -1589,8 +1589,7 @@ export function http_serve(port: number, hostname?: string) {
1589
1589
  if (stat.isDirectory())
1590
1590
  return 401; // Unauthorized
1591
1591
 
1592
- const ext = path.extname(file_path);
1593
- if (static_options.sub_ext?.includes(ext)) {
1592
+ if (static_options.sub_ext?.some(ext => file_path.endsWith(ext))) {
1594
1593
  const content = await parse_template(await file.text(), global_sub_table, true);
1595
1594
  return new Response(content, {
1596
1595
  headers: {