@ayapapa-npm/contracts-js 0.4.1 → 0.4.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.
package/README.md CHANGED
@@ -5,11 +5,18 @@
5
5
  ![Lines](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-lines.svg)
6
6
  ![Statements](https://raw.githubusercontent.com/ayapapa/contracts-js/main/badges/coverage-statements.svg)
7
7
 
8
+ ## Table of contents
9
+ [Overview](#overview) | [API Reference](#api-reference) | [Installation](#installation) | [Contract Types](#contract-types) | [Usage](#usage)
10
+
8
11
  # contracts-js
12
+ ## Overview
9
13
  A lightweight Design by Contract library for JavaScript.</br>
10
14
  Provides runtime contract checks based on Design by Contract principles.</br>
11
15
  All check functions return the evaluated condition itself, so they can be used directly in control flow when exception throwing is suppressed.
12
16
 
17
+ ## API Reference
18
+ [API document](https://github.com/ayapapa/contracts-js/blob/main/docs/api.md)<br>
19
+ Implementation examples are also included.
13
20
 
14
21
  ## Installation
15
22
 
@@ -132,9 +139,6 @@ Contracts.INVARIANT(
132
139
  );
133
140
  ```
134
141
 
135
- ## API Reference
136
- [API document](docs/api.md)
137
-
138
142
  ## Usage
139
143
 
140
144
  ```javascript
package/dist/index.cjs CHANGED
@@ -30,7 +30,11 @@ var Contracts = class _Contracts {
30
30
  /**
31
31
  * Static fields
32
32
  */
33
- /** Debug mode state */
33
+ /**
34
+ * Debug mode state.<br>
35
+ * **Note: This property is retained for backward compatibility.<br>
36
+ * Please use `setConfig()` to change the debug mode.**
37
+ */
34
38
  static DEBUG_MODE = false;
35
39
  /** default configuration */
36
40
  static #defaultConf = {
@@ -39,8 +43,6 @@ var Contracts = class _Contracts {
39
43
  };
40
44
  /** Current config. */
41
45
  static #config = { ..._Contracts.#defaultConf };
42
- /** logger */
43
- //private static logger: LogProvider = console;
44
46
  /**
45
47
  * Configures contract checking behavior.
46
48
  *
@@ -61,7 +63,7 @@ var Contracts = class _Contracts {
61
63
  * it is used instead of the standard logger, `console`.
62
64
  * This module uses only the `error` method of the `logger`. <br>
63
65
  * <br>
64
- * Note: If the value of a property is `undefined`, it is treated as unspecified.
66
+ * Note: If the value of a property is `undefined` or `null`, it is treated as unspecified.
65
67
  *
66
68
  * @param reset
67
69
  * If `true`, unspecified values ​​are saved to the settings as default values. <br>
@@ -171,9 +173,9 @@ var Contracts = class _Contracts {
171
173
  * Verifies an intermediate condition in debug mode only.
172
174
  *
173
175
  * Performs the same validation as VERIFY only when
174
- * DEBUG_MODE is enabled.
176
+ * `debug_mode`(internal state) is enabled.
175
177
  *
176
- * When DEBUG_MODE is disabled,
178
+ * When `debug_mode`(internal state) is disabled,
177
179
  * no validation is performed.
178
180
  *
179
181
  * Typical usage:
@@ -290,9 +292,9 @@ var Contracts = class _Contracts {
290
292
  * Checks a precondition in debug mode only.
291
293
  *
292
294
  * Performs the same validation as REQUIRE only when
293
- * DEBUG_MODE is enabled.
295
+ * `debug_mode`(internal state) is enabled.
294
296
  *
295
- * When DEBUG_MODE is disabled,
297
+ * When `debug_mode`(internal state) is disabled,
296
298
  * no validation is performed.
297
299
  *
298
300
  * Typical usage:
@@ -412,9 +414,9 @@ var Contracts = class _Contracts {
412
414
  * Checks a postcondition in debug mode only.
413
415
  *
414
416
  * Performs the same validation as ENSURE only when
415
- * DEBUG_MODE is enabled.
417
+ * `debug_mode`(internal state) is enabled.
416
418
  *
417
- * When DEBUG_MODE is disabled,
419
+ * When `debug_mode`(internal state) is disabled,
418
420
  * no validation is performed.
419
421
  *
420
422
  * Typical usage:
@@ -531,9 +533,9 @@ var Contracts = class _Contracts {
531
533
  * Checks an invariant condition in debug mode only.
532
534
  *
533
535
  * Performs the same validation as INVARIANT only when
534
- * DEBUG_MODE is enabled.
536
+ * `debug_mode`(internal state) is enabled.
535
537
  *
536
- * When DEBUG_MODE is disabled,
538
+ * When `debug_mode`(internal state) is disabled,
537
539
  * no validation is performed.
538
540
  *
539
541
  * Typical usage:
@@ -631,9 +633,6 @@ var Contracts = class _Contracts {
631
633
  static check(isOk, prefix = "CHECK", ngMsg = "", ErrorClass = Error, eParams, eProps) {
632
634
  if (eProps === void 0) {
633
635
  eProps = eParams ?? {};
634
- eParams = null;
635
- } else {
636
- eProps ??= {};
637
636
  }
638
637
  if (!isOk) {
639
638
  const msg = `[${prefix}] ${ngMsg ?? ""}`;
@@ -643,7 +642,7 @@ var Contracts = class _Contracts {
643
642
  throw err;
644
643
  }
645
644
  if (ngMsg) {
646
- _Contracts.getLogger().error(msg, eProps);
645
+ _Contracts.#getLogger().error(msg, eProps);
647
646
  }
648
647
  }
649
648
  return isOk;
@@ -651,10 +650,9 @@ var Contracts = class _Contracts {
651
650
  /**
652
651
  * Debug-only contract evaluation logic.
653
652
  *
654
- * Executes contract validation only when DEBUG_MODE
655
- * is enabled.
653
+ * Executes contract validation only when `debug_mode`(internal state) is enabled.
656
654
  *
657
- * When DEBUG_MODE is disabled,
655
+ * When `debug_mode`(internal state) is disabled,
658
656
  * this method returns the original condition value
659
657
  * without performing any validation.
660
658
  *
@@ -701,11 +699,10 @@ var Contracts = class _Contracts {
701
699
  ) : isOk;
702
700
  }
703
701
  /**
704
- * Get logger
705
- *
706
702
  * @internal
703
+ * Get logger
707
704
  */
708
- static getLogger() {
705
+ static #getLogger() {
709
706
  return _Contracts.#config.logger;
710
707
  }
711
708
  };
package/dist/index.d.cts CHANGED
@@ -8,7 +8,7 @@ type LogProvider = Pick<Console, 'error'>;
8
8
  interface Config {
9
9
  /**
10
10
  * Debug mode state.
11
- * If `true`, `DEBUG_MODE` is enabled; otherwise, it is disabled.
11
+ * If `true`, `debug_mode`(internal state) is enabled; otherwise, it is disabled.
12
12
  * The default is `false`.
13
13
  */
14
14
  debug?: boolean;
@@ -49,9 +49,9 @@ type ConfigKey = keyof Config;
49
49
  * ## Debug Mode
50
50
  *
51
51
  * Methods ending with `_DEBUG` execute contract checks only
52
- * when `DEBUG_MODE` is enabled.
52
+ * when `debug_mode`(internal state) is enabled.
53
53
  *
54
- * When `DEBUG_MODE` is disabled,
54
+ * When `debug_mode`(internal state) is disabled,
55
55
  * these methods return the original condition value
56
56
  * without performing validation.
57
57
  *
@@ -62,9 +62,12 @@ declare class Contracts {
62
62
  /**
63
63
  * Static fields
64
64
  */
65
- /** Debug mode state */
65
+ /**
66
+ * Debug mode state.<br>
67
+ * **Note: This property is retained for backward compatibility.<br>
68
+ * Please use `setConfig()` to change the debug mode.**
69
+ */
66
70
  static DEBUG_MODE: boolean;
67
- /** logger */
68
71
  /**
69
72
  * Configures contract checking behavior.
70
73
  *
@@ -85,7 +88,7 @@ declare class Contracts {
85
88
  * it is used instead of the standard logger, `console`.
86
89
  * This module uses only the `error` method of the `logger`. <br>
87
90
  * <br>
88
- * Note: If the value of a property is `undefined`, it is treated as unspecified.
91
+ * Note: If the value of a property is `undefined` or `null`, it is treated as unspecified.
89
92
  *
90
93
  * @param reset
91
94
  * If `true`, unspecified values ​​are saved to the settings as default values. <br>
@@ -166,18 +169,14 @@ declare class Contracts {
166
169
  * 'Calculation result must not be negative'
167
170
  * );
168
171
  */
169
- static VERIFY(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
170
- [key: string]: any;
171
- } | null, eProps?: {
172
- [key: string]: any;
173
- } | null): boolean;
172
+ static VERIFY(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
174
173
  /**
175
174
  * Verifies an intermediate condition in debug mode only.
176
175
  *
177
176
  * Performs the same validation as VERIFY only when
178
- * DEBUG_MODE is enabled.
177
+ * `debug_mode`(internal state) is enabled.
179
178
  *
180
- * When DEBUG_MODE is disabled,
179
+ * When `debug_mode`(internal state) is disabled,
181
180
  * no validation is performed.
182
181
  *
183
182
  * Typical usage:
@@ -216,11 +215,7 @@ declare class Contracts {
216
215
  * 'Intermediate value must not be null'
217
216
  * );
218
217
  */
219
- static VERIFY_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
220
- [key: string]: any;
221
- } | null, eProps?: {
222
- [key: string]: any;
223
- } | null): boolean;
218
+ static VERIFY_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
224
219
  /**
225
220
  * Checks a precondition before execution.
226
221
  *
@@ -275,18 +270,14 @@ declare class Contracts {
275
270
  * return a / b;
276
271
  * }
277
272
  */
278
- static REQUIRE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
279
- [key: string]: any;
280
- } | null, eProps?: {
281
- [key: string]: any;
282
- } | null): boolean;
273
+ static REQUIRE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
283
274
  /**
284
275
  * Checks a precondition in debug mode only.
285
276
  *
286
277
  * Performs the same validation as REQUIRE only when
287
- * DEBUG_MODE is enabled.
278
+ * `debug_mode`(internal state) is enabled.
288
279
  *
289
- * When DEBUG_MODE is disabled,
280
+ * When `debug_mode`(internal state) is disabled,
290
281
  * no validation is performed.
291
282
  *
292
283
  * Typical usage:
@@ -325,11 +316,7 @@ declare class Contracts {
325
316
  * 'User must exist during debugging'
326
317
  * );
327
318
  */
328
- static REQUIRE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
329
- [key: string]: any;
330
- } | null, eProps?: {
331
- [key: string]: any;
332
- } | null): boolean;
319
+ static REQUIRE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
333
320
  /**
334
321
  * Checks a postcondition after execution.
335
322
  *
@@ -387,18 +374,14 @@ declare class Contracts {
387
374
  * return result;
388
375
  * }
389
376
  */
