@darthcav/ts-utils 0.8.7 → 0.8.8

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
@@ -1,9 +1,12 @@
1
1
  # @darthcav/ts-utils
2
2
 
3
- [![Node][node-version]][node-url] ![Version][version-image] ![CI][ci-badge] [![Coverage][coverage-badge]][coverage-url]
3
+ [![Node][node-version]][node-url] ![Version][version-image] ![CI][ci-badge]
4
+ [![Coverage][coverage-badge]][coverage-url]
4
5
 
5
6
  A collection of utility functions for TypeScript applications and modules.
6
7
 
8
+ ## Documentation
9
+
7
10
  [API Documentation][pages-url]
8
11
 
9
12
  ## Features
@@ -25,8 +28,9 @@ npm install @darthcav/ts-utils
25
28
 
26
29
  ### `getConsoleLogger`
27
30
 
28
- Configures logging and returns a `Logger` for the given category name. Records at or above `lowestLevel` are written to
29
- the console using an ANSI color formatter with RFC 3339 timestamps. The internal `logtape/meta` logger is silenced.
31
+ Configures logging and returns a `Logger` for the given category name. Records at or above
32
+ `lowestLevel` are written to the console using an ANSI color formatter with RFC 3339 timestamps. The
33
+ internal `logtape/meta` logger is silenced.
30
34
 
31
35
  ```ts
32
36
  import { getConsoleLogger, main } from "@darthcav/ts-utils"
@@ -47,8 +51,8 @@ const logger = await getConsoleLogger("my-app", "debug")
47
51
 
48
52
  ### `monitorMemory`
49
53
 
50
- Starts a periodic interval that logs process uptime and memory usage (in bytes). The interval defaults to every 24
51
- hours.
54
+ Starts a periodic interval that logs process uptime and memory usage (in bytes). The interval
55
+ defaults to every 24 hours.
52
56
 
53
57
  ```ts
54
58
  import { getConsoleLogger, main, monitorMemory } from "@darthcav/ts-utils"
