xdbc 1.0.93 → 1.0.95

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 (97) hide show
  1. package/.parcel-cache/bf96c58b6061a62a-BundleGraph +0 -0
  2. package/.parcel-cache/d7c812d65aeeac59-AssetGraph +0 -0
  3. package/.parcel-cache/data.mdb +0 -0
  4. package/.parcel-cache/e81759c1f106a17f-RequestGraph +0 -0
  5. package/.parcel-cache/fe0db3c4eb428be2-AssetGraph +0 -0
  6. package/.parcel-cache/lock.mdb +0 -0
  7. package/.parcel-cache/snapshot-e81759c1f106a17f.txt +4609 -0
  8. package/CODE_OF_CONDUCT.md +128 -0
  9. package/CONTRIBUTING.md +40 -0
  10. package/FUNDING.yml +3 -0
  11. package/LICENSE +21 -0
  12. package/README.md +96 -0
  13. package/SECURITY.md +36 -0
  14. package/Test.html +1 -1
  15. package/__tests__/DBC/AE.test.ts +62 -0
  16. package/__tests__/DBC/EQ.test.ts +13 -0
  17. package/__tests__/DBC/GREATER.test.ts +29 -0
  18. package/__tests__/DBC/INSTANCE.test.ts +13 -0
  19. package/__tests__/DBC/JSON.OP.test.ts +47 -0
  20. package/__tests__/DBC/JSON.Parse.test.ts +17 -0
  21. package/__tests__/DBC/OR.test.ts +14 -0
  22. package/__tests__/DBC/REGEX.test.ts +13 -0
  23. package/__tests__/DBC/TYPE.test.ts +13 -0
  24. package/babel.rc +12 -0
  25. package/dist/DBC/AE.js +39 -23
  26. package/dist/DBC/COMPARISON/GREATER.js +22 -0
  27. package/dist/DBC/COMPARISON.js +99 -0
  28. package/dist/DBC/EQ.js +21 -7
  29. package/dist/DBC/GREATER.js +19 -6
  30. package/dist/DBC/INSTANCE.js +22 -9
  31. package/dist/DBC/JSON.OP.js +19 -7
  32. package/dist/DBC/JSON.Parse.js +19 -7
  33. package/dist/DBC/OR.js +35 -23
  34. package/dist/DBC/REGEX.js +21 -9
  35. package/dist/DBC/TYPE.js +19 -7
  36. package/dist/DBC.js +112 -39
  37. package/dist/Demo.js +267 -0
  38. package/dist/bundle.js +1329 -0
  39. package/docs/.nojekyll +1 -0
  40. package/docs/assets/hierarchy.js +1 -0
  41. package/docs/assets/highlight.css +22 -0
  42. package/docs/assets/icons.js +18 -0
  43. package/docs/assets/icons.svg +1 -0
  44. package/docs/assets/main.js +60 -0
  45. package/docs/assets/navigation.js +1 -0
  46. package/docs/assets/search.js +1 -0
  47. package/docs/assets/style.css +1640 -0
  48. package/docs/classes/DBC.DBC.html +98 -0
  49. package/docs/classes/DBC_AE.AE.html +160 -0
  50. package/docs/classes/DBC_EQ.EQ.html +131 -0
  51. package/docs/classes/DBC_GREATER.GREATER.html +139 -0
  52. package/docs/classes/DBC_INSTANCE.INSTANCE.html +130 -0
  53. package/docs/classes/DBC_JSON.OP.JSON_OP.html +138 -0
  54. package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +129 -0
  55. package/docs/classes/DBC_OR.OR.html +137 -0
  56. package/docs/classes/DBC_REGEX.REGEX.html +136 -0
  57. package/docs/classes/DBC_TYPE.TYPE.html +130 -0
  58. package/docs/classes/Demo.Demo.html +14 -0
  59. package/docs/hierarchy.html +1 -0
  60. package/docs/index.html +1 -0
  61. package/docs/modules/DBC.html +1 -0
  62. package/docs/modules/DBC_AE.html +1 -0
  63. package/docs/modules/DBC_EQ.html +1 -0
  64. package/docs/modules/DBC_GREATER.html +1 -0
  65. package/docs/modules/DBC_INSTANCE.html +1 -0
  66. package/docs/modules/DBC_JSON.OP.html +1 -0
  67. package/docs/modules/DBC_JSON.Parse.html +1 -0
  68. package/docs/modules/DBC_OR.html +1 -0
  69. package/docs/modules/DBC_REGEX.html +1 -0
  70. package/docs/modules/DBC_TYPE.html +1 -0
  71. package/docs/modules/Demo.html +1 -0
  72. package/jest.config.ts +20 -0
  73. package/package.json +23 -5
  74. package/src/DBC/AE.ts +49 -24
  75. package/src/DBC/COMPARISON/GREATER.ts +38 -0
  76. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +38 -0
  77. package/src/DBC/COMPARISON/LESS.ts +38 -0
  78. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +38 -0
  79. package/src/DBC/COMPARISON.ts +150 -0
  80. package/src/DBC/EQ.ts +26 -8
  81. package/src/DBC/GREATER.ts +30 -7
  82. package/src/DBC/INSTANCE.ts +26 -10
  83. package/src/DBC/JSON.OP.ts +29 -8
  84. package/src/DBC/JSON.Parse.ts +24 -8
  85. package/src/DBC/OR.ts +42 -24
  86. package/src/DBC/REGEX.ts +26 -10
  87. package/src/DBC/TYPE.ts +24 -8
  88. package/src/DBC.ts +138 -46
  89. package/src/Demo.ts +211 -0
  90. package/tsconfig.json +3 -1
  91. package/typedoc.json +16 -0
  92. package/webpack.config.js +26 -0
  93. package/dist/DBC.min.js +0 -2
  94. package/dist/test.js +0 -110
  95. package/src/test.ts +0 -61
  96. package/test.js +0 -14
  97. package/test.ts +0 -11
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ Callari@WaXCode.net.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,40 @@
1
+ # Contributing to XDBC
2
+
3
+ Thank you for your interest in contributing to XDBC! We welcome contributions of all kinds, including bug reports, feature requests, code contributions, and documentation improvements.
4
+
5
+ ## Reporting Issues
6
+
7
+ If you find a bug or have a feature request, please open an issue on GitHub. When reporting a bug, please include:
8
+
9
+ * Steps to reproduce the bug
10
+ * Expected behavior
11
+ * Actual behavior
12
+ * Your operating system and browser (if applicable)
13
+
14
+ ## Contributing Code
15
+
16
+ 1. Fork the repository.
17
+ 2. Create a branch for your changes: `git checkout -b my-feature-branch`.
18
+ 3. Make your changes and commit them: `git commit -am 'Add some feature'`.
19
+ 4. Push your changes to your fork: `git push origin my-feature-branch`.
20
+ 5. Open a pull request on GitHub.
21
+
22
+ ## Code Style
23
+
24
+ Please follow the coding style guidelines used in the project. We use Biome, so please run it before submitting a pull request.
25
+
26
+ ## Documentation
27
+
28
+ We welcome improvements to the documentation. Please submit pull requests with your changes.
29
+
30
+ ## License
31
+
32
+ By contributing to XDBC, you agree that your contributions will be licensed under the MIT license.
33
+
34
+ ## Code of Conduct
35
+
36
+ Please review and abide by our [Code of Conduct](CODE_OF_CONDUCT.md).
37
+
38
+ ## Contact
39
+
40
+ If you have any questions, please mail to [XDBC@WaXcode.net](mailto:XDBC@WaXCode.net).
package/FUNDING.yml ADDED
@@ -0,0 +1,3 @@
1
+ github: CallariS
2
+ patreon: salvatorecallari
3
+ custom: ['https://paypal.me/CallariS']
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Salvatore Callari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # XDbC / e**X**plicit **D**esign **b**y **C**ontract™
2
+
3
+ Leverages the explicit nature of metadata to provide a **D**esign **b**y **C**ontract™ Framework in a precise and comprehensible manner.
4
+
5
+ | Do... | Instead Of |
6
+ |-------------------|------------------------------------------------------------|
7
+ | <pre>@DBC.ParamvalueProvider<br>public method(@AE.PRE([new REGEX(/^\.*XDBC.\*$/i)]) input : Array\<string>) {<br> ... <br>}</pre>|<pre>public method( input : Array\<string>) {<br> input.forEach(( element, index ) => {<br> console.assert(/^.\*XDBC.\*$/i.test(element),"inconsistent error message");<br> });<br><br> ...<br>}</pre>
8
+ | <pre>@REGEX.INVARIANT(/^.\*XDBC.\*$/i)<br>public field = "XDBC";</pre>|<pre>get field() : string { return ... }<br>set field( toSet : string ) {<br> console.assert(/^.\*XDBC.\*$/i.test(element),"Inconsistent error message"); <br><br> ...<br>}</pre>
9
+ | <pre>@REGEX.POST(/^XDBC$/i)<br>public method( input : unknown ) : string {<br> ...<br><br> return result ;<br>}</pre>|<pre>public method( input : unknown ) : string {<br> ...<br><br> if(!/^.\*XDBC.\*$/i.test(result) {<br> throw new Error("inconsistent error message");<br> }<br><br> return result ;<br>}</pre>
10
+ <pre>...and get consistent details about errors like: <code style = "background-color : beige ; color : red ;">[ XDBC Infringement [ From "method" in "MyClass": [ Parameter-value "+1d,+5d,-x10y" of the 1st parameter did not fulfill one of it's contracts: Violating-Arrayelement at index 2. Value has to comply to regular expression "/^(?i:(NOW)|([+-]\d+[dmy]))$/i"]]]</code></pre>
11
+
12
+ ## What is **D**esign **b**y **C**ontract™ ?
13
+ [**D**esign **b**y **C**ontract™ (DbC)](https://en.wikipedia.org/wiki/Design_by_contract) is a software development approach focused on defining precise and verifiable contracts between software components. These contracts specify the preconditions that must be true when calling a component (e.g., a function or method), the postconditions guaranteed after the component's execution, and the invariants that must hold true throughout the lifetime of an object or class.
14
+
15
+ ## Benefits of Design by Contract:
16
+
17
+ | Benefit | Description |
18
+ |-----------------------|------------------------------------------------------------|
19
+ | More Reliable | Early error detection through contract checking |
20
+ | More Maintainable | Clear responsibilities and expected behavior |
21
+ | Better Documentation | Contracts as living behavior descriptions |
22
+ | Easier Debugging | Error causes traceable through contract violations |
23
+
24
+
25
+ **DbC** improves software quality and maintainability by explicitly defining and verifying contract conditions.
26
+
27
+ ## What is the difference between DbC and Assertions ?
28
+
29
+ | Feature | DBC with Decorators | Assertions |
30
+ |------------------|----------------------------------------|---------------------------------------|
31
+ | Formality | Formal, explicit in definition | Informal, often within the body |
32
+ | Integration | Metadata | Built-in keyword |
33
+ | Features | Can be more feature-rich | Simple, primarily for error detection |
34
+ | Readability | Generally good, contracts are clear | Can become cluttered |
35
+ | Maintainability | Often better, contracts are localized | Can be harder to track and modify |
36
+ | Production | Contracts can be kept or disabled | Often disabled for performance |
37
+
38
+ ## Demo & API Documentation
39
+ Check out the **Demo.ts** to see some examples usages and the [API](https://callaris.github.io/XDBC/)'s documentation.
40
+
41
+ ## Installation
42
+
43
+ ```sh
44
+ npm install --save xdbc
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ As by now there're nine contracts that can be used:
50
+
51
+ - AE (*Each element of the value-array has to fulfill a certain set of contracts*)
52
+ - EQ (*Value has to be equal to a supplied reference value*)
53
+ - GREATER (*Value has to be greater than a supplied reference value*)
54
+ - INSTANCE (*Value has to be an instance of a supplied type*)
55
+ - JSON.OP (*Value has to contain certain properties of certain type*)
56
+ - JSON.Parse (*String-value has to be a parsable JSON*)
57
+ - OR (*At least one of a set of contracts has to be fulfilled*)
58
+ - REGEX (*Value has to be validated by a supplied regular expression*)
59
+ - TYPE (*Value has to be of a certain type*)
60
+
61
+ All of which expose a method **PRE**, **POST** and **INVARIANT** (*precondition, postcondition and invariant*).<br>
62
+ Import the classes to use from **xdbc**. If parameters shall be decorated with contracts import class **DBC** also. <br><br>
63
+
64
+ The **PRE**-Method can be used to decorate method-parameter: <code>public method(@REGEX.PRE(/XDBC.\*/g) input : string)</code>.<br>Whenever the method is invoked the value will be checked. Since parameter decorators don't have access to the parameter's value, the method itself must additionally be decorated with the **ParamvalueProvider**:<br>
65
+ <code>
66
+ @DBC.**ParamvalueProvider**<br>
67
+ public method(@REGEX.PRE(/XDBC.\*/g) input : string)
68
+ </code><br><br>
69
+ The **POST**-Method can be used to decorate a method:<br>
70
+ <code>
71
+ @EQ.POST(10)<br>
72
+ public method() { return 10 ;}<br></code>
73
+ Whenever the method returns, it's return-value will be checked.<br>
74
+
75
+ The **INVARIANT**-Method can be used to decorate fields:<br>
76
+ <code>
77
+ @REGEX.INVARIANT(/^a$/)<br>
78
+ public testProperty = "a";
79
+ </code><br>
80
+ Whenever the field is assigned a value and also when initialized, the new value will be checked. So there's no need to write a getter and setter just because there's is the necessity to perform checks on the value anymore.<br>
81
+
82
+ Certain contracts take other contracts as a parameter. For example the **AE** contract that applies a specified set of contracts on each element of the tagged object's value if it is an array or the object itself if it isn't: <code>@AE.PRE([new REGEX(/^(?i:(NOW)|([+-]\d+[dmy]))$/i, new GREATER(10,"length")])</code>.
83
+
84
+ With **PRE**, **POST** and **INVARIANT** decorators an optional **path** parameter may be specified. This parameter is a dotted path to a nested property of the tagged object that shall be checked instead of the tagged one. Thus **@DBC.INVARIANT([new REGEX(/^.$/)])** could also be defined as: **@DBC.INVARIANT([new EQ(1)],"length")**, that way demanding that the value to be set is a string with exactly one character.
85
+
86
+ Multiple instances of the class **DBC** with varying settings for e.g. reporting infringements may be instantiated. Which of these instances is used to report can be defined when either using **PRE**, **POST** or **INVARIANT** by defining their **dbc** parameter: **@DBC.INVARIANT([new EQ(1)],"length","MyVendor.MyDBCInstance")**, for example. The standard path (*WaXCode.DBC*) leads to an automatically created instance, that is generated when the Framework is imported.
87
+
88
+ Many contracts got further features like the **AE**-Contract that can check specific ranges within the tagged array or the **EQ**- and **GREATER**-Contract that can be inverted turning them into **not EQual**- or **LESS**-Contracts. Check out the [API](https://callaris.github.io/XDBC/) for details.
89
+
90
+ A **DBC**'s **warningSettings** & **infringementSettings** determine what happens on warnings and errors, whereas warnings are not implemented yet.
91
+
92
+ ## Contribution
93
+ Participation is highly valued and warmly welcomed. The ultimate goal is to create a tool that proves genuinely useful and empowers a wide range of developers to build more robust and reliable applications.
94
+
95
+
96
+
package/SECURITY.md ADDED
@@ -0,0 +1,36 @@
1
+ # Security Policy
2
+
3
+ ## Introduction
4
+
5
+ This security policy outlines our commitment to ensuring the security of XDBC and its users.
6
+
7
+ ## Reporting Vulnerabilities
8
+
9
+ To report a security vulnerability, please send an email to [Security@WaXCode.net](mailto:Security@WaXCode.net). Please include the following information:
10
+
11
+ * Description of the vulnerability
12
+ * Steps to reproduce
13
+ * Affected components/versions
14
+ * Potential impact
15
+
16
+ We will acknowledge your report within 24 - 48 hours and provide updates as we investigate.
17
+
18
+ ## Vulnerability Handling
19
+
20
+ We will triage and assess reported vulnerabilities, prioritizing them based on severity. We will develop and test patches, and communicate updates to users.
21
+
22
+ ## Disclosure Policy
23
+
24
+ We will publicly disclose vulnerabilities after a fix is available. We may provide credit to reporters with their consent.
25
+
26
+ ## Security Best Practices
27
+
28
+ We follow secure coding standards and regularly update dependencies.
29
+
30
+ ## Responsible Disclosure
31
+
32
+ We encourage responsible disclosure and will not take legal action against reporters.
33
+
34
+ ## Policy Updates
35
+
36
+ This policy will be reviewed and updated regularly.
package/Test.html CHANGED
@@ -8,7 +8,7 @@
8
8
  <body>
9
9
  <h1>Loading test.js Script</h1>
10
10
 
11
- <script src="dist/test.js" type="module"></script>
11
+ <script src="dist/bundle.js" type="module"></script>
12
12
  <script>
13
13
 
14
14
  </script>
@@ -0,0 +1,62 @@
1
+ import { AE } from "../../src/DBC/AE";
2
+ import { REGEX } from "../../src/DBC/REGEX";
3
+ import { EQ } from "../../src/DBC/EQ";
4
+
5
+ describe("AE", () => {
6
+ const ae = new AE([new REGEX(/^a$/), new EQ("a")]);
7
+
8
+ test("Should report no infringement with 'a' to check", () => {
9
+ expect(ae.check("a" as unknown as object)).toBe(true);
10
+ });
11
+
12
+ test("Should report no infringement with ['a','a','a'] to check", () => {
13
+ expect(ae.check(["a", "a", "a"] as unknown as object)).toBe(true);
14
+ });
15
+
16
+ test("Should report infringement with ['a','b','a'] to check", () => {
17
+ expect(typeof ae.check(["a", "b", "a"] as unknown as object)).toBe(
18
+ "string",
19
+ );
20
+ 1;
21
+ });
22
+
23
+ test("Should not report infringement with ['b','a','b'] to check when checking only index 1", () => {
24
+ expect(
25
+ new AE([new REGEX(/^a$/), new EQ("a")], 1).check([
26
+ "b",
27
+ "a",
28
+ "b",
29
+ ] as unknown as object),
30
+ ).toBe(true);
31
+ });
32
+
33
+ test("Should report infringement with ['b','a','b'] to check when checking from index 1 on", () => {
34
+ expect(
35
+ typeof new AE([new REGEX(/^a$/), new EQ("a")], 1, -1).check([
36
+ "b",
37
+ "a",
38
+ "b",
39
+ ] as unknown as object),
40
+ ).toBe("string");
41
+ });
42
+
43
+ test("Should not report infringement with ['a','a','b'] to check when checking from index 0 to 1", () => {
44
+ expect(
45
+ new AE([new REGEX(/^a$/), new EQ("a")], 0, 1).check([
46
+ "a",
47
+ "a",
48
+ "b",
49
+ ] as unknown as object),
50
+ ).toBe(true);
51
+ });
52
+
53
+ test("Should report infringement with ['a','a','b'] to check when checking from index 0 to 1 case of EQ-Condition", () => {
54
+ expect(
55
+ typeof new AE([new REGEX(/^a$/), new EQ("b")], 0, 1).check([
56
+ "a",
57
+ "a",
58
+ "b",
59
+ ] as unknown as object),
60
+ ).toBe("string");
61
+ });
62
+ });
@@ -0,0 +1,13 @@
1
+ import { EQ } from "../../src/DBC/EQ";
2
+
3
+ describe("EQ", () => {
4
+ const eq = new EQ("b");
5
+
6
+ test("Should not report infringement with 'b' to check", () => {
7
+ expect(eq.check("b")).toBe(true);
8
+ });
9
+
10
+ test("Should report infringement with 'c' to check", () => {
11
+ expect(typeof eq.check("c")).toBe("string");
12
+ });
13
+ });
@@ -0,0 +1,29 @@
1
+ import { GREATER } from "../../src/DBC/GREATER";
2
+
3
+ describe("GREATER", () => {
4
+ const greater = new GREATER(1);
5
+
6
+ test("Should not report infringement with '2' to check", () => {
7
+ expect(greater.check(2)).toBe(true);
8
+ });
9
+
10
+ test("Should report infringement with '0' to check", () => {
11
+ expect(typeof greater.check(0)).toBe("string");
12
+ });
13
+
14
+ test("Should report infringement with '0' to check", () => {
15
+ expect(typeof greater.check(0)).toBe("string");
16
+ });
17
+
18
+ test("Should not report infringement with '1' and '1' to check since equality is now permitted", () => {
19
+ expect(new GREATER(1, true).check(1)).toBe(true);
20
+ });
21
+
22
+ test("Should not report infringement with '2' and '1' to check since inverting the result is now on", () => {
23
+ expect(new GREATER(1, true, true).check(1)).toBe(true);
24
+ });
25
+
26
+ test("Should not report infringement with 'undefined' and 'undefined' to check", () => {
27
+ expect(new GREATER(undefined).check(undefined)).toBe(true);
28
+ });
29
+ });
@@ -0,0 +1,13 @@
1
+ import { INSTANCE } from "../../src/DBC/INSTANCE";
2
+
3
+ describe("INSTANCE", () => {
4
+ const instance = new INSTANCE(RegExp);
5
+
6
+ test("Should not report infringement with '/a/g' to check", () => {
7
+ expect(instance.check(/a/g)).toBe(true);
8
+ });
9
+
10
+ test("Should report infringement with 'd' to check", () => {
11
+ expect(typeof instance.check("d")).toBe("string");
12
+ });
13
+ });
@@ -0,0 +1,47 @@
1
+ import { JSON_OP } from "../../src/DBC/JSON.OP";
2
+
3
+ describe("JSON.OP", () => {
4
+ const jsonOP = new JSON_OP([
5
+ { name: "x", type: "string" },
6
+ { name: "y", type: "number" },
7
+ ]);
8
+
9
+ test("Should not report infringement with { x: 'x', y: 1 } to check", () => {
10
+ expect(jsonOP.check({ x: "x", y: 1 })).toBe(true);
11
+ });
12
+
13
+ test("Should report infringement with { x: 1 } to check", () => {
14
+ expect(typeof jsonOP.check({ x: 1 })).toBe("string");
15
+ });
16
+
17
+ test("Should not report infringement with [{ x: 'x', y: 1 },{ x: 'xs', y: 2 }] to check in 'checkElements' mode", () => {
18
+ expect(
19
+ new JSON_OP(
20
+ [
21
+ { name: "x", type: "string" },
22
+ { name: "y", type: "number" },
23
+ ],
24
+ true,
25
+ ).check([
26
+ { x: "x", y: 1 },
27
+ { x: "xs", y: 2 },
28
+ ]),
29
+ ).toBe(true);
30
+ });
31
+
32
+ test("Should report infringement with [{ x: 'x', y: 1 },{ x: 'xs', y: 2 }] to check with no 'checkElements' mode", () => {
33
+ expect(
34
+ typeof new JSON_OP([
35
+ { name: "x", type: "string" },
36
+ { name: "y", type: "number" },
37
+ ]).check([
38
+ { x: "x", y: 1 },
39
+ { x: "xs", y: 2 },
40
+ ]),
41
+ ).toBe("string");
42
+ });
43
+
44
+ test("Should report infringement with [] to check", () => {
45
+ expect(typeof jsonOP.check([])).toBe("string");
46
+ });
47
+ });
@@ -0,0 +1,17 @@
1
+ import { JSON_Parse } from "../../src/DBC/JSON.Parse";
2
+
3
+ describe("EQ", () => {
4
+ const jsonParse = new JSON_Parse();
5
+
6
+ test(`Should not report infringement with '{"d":"o"}' to check`, () => {
7
+ expect(jsonParse.check('{"d":"o"}')).toBe(true);
8
+ });
9
+
10
+ test(`Should report infringement with '{"d":o}' to check`, () => {
11
+ expect(typeof jsonParse.check('{"d":o}')).toBe("string");
12
+ });
13
+
14
+ test(`Should not report infringement or throw "referenceException" with '{"d":"o"}' to check and "receptor" not defined`, () => {
15
+ expect(new JSON_Parse().check('{"d":"o"}')).toBe(true);
16
+ });
17
+ });
@@ -0,0 +1,14 @@
1
+ import { OR } from "../../src/DBC/OR";
2
+ import { EQ } from "../../src/DBC/EQ";
3
+
4
+ describe("EQ", () => {
5
+ const or = new OR([new EQ("a"), new EQ("b")]);
6
+
7
+ test("Should not report infringement with 'b' to check", () => {
8
+ expect(or.check("b")).toBe(true);
9
+ });
10
+
11
+ test("Should report infringement with 'c' to check", () => {
12
+ expect(typeof or.check("c")).toBe("string");
13
+ });
14
+ });
@@ -0,0 +1,13 @@
1
+ import { REGEX } from "../../src/DBC/REGEX";
2
+
3
+ describe("EQ", () => {
4
+ const regex = new REGEX(/^a$/);
5
+
6
+ test("Should not report infringement with 'a' to check", () => {
7
+ expect(regex.check("a")).toBe(true);
8
+ });
9
+
10
+ test("Should report infringement with 'c' to check", () => {
11
+ expect(typeof regex.check("c")).toBe("string");
12
+ });
13
+ });
@@ -0,0 +1,13 @@
1
+ import { TYPE } from "../../src/DBC/TYPE";
2
+
3
+ describe("EQ", () => {
4
+ const type = new TYPE("string");
5
+
6
+ test("Should not report infringement with 'a' to check", () => {
7
+ expect(type.check("a")).toBe(true);
8
+ });
9
+
10
+ test("Should report infringement with 1 to check", () => {
11
+ expect(typeof type.check(1)).toBe("string");
12
+ });
13
+ });
package/babel.rc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": "current"
8
+ }
9
+ }
10
+ ]
11
+ ]
12
+ }