390
- static ENSURE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
391
- [key: string]: any;
392
- } | null, eProps?: {
393
- [key: string]: any;
394
- } | null): boolean;
377
+ static ENSURE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
395
378
  /**
396
379
  * Checks a postcondition in debug mode only.
397
380
  *
398
381
  * Performs the same validation as ENSURE only when
399
- * DEBUG_MODE is enabled.
382
+ * `debug_mode`(internal state) is enabled.
400
383
  *
401
- * When DEBUG_MODE is disabled,
384
+ * When `debug_mode`(internal state) is disabled,
402
385
  * no validation is performed.
403
386
  *
404
387
  * Typical usage:
@@ -437,11 +420,7 @@ declare class Contracts {
437
420
  * 'Result should exist during debugging'
438
421
  * );
439
422
  */
440
- static ENSURE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
441
- [key: string]: any;
442
- } | null, eProps?: {
443
- [key: string]: any;
444
- } | null): boolean;
423
+ static ENSURE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
445
424
  /**
446
425
  * Checks an invariant condition.
447
426
  *
@@ -496,18 +475,14 @@ declare class Contracts {
496
475
  *
497
476
  * }
498
477
  */
499
- static INVARIANT(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
500
- [key: string]: any;
501
- } | null, eProps?: {
502
- [key: string]: any;
503
- } | null): boolean;
478
+ static INVARIANT(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
504
479
  /**
505
480
  * Checks an invariant condition in debug mode only.
506
481
  *
507
482
  * Performs the same validation as INVARIANT only when
508
- * DEBUG_MODE is enabled.
483
+ * `debug_mode`(internal state) is enabled.
509
484
  *
510
- * When DEBUG_MODE is disabled,
485
+ * When `debug_mode`(internal state) is disabled,
511
486
  * no validation is performed.
512
487
  *
513
488
  * Typical usage:
@@ -546,11 +521,7 @@ declare class Contracts {
546
521
  * 'Cache size exceeded expected limit'
547
522
  * );
548
523
  */
549
- static INVARIANT_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
550
- [key: string]: any;
551
- } | null, eProps?: {
552
- [key: string]: any;
553
- } | null): boolean;
524
+ static INVARIANT_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
554
525
  /**
555
526
  * Core contract evaluation logic.
556
527
  *
@@ -601,10 +572,9 @@ declare class Contracts {
601
572
  /**
602
573
  * Debug-only contract evaluation logic.
603
574
  *
604
- * Executes contract validation only when DEBUG_MODE
605
- * is enabled.
575
+ * Executes contract validation only when `debug_mode`(internal state) is enabled.
606
576
  *
607
- * When DEBUG_MODE is disabled,
577
+ * When `debug_mode`(internal state) is disabled,
608
578
  * this method returns the original condition value
609
579
  * without performing any validation.
610
580
  *
@@ -641,12 +611,6 @@ declare class Contracts {
641
611
  *
642
612
  */