@@ -63,9 +67,10 @@ main("my-app", logger, () => {
63
67
 
64
68
  ### `millisecondsToString`
65
69
 
66
- Converts a duration in milliseconds to a human-readable string via `Intl.DurationFormat`. Sub-second values are rounded
67
- to the nearest second, and any zero-valued components are omitted — so a zero-millisecond input returns an empty string.
68
- An optional BCP 47 locale tag (default `"en"`) controls the unit labels.
70
+ Converts a duration in milliseconds to a human-readable string via `Intl.DurationFormat`. Sub-second
71
+ values are rounded to the nearest second, and any zero-valued components are omitted — so a
72
+ zero-millisecond input returns an empty string. An optional BCP 47 locale tag (default `"en"`)
73
+ controls the unit labels.
69
74
 
70
75
  ```ts
71
76
  import { millisecondsToString } from "@darthcav/ts-utils"
@@ -78,7 +83,8 @@ millisecondsToString(90_061_000, "es") // "1d 1h 1min 1s"
78
83
 
79
84
  ### `noop`
80
85
 
81
- A no-op function that does nothing and returns `void`. Useful as a placeholder callback or default handler.
86
+ A no-op function that does nothing and returns `void`. Useful as a placeholder callback or default
87
+ handler.
82
88
 
83
89
  ```ts
84
90
  import { noop } from "@darthcav/ts-utils"
@@ -89,8 +95,8 @@ element.addEventListener("click", noop)
89
95
 
90
96
  ### `RuntimeObject`
91
97
 
92
- Represents an object whose keys and values are only known at runtime. It is defined as `Record<string, unknown>` so
93
- values must be narrowed before use.
98
+ Represents an object whose keys and values are only known at runtime. It is defined as
99
+ `Record<string, unknown>` so values must be narrowed before use.
94
100
 
95
101
  ```ts
96
102
  import type { RuntimeObject } from "@darthcav/ts-utils"
@@ -103,8 +109,8 @@ const payload: RuntimeObject = {
103
109
 
104
110
  ### `getDummyLogger`
105
111
 
106
- Returns a no-op `Logger` useful as a placeholder in tests. All logging methods are no-ops and `isEnabledFor` always
107
- returns `false`. `getChild` and `with` return the same dummy logger instance.
112
+ Returns a no-op `Logger` useful as a placeholder in tests. All logging methods are no-ops and
113
+ `isEnabledFor` always returns `false`. `getChild` and `with` return the same dummy logger instance.
108
114
 
109
115
  ```ts
110
116
  import { getDummyLogger } from "@darthcav/ts-utils"
@@ -115,13 +121,15 @@ const logger = getDummyLogger()
115
121
 
116
122
  ### `main`
117
123
 
118
- Bootstraps an application process: logs startup information, optionally registers handlers for `SIGINT` and `SIGTERM`
119
- (controlled by `defaultInterruptionHandler`, defaults to `true`), always registers handlers for `uncaughtException` and
120
- `unhandledRejection`, then delegates to an optional launcher function.
124
+ Bootstraps an application process: logs startup information, optionally registers handlers for
125
+ `SIGINT` and `SIGTERM` (controlled by `defaultInterruptionHandler`, defaults to `true`), always
126
+ registers handlers for `uncaughtException` and `unhandledRejection`, then delegates to an optional
127
+ launcher function.
121
128
 
122
- The three optional parameters — `launcher` (function), `monitorMemoryHours` (number, defaults to `0`), and
123
- `defaultInterruptionHandler` (boolean, defaults to `true`) — have distinct types. Any subset can be passed in order and
124
- the function resolves each by type, so middle parameters can be omitted:
129
+ The three optional parameters — `launcher` (function), `monitorMemoryHours` (number, defaults to
130
+ `0`), and `defaultInterruptionHandler` (boolean, defaults to `true`) — have distinct types. Any
131
+ subset can be passed in order and the function resolves each by type, so middle parameters can be
132
+ omitted:
125
133
 
126
134
  ```ts
127
135
  import { getLogger } from "@logtape/logtape"
@@ -183,8 +191,9 @@ public/ # Documentation output (generated)
183
191
 
184
192
  [node-version]: https://img.shields.io/badge/node-%3E%3D25-orange.svg?style=flat-square
185
193
  [node-url]: https://nodejs.org
186
- [version-image]: https://img.shields.io/badge/version-0.8.7-blue.svg?style=flat-square
194
+ [version-image]: https://img.shields.io/badge/version-0.8.8-blue.svg?style=flat-square
187
195
  [ci-badge]: https://github.com/darthcav/ts-utils/actions/workflows/tests.yml/badge.svg
188
- [coverage-badge]: https://codecov.io/github/darthcav/ts-utils/branch/dev/graph/badge.svg?token=RNEPER4KEI
196
+ [coverage-badge]:
197
+ https://codecov.io/github/darthcav/ts-utils/branch/dev/graph/badge.svg?token=RNEPER4KEI
189
198
  [coverage-url]: https://codecov.io/github/darthcav/ts-utils
190
199
  [pages-url]: https://darthcav.github.io/ts-utils/
@@ -4,20 +4,18 @@
4
4
  * Common keys include `ID`, `NAME`, `VERSION_ID`, and `PRETTY_NAME`.
5
5
  * See {@link https://www.freedesktop.org/software/systemd/man/os-release.html | os-release(5)} for the full spec.
6
6
  */
7
- export interface LinuxRelease {
8
- [key: string]: string;
9
- }
7
+ export type LinuxRelease = Record<string, string>;
10
8
  /**
11
9
  * Basic information about the current Windows environment.
12
10
  */
13
- export interface WindowsRelease {
11
+ export type WindowsRelease = {
14
12
  /** Human-readable Windows version name, e.g. `"Windows 11"`. */
15
13
  name: string;
16
14
  /** NT kernel version string as returned by `os.release()`, e.g. `"10.0.22000"`. */
17
15
  version: string;
18
16
  /** Processor architecture as returned by `os.arch()`, e.g. `"x64"`. */
19
17
  arch: string;
20
- }
18
+ };
21
19
  /**
22
20
  * Returns parsed key-value pairs from `/etc/os-release` on Linux, or `null` on other platforms
23
21
  * or when the file is absent.
@@ -1 +1 @@
1
- {"version":3,"file":"os-utils.d.ts","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAA;IACZ,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;CACf;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,IAAI,YAAY,GAAG,IAAI,CAkBlD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,IAAI,cAAc,GAAG,IAAI,CAyCtD"}
1
+ {"version":3,"file":"os-utils.d.ts","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEjD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAA;IACZ,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;CACf,CAAA;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,IAAI,YAAY,GAAG,IAAI,CAiBlD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,IAAI,cAAc,GAAG,IAAI,CAyCtD"}
package/dist/os-utils.js CHANGED
@@ -24,11 +24,10 @@ export function linuxRelease() {
24
24
  continue;
25
25
  }
26
26
  const key = line.substring(0, eq).trim();
27
- const value = line
27
+ result[key] = line
28
28
  .substring(eq + 1)
29
29
  .trim()
30
30
  .replace(/^"|"$/g, "");
31
- result[key] = value;
32
31
  }
33
32
  return result;
34
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"os-utils.js","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAwB9D,MAAM,UAAU,GAAG,iBAAiB,CAAA;AAEpC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY;IACxB,IAAI,QAAQ,EAAE,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,OAAO,IAAI,CAAA;IACf,CAAC;IACD,MAAM,MAAM,GAAiB,EAAE,CAAA;IAC/B,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/D,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC5B,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;YACZ,SAAQ;QACZ,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;QACxC,MAAM,KAAK,GAAG,IAAI;aACb,SAAS,CAAC,EAAE,GAAG,CAA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O,EAAE,CAAC;QACzB,OAAO,IAAI,CAAA;IACf,CAAC;IACD,MAAM,OAAO,GAAG,SAAS,EAAE,CAAA;IAC3B,MAAM,CAAC,KAAK,EAAE,AAAD,EAAG,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACvD,IAAI,IAAI,GAAG,UAAU,CAAA;IACrB,IAAI,KAAK,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC;QACxC,IAAI,IAAI,IAAI,CAAA;IAChB,CAAC;SAAM,CAAC;QACJ,QAAQ,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAC9B,KAAK,KAAK;gBACN,IAAI,IAAI,IAAI,CAAA;gBACZ,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,KAAK,CAAA;gBACb,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,GAAG,CAAA;gBACX,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,GAAG,CAAA;gBACX,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,OAAO,CAAA;gBACf,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,mBAAmB,CAAA;gBAC3B,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,IAAI,CAAA;gBACZ,MAAK;YACT,KAAK,KAAK;gBACN,IAAI,IAAI,MAAM,CAAA;gBACd,MAAK;YACT;gBACI,IAAI,IAAI,iBAAiB,CAAA;gBACzB,MAAK;QACb,CAAC;IACL,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;AAC1C,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@darthcav/ts-utils",
3
3
  "description": "A collection of utility functions for TypeScript applications and modules",
4
- "version": "0.8.7",
4
+ "version": "0.8.8",
5
5
  "author": {
6
6
  "name": "darthcav",
7
7
  "url": "https://github.com/darthcav"
package/src/os-utils.ts CHANGED
@@ -7,14 +7,12 @@ import { arch, release as osRelease, platform } from "node:os"
7
7
  * Common keys include `ID`, `NAME`, `VERSION_ID`, and `PRETTY_NAME`.
8
8
  * See {@link https://www.freedesktop.org/software/systemd/man/os-release.html | os-release(5)} for the full spec.
9
9
  */
10
- export interface LinuxRelease {
11
- [key: string]: string
12
- }
10
+ export type LinuxRelease = Record<string, string>
13
11
 
14
12
  /**
15
13
  * Basic information about the current Windows environment.
16
14
  */
17
- export interface WindowsRelease {
15
+ export type WindowsRelease = {
18
16
  /** Human-readable Windows version name, e.g. `"Windows 11"`. */
19
17
  name: string
20
18
  /** NT kernel version string as returned by `os.release()`, e.g. `"10.0.22000"`. */
@@ -48,11 +46,10 @@ export function linuxRelease(): LinuxRelease | null {
48
46
  continue
49
47
  }
50
48
  const key = line.substring(0, eq).trim()
51
- const value = line
49
+ result[key] = line
52
50
  .substring(eq + 1)
53
51
  .trim()
54
52
  .replace(/^"|"$/g, "")
55
- result[key] = value
56
53
  }
57
54
  return result
58
55
  }