vivth 1.1.0 → 1.1.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/README.md CHANGED
@@ -68,12 +68,12 @@ npm i vivth
68
68
  - [TsToMjs](#tstomjs)
69
69
  - [WriteFileSafe](#writefilesafe)
70
70
  - [AnyButUndefined](#anybutundefined)
71
- - [ExtnameType](#extnametype)
72
- - [IsListSignal](#islistsignal)
73
- - [ListArg](#listarg)
74
- - [MutationType](#mutationtype)
75
- - [QCBFIFOReturn](#qcbfiforeturn)
76
71
  - [QCBReturn](#qcbreturn)
72
+ - [QCBFIFOReturn](#qcbfiforeturn)
73
+ - [MutationType](#mutationtype)
74
+ - [ListArg](#listarg)
75
+ - [IsListSignal](#islistsignal)
76
+ - [ExtnameType](#extnametype)
77
77
 
78
78
  <h2 id="compilemjs">CompileMJS</h2>
79
79
 
@@ -1031,7 +1031,7 @@ npm i vivth
1031
1031
 
1032
1032
  ```js
1033
1033
  /**
1034
- * @template {[string, ...string[]]} ExitEventNames
1034
+ * @template {[string, ...string[]]} eventNames
1035
1035
  */
1036
1036
  ```
1037
1037
 
@@ -1050,8 +1050,8 @@ npm i vivth
1050
1050
  ```js
1051
1051
  /**
1052
1052
  * @param {Object} options
1053
- * @param {ExitEventNames} options.exitEventNames
1054
- * @param {()=>void} options.exitCallback
1053
+ * @param {eventNames} options.eventNames
1054
+ * @param {()=>void} options.terminator
1055
1055
  * - standard node/bun:
1056
1056
  * ```js
1057
1057
  * () => process.exit(0),
@@ -1060,7 +1060,7 @@ npm i vivth
1060
1060
  * ```js
1061
1061
  * () => Deno.exit(0),
1062
1062
  * ```
1063
- * @param {(eventName:string)=>void} [options.exitCallbackListeners]
1063
+ * @param {(eventName:string)=>void} [options.listener]
1064
1064
  * - default value
1065
1065
  * ```js
1066
1066
  * (eventName) => {
@@ -1078,12 +1078,12 @@ npm i vivth
1078
1078
  import { SafeExit, Console } from 'vivth';
1079
1079
 
1080
1080
  new SafeExit({
1081
- // exitEventNames are blank by default, you need to manually name them all;
1081
+ // eventNames are blank by default, you need to manually name them all;
1082
1082
  // 'exit' will be omited, as it might cause async callbacks failed to execute;
1083
- exitEventNames: ['SIGINT', 'SIGTERM', ...otherExitEventNames],
1084
- exitCallback = () => process.exit(0), // OR on deno () => Deno.exit(0),
1083
+ eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
1084
+ terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
1085
1085
  // optional deno example
1086
- exitCallbackListeners = (eventName) => {
1086
+ listener = (eventName) => {
1087
1087
  const sig = Deno.signal(eventName);
1088
1088
  for await (const _ of sig) {
1089
1089
  exiting.correction(true);
@@ -2134,76 +2134,76 @@ npm i vivth
2134
2134
  ```
2135
2135
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2136
2136
 
2137
- <h2 id="extnametype">ExtnameType</h2>
2137
+ <h2 id="qcbreturn">QCBReturn</h2>
2138
2138
 
2139
2139
  - jsdoc types:
2140
2140
 
2141
2141
  ```js
2142
2142
  /**
2143
- * - jsRuntime extention naming convention;
2144
- * @typedef {`.${string}`} ExtnameType
2143
+ * - return type of Q callback;
2144
+ * @typedef {{resume:()=>void, isLastOnQ:boolean}} QCBReturn
2145
2145
  */
2146
2146
  ```
2147
2147
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2148
2148
 
2149
- <h2 id="islistsignal">IsListSignal</h2>
2149
+ <h2 id="qcbfiforeturn">QCBFIFOReturn</h2>
2150
2150
 
2151
2151
  - jsdoc types:
2152
2152
 
2153
2153
  ```js
2154
2154
  /**
2155
- * - `EnvSignal.get` argument whether signal need to be a list or not;
2156
- * @typedef {boolean} IsListSignal
2155
+ * - return type of Q callback fifo;
2156
+ * @typedef {Omit<import("./src/types/QCBReturn.mjs").QCBReturn, "isLastOnQ">} QCBFIFOReturn
2157
2157
  */
2158
2158
  ```
2159
2159
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2160
2160
 
2161
- <h2 id="listarg">ListArg</h2>
2161
+ <h2 id="mutationtype">MutationType</h2>
2162
2162
 
2163
2163
  - jsdoc types:
2164
2164
 
2165
2165
  ```js
2166
2166
  /**
2167
- * - ListSignal argument type;
2168
- * @typedef {Record<string, string>} ListArg
2167
+ * - `ListSignal` mutation type;
2168
+ * @typedef {'push'|'unshift'|'splice'|'swap'|'modify'|'shift'|'remove'} MutationType
2169
+ * - instance method: serves as helper to mutate, and notify for `effects`;
2170
+ * > - `slice` uses `splice` in the background, you don't need to manually reindex when using it;
2169
2171
  */
2170
2172
  ```
2171
2173
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2172
2174
 
2173
- <h2 id="mutationtype">MutationType</h2>
2175
+ <h2 id="listarg">ListArg</h2>
2174
2176
 
2175
2177
  - jsdoc types:
2176
2178
 
2177
2179
  ```js
2178
2180
  /**
2179
- * - `ListSignal` mutation type;
2180
- * @typedef {'push'|'unshift'|'splice'|'swap'|'modify'|'shift'|'remove'} MutationType
2181
- * - instance method: serves as helper to mutate, and notify for `effects`;
2182
- * > - `slice` uses `splice` in the background, you don't need to manually reindex when using it;
2181
+ * - ListSignal argument type;
2182
+ * @typedef {Record<string, string>} ListArg
2183
2183
  */
2184
2184
  ```
2185
2185
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2186
2186
 
2187
- <h2 id="qcbfiforeturn">QCBFIFOReturn</h2>
2187
+ <h2 id="islistsignal">IsListSignal</h2>
2188
2188
 
2189
2189
  - jsdoc types:
2190
2190
 
2191
2191
  ```js
2192
2192
  /**
2193
- * - return type of Q callback fifo;
2194
- * @typedef {Omit<import("./src/types/QCBReturn.mjs").QCBReturn, "isLastOnQ">} QCBFIFOReturn
2193
+ * - `EnvSignal.get` argument whether signal need to be a list or not;
2194
+ * @typedef {boolean} IsListSignal
2195
2195
  */
2196
2196
  ```
2197
2197
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2198
2198
 
2199
- <h2 id="qcbreturn">QCBReturn</h2>
2199
+ <h2 id="extnametype">ExtnameType</h2>
2200
2200
 
2201
2201
  - jsdoc types:
2202
2202
 
2203
2203
  ```js
2204
2204
  /**
2205
- * - return type of Q callback;
2206
- * @typedef {{resume:()=>void, isLastOnQ:boolean}} QCBReturn
2205
+ * - jsRuntime extention naming convention;
2206
+ * @typedef {`.${string}`} ExtnameType
2207
2207
  */
2208
2208
  ```
2209
2209
  *) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
package/dev/index.mjs CHANGED
@@ -11,9 +11,9 @@ new paths({
11
11
  });
12
12
 
13
13
  new safeExit({
14
- exitEventNames: ['SIGINT', 'SIGTERM', 'exit'],
15
- exitCallback: () => process.exit(0),
16
- exitCallbackListeners: (eventName) => {
14
+ eventNames: ['SIGINT', 'SIGTERM', 'exit'],
15
+ terminator: () => process.exit(0),
16
+ listener: (eventName) => {
17
17
  process.once(eventName, function () {
18
18
  safeExit.instance.exiting.correction(true);
19
19
  Console.log(`safe exit via "${eventName}"`);
package/index.mjs CHANGED
@@ -41,20 +41,20 @@ export { WriteFileSafe } from './src/function/WriteFileSafe.mjs';
41
41
  * @typedef {import('./src/types/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
42
42
  */
43
43
  /**
44
- * @typedef {import('./src/types/ExtnameType.mjs').ExtnameType} ExtnameType
44
+ * @typedef {import('./src/types/QCBReturn.mjs').QCBReturn} QCBReturn
45
45
  */
46
46
  /**
47
- * @typedef {import('./src/types/IsListSignal.mjs').IsListSignal} IsListSignal
47
+ * @typedef {import('./src/types/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
48
48
  */
49
49
  /**
50
- * @typedef {import('./src/types/ListArg.mjs').ListArg} ListArg
50
+ * @typedef {import('./src/types/MutationType.mjs').MutationType} MutationType
51
51
  */
52
52
  /**
53
- * @typedef {import('./src/types/MutationType.mjs').MutationType} MutationType
53
+ * @typedef {import('./src/types/ListArg.mjs').ListArg} ListArg
54
54
  */
55
55
  /**
56
- * @typedef {import('./src/types/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
56
+ * @typedef {import('./src/types/IsListSignal.mjs').IsListSignal} IsListSignal
57
57
  */
58
58
  /**
59
- * @typedef {import('./src/types/QCBReturn.mjs').QCBReturn} QCBReturn
59
+ * @typedef {import('./src/types/ExtnameType.mjs').ExtnameType} ExtnameType
60
60
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "extremely simple signal as library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
@@ -15,7 +15,7 @@ export const safeCleanUpCBs = new Set();
15
15
  * @description
16
16
  * - class helper for describing how to Safely Response on exit events
17
17
  * - singleton;
18
- * @template {[string, ...string[]]} ExitEventNames
18
+ * @template {[string, ...string[]]} eventNames
19
19
  */
20
20
  export class SafeExit {
21
21
  /**
@@ -27,8 +27,8 @@ export class SafeExit {
27
27
  /**
28
28
  * @description
29
29
  * @param {Object} options
30
- * @param {ExitEventNames} options.exitEventNames
31
- * @param {()=>void} options.exitCallback
30
+ * @param {eventNames} options.eventNames
31
+ * @param {()=>void} options.terminator
32
32
  * - standard node/bun:
33
33
  * ```js
34
34
  * () => process.exit(0),
@@ -37,7 +37,7 @@ export class SafeExit {
37
37
  * ```js
38
38
  * () => Deno.exit(0),
39
39
  * ```
40
- * @param {(eventName:string)=>void} [options.exitCallbackListeners]
40
+ * @param {(eventName:string)=>void} [options.listener]
41
41
  * - default value
42
42
  * ```js
43
43
  * (eventName) => {
@@ -52,12 +52,12 @@ export class SafeExit {
52
52
  * import { SafeExit, Console } from 'vivth';
53
53
  *
54
54
  * new SafeExit({
55
- * // exitEventNames are blank by default, you need to manually name them all;
55
+ * // eventNames are blank by default, you need to manually name them all;
56
56
  * // 'exit' will be omited, as it might cause async callbacks failed to execute;
57
- * exitEventNames: ['SIGINT', 'SIGTERM', ...otherExitEventNames],
58
- * exitCallback = () => process.exit(0), // OR on deno () => Deno.exit(0),
57
+ * eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
58
+ * terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
59
59
  * // optional deno example
60
- * exitCallbackListeners = (eventName) => {
60
+ * listener = (eventName) => {
61
61
  * const sig = Deno.signal(eventName);
62
62
  * for await (const _ of sig) {
63
63
  * exiting.correction(true);
@@ -67,16 +67,16 @@ export class SafeExit {
67
67
  * }
68
68
  * });
69
69
  */
70
- constructor({ exitEventNames, exitCallback, exitCallbackListeners = undefined }) {
70
+ constructor({ eventNames, terminator, listener = undefined }) {
71
71
  if (SafeExit.instance) {
72
72
  return SafeExit.instance;
73
73
  }
74
74
  SafeExit.instance = this;
75
- this.#exit = exitCallback;
76
- if (exitCallbackListeners) {
77
- this.#exitCallbackListeners = exitCallbackListeners;
75
+ this.#exit = terminator;
76
+ if (listener) {
77
+ this.#listener = listener;
78
78
  }
79
- this.#register(exitEventNames);
79
+ this.#register(eventNames);
80
80
  }
81
81
  /**
82
82
  * @description
@@ -86,21 +86,21 @@ export class SafeExit {
86
86
  */
87
87
  exiting = new EnvSignal(false);
88
88
  /**
89
- * @param {ExitEventNames} exitEventNames
89
+ * @param {eventNames} eventNames
90
90
  * @returns {void}
91
91
  */
92
- #register = (exitEventNames) => {
93
- exitEventNames.forEach((eventName) => {
92
+ #register = (eventNames) => {
93
+ eventNames.forEach((eventName) => {
94
94
  if (eventName == 'exit') {
95
95
  return;
96
96
  }
97
- this.#exitCallbackListeners(eventName);
97
+ this.#listener(eventName);
98
98
  });
99
99
  };
100
100
  /**
101
101
  * @type {(eventName:string)=>void}
102
102
  */
103
- #exitCallbackListeners = (eventName) => {
103
+ #listener = (eventName) => {
104
104
  SafeExit.instance.exiting.env.value;
105
105
  process.once(eventName, function () {
106
106
  Console.log(`safe exit via "${eventName}"`);
package/types/index.d.mts CHANGED
@@ -30,9 +30,9 @@ export { TrySync } from "./src/function/TrySync.mjs";
30
30
  export { TsToMjs } from "./src/function/TsToMjs.mjs";
31
31
  export { WriteFileSafe } from "./src/function/WriteFileSafe.mjs";
32
32
  export type AnyButUndefined = import("./src/types/AnyButUndefined.mjs").AnyButUndefined;
33
- export type ExtnameType = import("./src/types/ExtnameType.mjs").ExtnameType;
34
- export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
35
- export type ListArg = import("./src/types/ListArg.mjs").ListArg;
36
- export type MutationType = import("./src/types/MutationType.mjs").MutationType;
37
- export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
38
33
  export type QCBReturn = import("./src/types/QCBReturn.mjs").QCBReturn;
34
+ export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
35
+ export type MutationType = import("./src/types/MutationType.mjs").MutationType;
36
+ export type ListArg = import("./src/types/ListArg.mjs").ListArg;
37
+ export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
38
+ export type ExtnameType = import("./src/types/ExtnameType.mjs").ExtnameType;
@@ -6,9 +6,9 @@ export const safeCleanUpCBs: Set<() => Promise<void>>;
6
6
  * @description
7
7
  * - class helper for describing how to Safely Response on exit events
8
8
  * - singleton;
9
- * @template {[string, ...string[]]} ExitEventNames
9
+ * @template {[string, ...string[]]} eventNames
10
10
  */
11
- export class SafeExit<ExitEventNames extends [string, ...string[]]> {
11
+ export class SafeExit<eventNames extends [string, ...string[]]> {
12
12
  /**
13
13
  * @description
14
14
  * - only accessible after instantiation;
@@ -18,8 +18,8 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
18
18
  /**
19
19
  * @description
20
20
  * @param {Object} options
21
- * @param {ExitEventNames} options.exitEventNames
22
- * @param {()=>void} options.exitCallback
21
+ * @param {eventNames} options.eventNames
22
+ * @param {()=>void} options.terminator
23
23
  * - standard node/bun:
24
24
  * ```js
25
25
  * () => process.exit(0),
@@ -28,7 +28,7 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
28
28
  * ```js
29
29
  * () => Deno.exit(0),
30
30
  * ```
31
- * @param {(eventName:string)=>void} [options.exitCallbackListeners]
31
+ * @param {(eventName:string)=>void} [options.listener]
32
32
  * - default value
33
33
  * ```js
34
34
  * (eventName) => {
@@ -43,12 +43,12 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
43
43
  * import { SafeExit, Console } from 'vivth';
44
44
  *
45
45
  * new SafeExit({
46
- * // exitEventNames are blank by default, you need to manually name them all;
46
+ * // eventNames are blank by default, you need to manually name them all;
47
47
  * // 'exit' will be omited, as it might cause async callbacks failed to execute;
48
- * exitEventNames: ['SIGINT', 'SIGTERM', ...otherExitEventNames],
49
- * exitCallback = () => process.exit(0), // OR on deno () => Deno.exit(0),
48
+ * eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
49
+ * terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
50
50
  * // optional deno example
51
- * exitCallbackListeners = (eventName) => {
51
+ * listener = (eventName) => {
52
52
  * const sig = Deno.signal(eventName);
53
53
  * for await (const _ of sig) {
54
54
  * exiting.correction(true);
@@ -58,10 +58,10 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
58
58
  * }
59
59
  * });
60
60
  */
61
- constructor({ exitEventNames, exitCallback, exitCallbackListeners }: {
62
- exitEventNames: ExitEventNames;
63
- exitCallback: () => void;
64
- exitCallbackListeners?: (eventName: string) => void;
61
+ constructor({ eventNames, terminator, listener }: {
62
+ eventNames: eventNames;
63
+ terminator: () => void;
64
+ listener?: (eventName: string) => void;
65
65
  });
66
66
  /**
67
67
  * @description