643
613
  private static checkDebug;
644
- /**
645
- * Get logger
646
- *
647
- * @internal
648
- */
649
- private static getLogger;
650
614
  }
651
615
 
652
616
  export { type Config, type ConfigKey, Contracts, type LogProvider, Contracts as default };
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ type LogProvider = Pick<Console, 'error'>;
8
8
  interface Config {
9
9
  /**
10
10
  * Debug mode state.
11
- * If `true`, `DEBUG_MODE` is enabled; otherwise, it is disabled.
11
+ * If `true`, `debug_mode`(internal state) is enabled; otherwise, it is disabled.
12
12
  * The default is `false`.
13
13
  */
14
14
  debug?: boolean;
@@ -49,9 +49,9 @@ type ConfigKey = keyof Config;
49
49
  * ## Debug Mode
50
50
  *
51
51
  * Methods ending with `_DEBUG` execute contract checks only
52
- * when `DEBUG_MODE` is enabled.
52
+ * when `debug_mode`(internal state) is enabled.
53
53
  *
54
- * When `DEBUG_MODE` is disabled,
54
+ * When `debug_mode`(internal state) is disabled,
55
55
  * these methods return the original condition value
56
56
  * without performing validation.
57
57
  *
@@ -62,9 +62,12 @@ declare class Contracts {
62
62
  /**
63
63
  * Static fields
64
64
  */
65
- /** Debug mode state */
65
+ /**
66
+ * Debug mode state.<br>
67
+ * **Note: This property is retained for backward compatibility.<br>
68
+ * Please use `setConfig()` to change the debug mode.**
69
+ */
66
70
  static DEBUG_MODE: boolean;
67
- /** logger */
68
71
  /**
69
72
  * Configures contract checking behavior.
70
73
  *
@@ -85,7 +88,7 @@ declare class Contracts {
85
88
  * it is used instead of the standard logger, `console`.
86
89
  * This module uses only the `error` method of the `logger`. <br>
87
90
  * <br>
88
- * Note: If the value of a property is `undefined`, it is treated as unspecified.
91
+ * Note: If the value of a property is `undefined` or `null`, it is treated as unspecified.
89
92
  *
90
93
  * @param reset
91
94
  * If `true`, unspecified values ​​are saved to the settings as default values. <br>
@@ -166,18 +169,14 @@ declare class Contracts {
166
169
  * 'Calculation result must not be negative'
167
170
  * );
168
171
  */
169
- static VERIFY(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
170
- [key: string]: any;
171
- } | null, eProps?: {
172
- [key: string]: any;
173
- } | null): boolean;
172
+ static VERIFY(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
174
173
  /**
175
174
  * Verifies an intermediate condition in debug mode only.
176
175
  *
177
176
  * Performs the same validation as VERIFY only when
178
- * DEBUG_MODE is enabled.
177
+ * `debug_mode`(internal state) is enabled.
179
178
  *
180
- * When DEBUG_MODE is disabled,
179
+ * When `debug_mode`(internal state) is disabled,
181
180
  * no validation is performed.
182
181
  *
183
182
  * Typical usage:
@@ -216,11 +215,7 @@ declare class Contracts {
216
215
  * 'Intermediate value must not be null'
217
216
  * );
218
217
  */
219
- static VERIFY_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
220
- [key: string]: any;
221
- } | null, eProps?: {
222
- [key: string]: any;
223
- } | null): boolean;
218
+ static VERIFY_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
224
219
  /**
225
220
  * Checks a precondition before execution.
226
221
  *
@@ -275,18 +270,14 @@ declare class Contracts {
275
270
  * return a / b;
276
271
  * }
277
272
  */
