@ayapapa-npm/contracts-js 0.3.0 → 0.4.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
@@ -1,4 +1,10 @@
1
1
  [![CI](https://github.com/ayapapa/contracts-js/actions/workflows/ci.yml/badge.svg)](https://github.com/ayapapa/contracts-js/actions/workflows/ci.yml)
2
+ ![Coverage](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-total.svg)
3
+ ![Branches](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-branches.svg)
4
+ ![Functions](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-functions.svg)
5
+ ![Lines](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-lines.svg)
6
+ ![Statements](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-statements.svg)
7
+
2
8
  # contracts-js
3
9
  A lightweight Design by Contract library for JavaScript.</br>
4
10
  Provides runtime contract checks based on Design by Contract principles.</br>
@@ -126,6 +132,9 @@ Contracts.INVARIANT(
126
132
  );
127
133
  ```
128
134
 
135
+ ## API Reference
136
+ [API document](docs/api.md)
137
+
129
138
  ## Usage
130
139
 
131
140
  ```javascript
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -32,30 +33,39 @@ var Contracts = class _Contracts {
32
33
  /** Debug mode state */
33
34
  static DEBUG_MODE = false;
34
35
  /** default configuration */
35
- static defaultConf = {
36
+ static #defaultConf = {
36
37
  debug: false,
37
38
  logger: console
38
39
  };
40
+ /** Current config. */
41
+ static #config = { ..._Contracts.#defaultConf };
39
42
  /** logger */
40
- static logger = console;
43
+ //private static logger: LogProvider = console;
41
44
  /**
42
45
  * Configures contract checking behavior.
43
46
  *
44
47
  * @param config
45
- * Configuration options.
46
- *
47
- * The `debug` property enables or disables
48
- * debug-only contract checks.
49
- *
48
+ * Configuration options. <br>
49
+ * <br>
50
+ * The `debug` property toggles the behavior—specifically,
51
+ * throwing an exception or outputting to the console when the condition is
52
+ * false—for the validation of contracts intended for use during debugging (methods ending in `_DEBUG`). <br>
53
+ * <br>
50
54
  * When `debug` is `true`,
51
- * methods ending with `_DEBUG` perform validation.
52
- *
53
- * When `debug` is `false` or omitted,
54
- * methods ending with `_DEBUG` skip validation.
55
- *
55
+ * methods ending with `_DEBUG` perform validation. <br>
56
+ * <br>
57
+ * When `debug` is `false`,
58
+ * methods ending with `_DEBUG` skip validation. <br>
59
+ * <br>
56
60
  * Is the `logger` property is specified,
57
61
  * it is used instead of the standard logger, `console`.
58
- * This module uses only the `error` method of the `logger`.
62
+ * This module uses only the `error` method of the `logger`. <br>
63
+ * <br>
64
+ * Note: If the value of a property is `undefined`, it is treated as unspecified.
65
+ *
66
+ * @param reset
67
+ * If `true`, unspecified values ​​are saved to the settings as default values. <br>
68
+ * If `false`, unspecified values ​​remain at their current settings.
59
69
  *
60
70
  * @example
61
71
  * // Use a logger that is slightly more advanced than the standard logger—namely, `console`.
@@ -65,9 +75,36 @@ var Contracts = class _Contracts {
65
75
  * Contracts.setConfig({ debug: true, logger: prettyConsole });
66
76
  * // Node: ` The `logger` property is optional.
67
77
  */
68
- static setConfig(config) {
69
- _Contracts.DEBUG_MODE = Boolean(config?.debug);
70
- _Contracts.logger = config?.logger ?? console;
78
+ static setConfig(config, reset = true) {
79
+ const rConf = { ...config };
80
+ for (let key of Object.keys(rConf)) {
81
+ if (rConf[key] == null) delete rConf[key];
82
+ }
83
+ if (reset) _Contracts.#config = { ..._Contracts.getDefaultConfig() };
84
+ Object.assign(_Contracts.#config, rConf);
85
+ _Contracts.DEBUG_MODE = _Contracts.#config.debug;
86
+ }
87
+ /**
88
+ * Get the default configurations.
89
+ * @returns Default configurations.
90
+ */
91
+ static getDefaultConfig() {
92
+ return { ..._Contracts.#defaultConf };
93
+ }
94
+ /**
95
+ * Get the current configurations.
96
+ * @returns Default configurations.
97
+ */
98
+ static getConfig() {
99
+ _Contracts.#config.debug = _Contracts.DEBUG_MODE;
100
+ return { ..._Contracts.#config };
101
+ }
102
+ /**
103
+ * Reset the current configurations to the default configurations.
104
+ * @returns Default configurations.
105
+ */
106
+ static resetConfig() {
107
+ _Contracts.setConfig({}, true);
71
108
  }
72
109
  /**
73
110
  * Verifies an intermediate condition during execution.
@@ -87,7 +124,7 @@ var Contracts = class _Contracts {
87
124
  * - Check temporary assumptions during execution.
88
125
  *
89
126
  * @param isOk
90
- * Condition result to verify.
127
+ * Condition result(`boolean`) to be verified.
91
128
  *
92
129
  * @param ngMsg
93
130
  * Failure message.
@@ -144,7 +181,7 @@ var Contracts = class _Contracts {
144
181
  * - Check internal assumptions while debugging.
145
182
  *
146
183
  * @param isOk
147
- * Condition result to verify.
184
+ * Condition result(`boolean`) to be verified.
148
185
  *
149
186
  * @param ngMsg
150
187
  * Failure message.
@@ -199,7 +236,7 @@ var Contracts = class _Contracts {
199
236
  * - Check required external conditions.
200
237
  *
201
238
  * @param isOk
202
- * Condition result to verify.
239
+ * Condition result(`boolean`) to be verified.
203
240
  *
204
241
  * @param ngMsg
205
242
  * Failure message.
@@ -263,7 +300,7 @@ var Contracts = class _Contracts {
263
300
  * - Perform additional argument checks while debugging.
264
301
  *
265
302
  * @param isOk
266
- * Condition result to verify.
303
+ * Condition result(`boolean`) to be verified.
267
304
  *
268
305
  * @param ngMsg
269
306
  * Failure message.
@@ -319,7 +356,7 @@ var Contracts = class _Contracts {
319
356
  * - Verify that processing completed correctly.
320
357
  *
321
358
  * @param isOk
322
- * Condition result to verify.
359
+ * Condition result(`boolean`) to be verified.
323
360
  *
324
361
  * @param ngMsg
325
362
  * Failure message.
@@ -385,7 +422,7 @@ var Contracts = class _Contracts {
385
422
  * - Confirm internal behavior while debugging.
386
423
  *
387
424
  * @param isOk
388
- * Condition result to verify.
425
+ * Condition result(`boolean`) to be verified.
389
426
  *
390
427
  * @param ngMsg
391
428
  * Failure message.
@@ -441,7 +478,7 @@ var Contracts = class _Contracts {
441
478
  * INVARIANT represents conditions that must always remain true.
442
479
  *
443
480
  * @param isOk
444
- * Condition result to verify.
481
+ * Condition result(`boolean`) to be verified.
445
482
  *
446
483
  * @param ngMsg
447
484
  * Failure message.
@@ -504,7 +541,7 @@ var Contracts = class _Contracts {
504
541
  * - Detect unexpected state changes while debugging.
505
542
  *
506
543
  * @param isOk
507
- * Condition result to verify.
544
+ * Condition result(`boolean`) to be verified.
508
545
  *
509
546
  * @param [ngMsg]
510
547
  * Failure message.
@@ -562,7 +599,7 @@ var Contracts = class _Contracts {
562
599
  * @internal
563
600
  *
564
601
  * @param isOk
565
- * Condition result.
602
+ * Condition result(`boolean`) to be verified.
566
603
  *
567
604
  * @param prefix
568
605
  * Contract type prefix used in the error message.
@@ -602,9 +639,7 @@ var Contracts = class _Contracts {
602
639
  const msg = `[${prefix}] ${ngMsg ?? ""}`;
603
640
  if (ErrorClass) {
604
641
  const err = eParams ? new ErrorClass(msg, eParams) : new ErrorClass(msg);
605
- if (eProps) {
606
- Object.assign(err, eProps);
607
- }
642
+ eProps && Object.assign(err, eProps);
608
643
  throw err;
609
644
  }
610
645
  if (ngMsg) {
@@ -626,7 +661,7 @@ var Contracts = class _Contracts {
626
661
  * @internal
627
662
  *
628
663
  * @param isOk
629
- * Condition result.
664
+ * Condition result(`boolean`) to be verified.
630
665
  *
631
666
  * @param prefix
632
667
  * Contract type prefix used in the error message.
@@ -671,7 +706,7 @@ var Contracts = class _Contracts {
671
706
  * @internal
672
707
  */
673
708
  static getLogger() {
674
- return _Contracts.logger ?? console;
709
+ return _Contracts.#config.logger;
675
710
  }
676
711
  };
677
712
 
package/dist/index.d.cts CHANGED
@@ -58,33 +58,38 @@ type ConfigKey = keyof Config;
58
58
  * @module Contracts
59
59
  */
60
60
  declare class Contracts {
61
+ #private;
61
62
  /**
62
63
  * Static fields
63
64
  */
64
65
  /** Debug mode state */
65
66
  static DEBUG_MODE: boolean;
66
- /** default configuration */
67
- private static readonly defaultConf;
68
67
  /** logger */
69
- private static logger;
70
68
  /**
71
69
  * Configures contract checking behavior.
72
70
  *
73
71
  * @param config
74
- * Configuration options.
75
- *
76
- * The `debug` property enables or disables
77
- * debug-only contract checks.
78
- *
72
+ * Configuration options. <br>
73
+ * <br>
74
+ * The `debug` property toggles the behavior—specifically,
75
+ * throwing an exception or outputting to the console when the condition is
76
+ * false—for the validation of contracts intended for use during debugging (methods ending in `_DEBUG`). <br>
77
+ * <br>
79
78
  * When `debug` is `true`,
80
- * methods ending with `_DEBUG` perform validation.
81
- *
82
- * When `debug` is `false` or omitted,
83
- * methods ending with `_DEBUG` skip validation.
84
- *
79
+ * methods ending with `_DEBUG` perform validation. <br>
80
+ * <br>
81
+ * When `debug` is `false`,
82
+ * methods ending with `_DEBUG` skip validation. <br>
83
+ * <br>
85
84
  * Is the `logger` property is specified,
86
85
  * it is used instead of the standard logger, `console`.
87
- * This module uses only the `error` method of the `logger`.
86
+ * This module uses only the `error` method of the `logger`. <br>
87
+ * <br>
88
+ * Note: If the value of a property is `undefined`, it is treated as unspecified.
89
+ *
90
+ * @param reset
91
+ * If `true`, unspecified values ​​are saved to the settings as default values. <br>
92
+ * If `false`, unspecified values ​​remain at their current settings.
88
93
  *
89
94
  * @example
90
95
  * // Use a logger that is slightly more advanced than the standard logger—namely, `console`.
@@ -94,7 +99,22 @@ declare class Contracts {
94
99
  * Contracts.setConfig({ debug: true, logger: prettyConsole });
95
100
  * // Node: ` The `logger` property is optional.
96
101
  */
97
- static setConfig(config: Config): void;
102
+ static setConfig(config: Config, reset?: boolean): void;
103
+ /**
104
+ * Get the default configurations.
105
+ * @returns Default configurations.
106
+ */
107
+ static getDefaultConfig(): Required<Config>;
108
+ /**
109
+ * Get the current configurations.
110
+ * @returns Default configurations.
111
+ */
112
+ static getConfig(): Required<Config>;
113
+ /**
114
+ * Reset the current configurations to the default configurations.
115
+ * @returns Default configurations.
116
+ */
117
+ static resetConfig(): void;
98
118
  /**
99
119
  * Verifies an intermediate condition during execution.
100
120
  *
@@ -113,7 +133,7 @@ declare class Contracts {
113
133
  * - Check temporary assumptions during execution.
114
134
  *
115
135
  * @param isOk
116
- * Condition result to verify.
136
+ * Condition result(`boolean`) to be verified.
117
137
  *
118
138
  * @param ngMsg
119
139
  * Failure message.
@@ -165,7 +185,7 @@ declare class Contracts {
165
185
  * - Check internal assumptions while debugging.
166
186
  *
167
187
  * @param isOk
168
- * Condition result to verify.
188
+ * Condition result(`boolean`) to be verified.
169
189
  *
170
190
  * @param ngMsg
171
191
  * Failure message.
@@ -215,7 +235,7 @@ declare class Contracts {
215
235
  * - Check required external conditions.
216
236
  *
217
237
  * @param isOk
218
- * Condition result to verify.
238
+ * Condition result(`boolean`) to be verified.
219
239
  *
220
240
  * @param ngMsg
221
241
  * Failure message.
@@ -274,7 +294,7 @@ declare class Contracts {
274
294
  * - Perform additional argument checks while debugging.
275
295
  *
276
296
  * @param isOk
277
- * Condition result to verify.
297
+ * Condition result(`boolean`) to be verified.
278
298
  *
279
299
  * @param ngMsg
280
300
  * Failure message.
@@ -325,7 +345,7 @@ declare class Contracts {
325
345
  * - Verify that processing completed correctly.
326
346
  *
327
347
  * @param isOk
328
- * Condition result to verify.
348
+ * Condition result(`boolean`) to be verified.
329
349
  *
330
350
  * @param ngMsg
331
351
  * Failure message.
@@ -386,7 +406,7 @@ declare class Contracts {
386
406
  * - Confirm internal behavior while debugging.
387
407
  *
388
408
  * @param isOk
389
- * Condition result to verify.
409
+ * Condition result(`boolean`) to be verified.
390
410
  *
391
411
  * @param ngMsg
392
412
  * Failure message.
@@ -437,7 +457,7 @@ declare class Contracts {
437
457
  * INVARIANT represents conditions that must always remain true.
438
458
  *
439
459
  * @param isOk
440
- * Condition result to verify.
460
+ * Condition result(`boolean`) to be verified.
441
461
  *
442
462
  * @param ngMsg
443
463
  * Failure message.
@@ -495,7 +515,7 @@ declare class Contracts {
495
515
  * - Detect unexpected state changes while debugging.
496
516
  *
497
517
  * @param isOk
498
- * Condition result to verify.
518
+ * Condition result(`boolean`) to be verified.
499
519
  *
500
520
  * @param [ngMsg]
501
521
  * Failure message.
@@ -548,7 +568,7 @@ declare class Contracts {
548
568
  * @internal
549
569
  *
550
570
  * @param isOk
551
- * Condition result.
571
+ * Condition result(`boolean`) to be verified.
552
572
  *
553
573
  * @param prefix
554
574
  * Contract type prefix used in the error message.
@@ -591,7 +611,7 @@ declare class Contracts {
591
611
  * @internal
592
612
  *
593
613
  * @param isOk
594
- * Condition result.
614
+ * Condition result(`boolean`) to be verified.
595
615
  *
596
616
  * @param prefix
597
617
  * Contract type prefix used in the error message.
package/dist/index.d.ts CHANGED
@@ -58,33 +58,38 @@ type ConfigKey = keyof Config;
58
58
  * @module Contracts
59
59
  */
60
60
  declare class Contracts {
61
+ #private;
61
62
  /**
62
63
  * Static fields
63
64
  */
64
65
  /** Debug mode state */
65
66
  static DEBUG_MODE: boolean;
66
- /** default configuration */
67
- private static readonly defaultConf;
68
67
  /** logger */
69
- private static logger;
70
68
  /**
71
69
  * Configures contract checking behavior.
72
70
  *
73
71
  * @param config
74
- * Configuration options.
75
- *
76
- * The `debug` property enables or disables
77
- * debug-only contract checks.
78
- *
72
+ * Configuration options. <br>
73
+ * <br>
74
+ * The `debug` property toggles the behavior—specifically,
75
+ * throwing an exception or outputting to the console when the condition is
76
+ * false—for the validation of contracts intended for use during debugging (methods ending in `_DEBUG`). <br>
77
+ * <br>
79
78
  * When `debug` is `true`,
80
- * methods ending with `_DEBUG` perform validation.
81
- *
82
- * When `debug` is `false` or omitted,
83
- * methods ending with `_DEBUG` skip validation.
84
- *
79
+ * methods ending with `_DEBUG` perform validation. <br>
80
+ * <br>
81
+ * When `debug` is `false`,
82
+ * methods ending with `_DEBUG` skip validation. <br>
83
+ * <br>
85
84
  * Is the `logger` property is specified,
86
85
  * it is used instead of the standard logger, `console`.
87
- * This module uses only the `error` method of the `logger`.
86
+ * This module uses only the `error` method of the `logger`. <br>
87
+ * <br>
88
+ * Note: If the value of a property is `undefined`, it is treated as unspecified.
89
+ *
90
+ * @param reset
91
+ * If `true`, unspecified values ​​are saved to the settings as default values. <br>
92
+ * If `false`, unspecified values ​​remain at their current settings.
88
93
  *
89
94
  * @example
90
95
  * // Use a logger that is slightly more advanced than the standard logger—namely, `console`.
@@ -94,7 +99,22 @@ declare class Contracts {
94
99
  * Contracts.setConfig({ debug: true, logger: prettyConsole });
95
100
  * // Node: ` The `logger` property is optional.
96
101
  */
97
- static setConfig(config: Config): void;
102
+ static setConfig(config: Config, reset?: boolean): void;
103
+ /**
104
+ * Get the default configurations.
105
+ * @returns Default configurations.
106
+ */
107
+ static getDefaultConfig(): Required<Config>;
108
+ /**
109
+ * Get the current configurations.
110
+ * @returns Default configurations.
111
+ */
112
+ static getConfig(): Required<Config>;
113
+ /**
114
+ * Reset the current configurations to the default configurations.
115
+ * @returns Default configurations.
116
+ */
117
+ static resetConfig(): void;
98
118
  /**
99
119
  * Verifies an intermediate condition during execution.
100
120
  *
@@ -113,7 +133,7 @@ declare class Contracts {
113
133
  * - Check temporary assumptions during execution.
114
134
  *
115
135
  * @param isOk
116
- * Condition result to verify.
136
+ * Condition result(`boolean`) to be verified.
117
137
  *
118
138
  * @param ngMsg
119
139
  * Failure message.
@@ -165,7 +185,7 @@ declare class Contracts {
165
185
  * - Check internal assumptions while debugging.
166
186
  *
167
187
  * @param isOk
168
- * Condition result to verify.
188
+ * Condition result(`boolean`) to be verified.
169
189
  *
170
190
  * @param ngMsg
171
191
  * Failure message.
@@ -215,7 +235,7 @@ declare class Contracts {
215
235
  * - Check required external conditions.
216
236
  *
217
237
  * @param isOk
218
- * Condition result to verify.
238
+ * Condition result(`boolean`) to be verified.
219
239
  *
220
240
  * @param ngMsg
221
241
  * Failure message.
@@ -274,7 +294,7 @@ declare class Contracts {
274
294
  * - Perform additional argument checks while debugging.
275
295
  *
276
296
  * @param isOk
277
- * Condition result to verify.
297
+ * Condition result(`boolean`) to be verified.
278
298
  *
279
299
  * @param ngMsg
280
300
  * Failure message.
@@ -325,7 +345,7 @@ declare class Contracts {
325
345
  * - Verify that processing completed correctly.
326
346
  *
327
347
  * @param isOk
328
- * Condition result to verify.
348
+ * Condition result(`boolean`) to be verified.
329
349
  *
330
350
  * @param ngMsg
331
351
  * Failure message.
@@ -386,7 +406,7 @@ declare class Contracts {
386
406
  * - Confirm internal behavior while debugging.
387
407
  *
388
408
  * @param isOk
389
- * Condition result to verify.
409
+ * Condition result(`boolean`) to be verified.
390
410
  *
391
411
  * @param ngMsg
392
412
  * Failure message.
@@ -437,7 +457,7 @@ declare class Contracts {
437
457
  * INVARIANT represents conditions that must always remain true.
438
458
  *
439
459
  * @param isOk
440
- * Condition result to verify.
460
+ * Condition result(`boolean`) to be verified.
441
461
  *
442
462
  * @param ngMsg
443
463
  * Failure message.
@@ -495,7 +515,7 @@ declare class Contracts {
495
515
  * - Detect unexpected state changes while debugging.
496
516
  *
497
517
  * @param isOk
498
- * Condition result to verify.
518
+ * Condition result(`boolean`) to be verified.
499
519
  *
500
520
  * @param [ngMsg]
501
521
  * Failure message.
@@ -548,7 +568,7 @@ declare class Contracts {
548
568
  * @internal
549
569
  *
550
570
  * @param isOk
551
- * Condition result.
571
+ * Condition result(`boolean`) to be verified.
552
572
  *
553
573
  * @param prefix
554
574
  * Contract type prefix used in the error message.
@@ -591,7 +611,7 @@ declare class Contracts {
591
611
  * @internal
592
612
  *
593
613
  * @param isOk
594
- * Condition result.
614
+ * Condition result(`boolean`) to be verified.
595
615
  *
596
616
  * @param prefix
597
617
  * Contract type prefix used in the error message.
package/dist/index.js CHANGED
@@ -6,30 +6,39 @@ var Contracts = class _Contracts {
6
6
  /** Debug mode state */
7
7
  static DEBUG_MODE = false;
8
8
  /** default configuration */
9
- static defaultConf = {
9
+ static #defaultConf = {
10
10
  debug: false,
11
11
  logger: console
12
12
  };
13
+ /** Current config. */
14
+ static #config = { ..._Contracts.#defaultConf };
13
15
  /** logger */
14
- static logger = console;
16
+ //private static logger: LogProvider = console;
15
17
  /**
16
18
  * Configures contract checking behavior.
17
19
  *
18
20
  * @param config
19
- * Configuration options.
20
- *
21
- * The `debug` property enables or disables
22
- * debug-only contract checks.
23
- *
21
+ * Configuration options. <br>
22
+ * <br>
23
+ * The `debug` property toggles the behavior—specifically,
24
+ * throwing an exception or outputting to the console when the condition is
25
+ * false—for the validation of contracts intended for use during debugging (methods ending in `_DEBUG`). <br>
26
+ * <br>
24
27
  * When `debug` is `true`,
25
- * methods ending with `_DEBUG` perform validation.
26
- *
27
- * When `debug` is `false` or omitted,
28
- * methods ending with `_DEBUG` skip validation.
29
- *
28
+ * methods ending with `_DEBUG` perform validation. <br>
29
+ * <br>
30
+ * When `debug` is `false`,
31
+ * methods ending with `_DEBUG` skip validation. <br>
32
+ * <br>
30
33
  * Is the `logger` property is specified,
31
34
  * it is used instead of the standard logger, `console`.
32
- * This module uses only the `error` method of the `logger`.
35
+ * This module uses only the `error` method of the `logger`. <br>
36
+ * <br>
37
+ * Note: If the value of a property is `undefined`, it is treated as unspecified.
38
+ *
39
+ * @param reset
40
+ * If `true`, unspecified values ​​are saved to the settings as default values. <br>
41
+ * If `false`, unspecified values ​​remain at their current settings.
33
42
  *
34
43
  * @example
35
44
  * // Use a logger that is slightly more advanced than the standard logger—namely, `console`.
@@ -39,9 +48,36 @@ var Contracts = class _Contracts {
39
48
  * Contracts.setConfig({ debug: true, logger: prettyConsole });
40
49
  * // Node: ` The `logger` property is optional.
41
50
  */
42
- static setConfig(config) {
43
- _Contracts.DEBUG_MODE = Boolean(config?.debug);
44
- _Contracts.logger = config?.logger ?? console;
51
+ static setConfig(config, reset = true) {
52
+ const rConf = { ...config };
53
+ for (let key of Object.keys(rConf)) {
54
+ if (rConf[key] == null) delete rConf[key];
55
+ }
56
+ if (reset) _Contracts.#config = { ..._Contracts.getDefaultConfig() };
57
+ Object.assign(_Contracts.#config, rConf);
58
+ _Contracts.DEBUG_MODE = _Contracts.#config.debug;
59
+ }
60
+ /**
61
+ * Get the default configurations.
62
+ * @returns Default configurations.
63
+ */
64
+ static getDefaultConfig() {
65
+ return { ..._Contracts.#defaultConf };
66
+ }
67
+ /**
68
+ * Get the current configurations.
69
+ * @returns Default configurations.
70
+ */
71
+ static getConfig() {
72
+ _Contracts.#config.debug = _Contracts.DEBUG_MODE;
73
+ return { ..._Contracts.#config };
74
+ }
75
+ /**
76
+ * Reset the current configurations to the default configurations.
77
+ * @returns Default configurations.
78
+ */
79
+ static resetConfig() {
80
+ _Contracts.setConfig({}, true);
45
81
  }
46
82
  /**
47
83
  * Verifies an intermediate condition during execution.
@@ -61,7 +97,7 @@ var Contracts = class _Contracts {
61
97
  * - Check temporary assumptions during execution.
62
98
  *
63
99
  * @param isOk
64
- * Condition result to verify.
100
+ * Condition result(`boolean`) to be verified.
65
101
  *
66
102
  * @param ngMsg
67
103
  * Failure message.
@@ -118,7 +154,7 @@ var Contracts = class _Contracts {
118
154
  * - Check internal assumptions while debugging.
119
155
  *
120
156
  * @param isOk
121
- * Condition result to verify.
157
+ * Condition result(`boolean`) to be verified.
122
158
  *
123
159
  * @param ngMsg
124
160
  * Failure message.
@@ -173,7 +209,7 @@ var Contracts = class _Contracts {
173
209
  * - Check required external conditions.
174
210
  *
175
211
  * @param isOk
176
- * Condition result to verify.
212
+ * Condition result(`boolean`) to be verified.
177
213
  *
178
214
  * @param ngMsg
179
215
  * Failure message.
@@ -237,7 +273,7 @@ var Contracts = class _Contracts {
237
273
  * - Perform additional argument checks while debugging.
238
274
  *
239
275
  * @param isOk
240
- * Condition result to verify.
276
+ * Condition result(`boolean`) to be verified.
241
277
  *
242
278
  * @param ngMsg
243
279
  * Failure message.
@@ -293,7 +329,7 @@ var Contracts = class _Contracts {
293
329
  * - Verify that processing completed correctly.
294
330
  *
295
331
  * @param isOk
296
- * Condition result to verify.
332
+ * Condition result(`boolean`) to be verified.
297
333
  *
298
334
  * @param ngMsg
299
335
  * Failure message.
@@ -359,7 +395,7 @@ var Contracts = class _Contracts {
359
395
  * - Confirm internal behavior while debugging.
360
396
  *
361
397
  * @param isOk
362
- * Condition result to verify.
398
+ * Condition result(`boolean`) to be verified.
363
399
  *
364
400
  * @param ngMsg
365
401
  * Failure message.
@@ -415,7 +451,7 @@ var Contracts = class _Contracts {
415
451
  * INVARIANT represents conditions that must always remain true.
416
452
  *
417
453
  * @param isOk
418
- * Condition result to verify.
454
+ * Condition result(`boolean`) to be verified.
419
455
  *
420
456
  * @param ngMsg
421
457
  * Failure message.
@@ -478,7 +514,7 @@ var Contracts = class _Contracts {
478
514
  * - Detect unexpected state changes while debugging.
479
515
  *
480
516
  * @param isOk
481
- * Condition result to verify.
517
+ * Condition result(`boolean`) to be verified.
482
518
  *
483
519
  * @param [ngMsg]
484
520
  * Failure message.
@@ -536,7 +572,7 @@ var Contracts = class _Contracts {
536
572
  * @internal
537
573
  *
538
574
  * @param isOk
539
- * Condition result.
575
+ * Condition result(`boolean`) to be verified.
540
576
  *
541
577
  * @param prefix
542
578
  * Contract type prefix used in the error message.
@@ -576,9 +612,7 @@ var Contracts = class _Contracts {
576
612
  const msg = `[${prefix}] ${ngMsg ?? ""}`;
577
613
  if (ErrorClass) {
578
614
  const err = eParams ? new ErrorClass(msg, eParams) : new ErrorClass(msg);
579
- if (eProps) {
580
- Object.assign(err, eProps);
581
- }
615
+ eProps && Object.assign(err, eProps);
582
616
  throw err;
583
617
  }
584
618
  if (ngMsg) {
@@ -600,7 +634,7 @@ var Contracts = class _Contracts {
600
634
  * @internal
601
635
  *
602
636
  * @param isOk
603
- * Condition result.
637
+ * Condition result(`boolean`) to be verified.
604
638
  *
605
639
  * @param prefix
606
640
  * Contract type prefix used in the error message.
@@ -645,7 +679,7 @@ var Contracts = class _Contracts {
645
679
  * @internal
646
680
  */
647
681
  static getLogger() {
648
- return _Contracts.logger ?? console;
682
+ return _Contracts.#config.logger;
649
683
  }
650
684
  };
651
685
 
package/package.json CHANGED
@@ -1,38 +1,43 @@
1
- {
2
- "name": "@ayapapa-npm/contracts-js",
3
- "version": "0.3.0",
4
- "description": "A lightweight Design by Contract library for JavaScript.",
5
- "license": "MIT",
6
- "author": "ayapapa",
7
- "type": "module",
8
- "main": "./dist/index.cjs",
9
- "module": "./dist/index.js",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
- }
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "scripts": {
20
- "build": "tsup src/index.ts --format esm,cjs --out-dir dist --clean --dts",
21
- "typecheck": "tsc --noEmit",
22
- "test": "vitest run",
23
- "test:debug": "vitest --inspect-brk --run",
24
- "test:watch": "vitest",
25
- "check": "npm run typecheck && npm run build && npm run test",
26
- "release:check": "npm run typecheck && npm run build && npm run test",
27
- "prepublishOnly": "npm run release:check"
28
- },
29
- "devDependencies": {
30
- "@types/node": "^26.2.0",
31
- "tsup": "^8.5.1",
32
- "typescript": "^5.9.3",
33
- "vitest": "^4.1.10"
34
- },
35
- "allowScripts": {
36
- "esbuild@0.28.1": true
37
- }
38
- }
1
+ {
2
+ "name": "@ayapapa-npm/contracts-js",
3
+ "version": "0.4.1",
4
+ "description": "A lightweight Design by Contract library for JavaScript.",
5
+ "license": "MIT",
6
+ "author": "ayapapa",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format esm,cjs --out-dir dist --clean --dts",
21
+ "typecheck": "tsc --noEmit",
22
+ "test": "vitest run",
23
+ "test:debug": "vitest --inspect-brk --run",
24
+ "test:watch": "vitest",
25
+ "test:ui": "vitest --ui",
26
+ "coverage": "vitest run --coverage",
27
+ "coverage:ui": "vitest run --coverage && start coverage/index.html",
28
+ "check": "npm run typecheck && npm run build && npm run test",
29
+ "release:check": "npm run check",
30
+ "prepublishOnly": "npm run release:check"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^26.2.0",
34
+ "@vitest/coverage-v8": "^4.1.11",
35
+ "@vitest/ui": "^4.1.11",
36
+ "tsup": "^8.5.1",
37
+ "typedoc": "^0.28.20",
38
+ "typedoc-plugin-markdown": "^4.13.0",
39
+ "typescript": "^5.9.3",
40
+ "vite": "^8.2.2",
41
+ "vitest": "^4.1.11"
42
+ }
43
+ }