278
- static REQUIRE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
279
- [key: string]: any;
280
- } | null, eProps?: {
281
- [key: string]: any;
282
- } | null): boolean;
273
+ static REQUIRE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
283
274
  /**
284
275
  * Checks a precondition in debug mode only.
285
276
  *
286
277
  * Performs the same validation as REQUIRE only when
287
- * DEBUG_MODE is enabled.
278
+ * `debug_mode`(internal state) is enabled.
288
279
  *
289
- * When DEBUG_MODE is disabled,
280
+ * When `debug_mode`(internal state) is disabled,
290
281
  * no validation is performed.
291
282
  *
292
283
  * Typical usage:
@@ -325,11 +316,7 @@ declare class Contracts {
325
316
  * 'User must exist during debugging'
326
317
  * );
327
318
  */
328
- static REQUIRE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
329
- [key: string]: any;
330
- } | null, eProps?: {
331
- [key: string]: any;
332
- } | null): boolean;
319
+ static REQUIRE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
333
320
  /**
334
321
  * Checks a postcondition after execution.
335
322
  *
@@ -387,18 +374,14 @@ declare class Contracts {
387
374
  * return result;
388
375
  * }
389
376
  */
390
- static ENSURE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
391
- [key: string]: any;
392
- } | null, eProps?: {
393
- [key: string]: any;
394
- } | null): boolean;
377
+ static ENSURE(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
395
378
  /**
396
379
  * Checks a postcondition in debug mode only.
397
380
  *
398
381
  * Performs the same validation as ENSURE only when
399
- * DEBUG_MODE is enabled.
382
+ * `debug_mode`(internal state) is enabled.
400
383
  *
401
- * When DEBUG_MODE is disabled,
384
+ * When `debug_mode`(internal state) is disabled,
402
385
  * no validation is performed.
403
386
  *
404
387
  * Typical usage:
@@ -437,11 +420,7 @@ declare class Contracts {
437
420
  * 'Result should exist during debugging'
438
421
  * );
439
422
  */
440
- static ENSURE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
441
- [key: string]: any;
442
- } | null, eProps?: {
443
- [key: string]: any;
444
- } | null): boolean;
423
+ static ENSURE_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
445
424
  /**
446
425
  * Checks an invariant condition.
447
426
  *
@@ -496,18 +475,14 @@ declare class Contracts {
496
475
  *
497
476
  * }
498
477
  */
499
- static INVARIANT(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
500
- [key: string]: any;
501
- } | null, eProps?: {
502
- [key: string]: any;
503
- } | null): boolean;
478
+ static INVARIANT(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
504
479
  /**
505
480
  * Checks an invariant condition in debug mode only.
506
481
  *
507
482
  * Performs the same validation as INVARIANT only when
508
- * DEBUG_MODE is enabled.
483
+ * `debug_mode`(internal state) is enabled.
509
484
  *
510
- * When DEBUG_MODE is disabled,
485
+ * When `debug_mode`(internal state) is disabled,
511
486
  * no validation is performed.
512
487
  *
513
488
  * Typical usage:
@@ -546,11 +521,7 @@ declare class Contracts {
546
521
  * 'Cache size exceeded expected limit'
547
522
  * );
548
523
  */
549
- static INVARIANT_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: {
550
- [key: string]: any;
551
- } | null, eProps?: {
552
- [key: string]: any;
553
- } | null): boolean;
524
+ static INVARIANT_DEBUG(isOk: boolean, ngMsg: string | null, ErrorClass?: (new (...args: any[]) => Error) | null, eParams?: Record<string, unknown> | null, eProps?: Record<string, unknown> | null): boolean;
554
525
  /**
555
526
  * Core contract evaluation logic.
556
527
  *
@@ -601,10 +572,9 @@ declare class Contracts {
601
572
  /**
602
573
  * Debug-only contract evaluation logic.
603
574
  *
604
- * Executes contract validation only when DEBUG_MODE
605
- * is enabled.
575
+ * Executes contract validation only when `debug_mode`(internal state) is enabled.
606
576
  *
607
- * When DEBUG_MODE is disabled,
577
+ * When `debug_mode`(internal state) is disabled,
608
578
  * this method returns the original condition value
609
579
  * without performing any validation.
610
580
  *
@@ -641,12 +611,6 @@ declare class Contracts {
641
611
  *
642
612
  */
643
613
  private static checkDebug;
644
- /**
645
- * Get logger
646
- *
647
- * @internal
648
- */
649
- private static getLogger;
650
614
  }
651
615
 
652
616
  export { type Config, type ConfigKey, Contracts, type LogProvider, Contracts as default };
package/dist/index.js CHANGED
@@ -3,7 +3,11 @@ var Contracts = class _Contracts {
3
3
  /**
4
4
  * Static fields
5
5
  */
6
- /** Debug mode state */
6
+ /**
7
+ * Debug mode state.<br>
8
+ * **Note: This property is retained for backward compatibility.<br>
9
+ * Please use `setConfig()` to change the debug mode.**
10
+ */
7
11
  static DEBUG_MODE = false;
8
12
  /** default configuration */
9
13
  static #defaultConf = {
@@ -12,8 +16,6 @@ var Contracts = class _Contracts {
12
16
  };
13
17
  /** Current config. */
14
18
  static #config = { ..._Contracts.#defaultConf };
15
- /** logger */
16
- //private static logger: LogProvider = console;
17
19
  /**
18
20
  * Configures contract checking behavior.
19
21
  *
@@ -34,7 +36,7 @@ var Contracts = class _Contracts {
34
36
  * it is used instead of the standard logger, `console`.
35
37
  * This module uses only the `error` method of the `logger`. <br>
36
38
  * <br>
37
- * Note: If the value of a property is `undefined`, it is treated as unspecified.
39
+ * Note: If the value of a property is `undefined` or `null`, it is treated as unspecified.
38
40
  *
39
41
  * @param reset
40
42
  * If `true`, unspecified values ​​are saved to the settings as default values. <br>
@@ -144,9 +146,9 @@ var Contracts = class _Contracts {
144
146
  * Verifies an intermediate condition in debug mode only.
145
147
  *
146
148
  * Performs the same validation as VERIFY only when
147
- * DEBUG_MODE is enabled.
149
+ * `debug_mode`(internal state) is enabled.
148
150
  *
149
- * When DEBUG_MODE is disabled,
151
+ * When `debug_mode`(internal state) is disabled,
150
152
  * no validation is performed.
151
153
  *
152
154
  * Typical usage:
@@ -263,9 +265,9 @@ var Contracts = class _Contracts {
263
265
  * Checks a precondition in debug mode only.
264
266
  *
265
267
  * Performs the same validation as REQUIRE only when
266
- * DEBUG_MODE is enabled.
268
+ * `debug_mode`(internal state) is enabled.
267
269
  *
268
- * When DEBUG_MODE is disabled,
270
+ * When `debug_mode`(internal state) is disabled,
269
271
  * no validation is performed.
270
272
  *
271
273
  * Typical usage:
@@ -385,9 +387,9 @@ var Contracts = class _Contracts {
385
387
  * Checks a postcondition in debug mode only.
386
388
  *
387
389
  * Performs the same validation as ENSURE only when
388
- * DEBUG_MODE is enabled.
390
+ * `debug_mode`(internal state) is enabled.
389
391
  *
390
- * When DEBUG_MODE is disabled,
392
+ * When `debug_mode`(internal state) is disabled,
391
393
  * no validation is performed.
392
394
  *
393
395
  * Typical usage:
@@ -504,9 +506,9 @@ var Contracts = class _Contracts {
504
506
  * Checks an invariant condition in debug mode only.
505
507
  *
506
508
  * Performs the same validation as INVARIANT only when
507
- * DEBUG_MODE is enabled.
509
+ * `debug_mode`(internal state) is enabled.
508
510
  *
509
- * When DEBUG_MODE is disabled,
511
+ * When `debug_mode`(internal state) is disabled,
510
512
  * no validation is performed.
511
513
  *
512
514
  * Typical usage:
@@ -604,9 +606,6 @@ var Contracts = class _Contracts {
604
606
  static check(isOk, prefix = "CHECK", ngMsg = "", ErrorClass = Error, eParams, eProps) {
605
607
  if (eProps === void 0) {
606
608
  eProps = eParams ?? {};
607
- eParams = null;
608
- } else {
609
- eProps ??= {};
610
609
  }
611
610
  if (!isOk) {
612
611
  const msg = `[${prefix}] ${ngMsg ?? ""}`;
@@ -616,7 +615,7 @@ var Contracts = class _Contracts {
616
615
  throw err;
617
616
  }
618
617
  if (ngMsg) {
619
- _Contracts.getLogger().error(msg, eProps);
618
+ _Contracts.#getLogger().error(msg, eProps);
620
619
  }
621
620
  }
622
621
  return isOk;
@@ -624,10 +623,9 @@ var Contracts = class _Contracts {
624
623
  /**
625
624
  * Debug-only contract evaluation logic.
626
625
  *
627
- * Executes contract validation only when DEBUG_MODE
628
- * is enabled.
626
+ * Executes contract validation only when `debug_mode`(internal state) is enabled.
629
627
  *
630
- * When DEBUG_MODE is disabled,
628
+ * When `debug_mode`(internal state) is disabled,
631
629
  * this method returns the original condition value
632
630
  * without performing any validation.
633
631
  *
@@ -674,11 +672,10 @@ var Contracts = class _Contracts {
674
672
  ) : isOk;
675
673
  }
676
674
  /**
677
- * Get logger
678
- *
679
675
  * @internal
676
+ * Get logger
680
677
  */
681
- static getLogger() {
678
+ static #getLogger() {
682
679
  return _Contracts.#config.logger;
683
680
  }
684
681
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ayapapa-npm/contracts-js",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "A lightweight Design by Contract library for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": "ayapapa",
@@ -18,6 +18,7 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "build": "tsup src/index.ts --format esm,cjs --out-dir dist --clean --dts",
21
+ "build:doc": "npx typedoc && node scripts/rename-docs.cjs",
21
22
  "typecheck": "tsc --noEmit",
22
23
  "test": "vitest run",
23
24
  "test:debug": "vitest --inspect-brk --run",
@@ -25,9 +26,8 @@
25
26
  "test:ui": "vitest --ui",
26
27
  "coverage": "vitest run --coverage",
27
28
  "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"
29
+ "check": "npm run typecheck && npm run build && npm run build:doc && npm run coverage:ui",
30
+ "prepublishOnly": "npm run check"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^26.2.0",