@cqse/commons 0.0.1-beta.1 → 0.0.1-beta.25

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 (64) hide show
  1. package/lib/index.js +5 -1
  2. package/package.json +4 -1
  3. package/.yarnrc +0 -2
  4. package/babel.config.js +0 -4
  5. package/coverage/Contract.js.html +0 -299
  6. package/coverage/Contract.ts.html +0 -329
  7. package/coverage/Exceptions.js.html +0 -236
  8. package/coverage/Exceptions.ts.html +0 -233
  9. package/coverage/base.css +0 -224
  10. package/coverage/block-navigation.js +0 -79
  11. package/coverage/clover.xml +0 -64
  12. package/coverage/coverage-final.json +0 -4
  13. package/coverage/favicon.png +0 -0
  14. package/coverage/index.html +0 -141
  15. package/coverage/index.js.html +0 -125
  16. package/coverage/index.ts.html +0 -89
  17. package/coverage/lcov-report/Contract.js.html +0 -299
  18. package/coverage/lcov-report/Contract.ts.html +0 -329
  19. package/coverage/lcov-report/Exceptions.js.html +0 -236
  20. package/coverage/lcov-report/Exceptions.ts.html +0 -233
  21. package/coverage/lcov-report/base.css +0 -224
  22. package/coverage/lcov-report/block-navigation.js +0 -79
  23. package/coverage/lcov-report/favicon.png +0 -0
  24. package/coverage/lcov-report/index.html +0 -141
  25. package/coverage/lcov-report/index.js.html +0 -125
  26. package/coverage/lcov-report/index.ts.html +0 -89
  27. package/coverage/lcov-report/prettify.css +0 -1
  28. package/coverage/lcov-report/prettify.js +0 -2
  29. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  30. package/coverage/lcov-report/sorter.js +0 -170
  31. package/coverage/lcov.info +0 -138
  32. package/coverage/prettify.css +0 -1
  33. package/coverage/prettify.js +0 -2
  34. package/coverage/sort-arrow-sprite.png +0 -0
  35. package/coverage/sorter.js +0 -170
  36. package/jest.config.js +0 -7
  37. package/lib/Contract.d.ts +0 -39
  38. package/lib/Contract.d.ts.map +0 -1
  39. package/lib/Contract.js +0 -74
  40. package/lib/Contract.js.map +0 -1
  41. package/lib/Exceptions.d.ts +0 -27
  42. package/lib/Exceptions.d.ts.map +0 -1
  43. package/lib/Exceptions.js +0 -44
  44. package/lib/Exceptions.js.map +0 -1
  45. package/lib/Strings.d.ts +0 -10
  46. package/lib/Strings.d.ts.map +0 -1
  47. package/lib/Strings.js +0 -19
  48. package/lib/Strings.js.map +0 -1
  49. package/lib/index.d.ts +0 -5
  50. package/lib/index.d.ts.map +0 -1
  51. package/lib/index.js.map +0 -1
  52. package/src/Contract.js +0 -73
  53. package/src/Contract.ts +0 -83
  54. package/src/Exceptions.js +0 -52
  55. package/src/Exceptions.ts +0 -39
  56. package/src/Strings.ts +0 -14
  57. package/src/index.js +0 -15
  58. package/src/index.ts +0 -4
  59. package/test/Contract.test.js +0 -29
  60. package/test/Contract.test.ts +0 -31
  61. package/test/Exceptions.test.js +0 -50
  62. package/test/Exceptions.test.ts +0 -56
  63. package/tsconfig.json +0 -23
  64. package/tsconfig.tsbuildinfo +0 -1
@@ -1,170 +0,0 @@
1
- /* eslint-disable */
2
- var addSorting = (function() {
3
- 'use strict';
4
- var cols,
5
- currentSort = {
6
- index: 0,
7
- desc: false
8
- };
9
-
10
- // returns the summary table element
11
- function getTable() {
12
- return document.querySelector('.coverage-summary');
13
- }
14
- // returns the thead element of the summary table
15
- function getTableHeader() {
16
- return getTable().querySelector('thead tr');
17
- }
18
- // returns the tbody element of the summary table
19
- function getTableBody() {
20
- return getTable().querySelector('tbody');
21
- }
22
- // returns the th element for nth column
23
- function getNthColumn(n) {
24
- return getTableHeader().querySelectorAll('th')[n];
25
- }
26
-
27
- // loads all columns
28
- function loadColumns() {
29
- var colNodes = getTableHeader().querySelectorAll('th'),
30
- colNode,
31
- cols = [],
32
- col,
33
- i;
34
-
35
- for (i = 0; i < colNodes.length; i += 1) {
36
- colNode = colNodes[i];
37
- col = {
38
- key: colNode.getAttribute('data-col'),
39
- sortable: !colNode.getAttribute('data-nosort'),
40
- type: colNode.getAttribute('data-type') || 'string'
41
- };
42
- cols.push(col);
43
- if (col.sortable) {
44
- col.defaultDescSort = col.type === 'number';
45
- colNode.innerHTML =
46
- colNode.innerHTML + '<span class="sorter"></span>';
47
- }
48
- }
49
- return cols;
50
- }
51
- // attaches a data attribute to every tr element with an object
52
- // of data values keyed by column name
53
- function loadRowData(tableRow) {
54
- var tableCols = tableRow.querySelectorAll('td'),
55
- colNode,
56
- col,
57
- data = {},
58
- i,
59
- val;
60
- for (i = 0; i < tableCols.length; i += 1) {
61
- colNode = tableCols[i];
62
- col = cols[i];
63
- val = colNode.getAttribute('data-value');
64
- if (col.type === 'number') {
65
- val = Number(val);
66
- }
67
- data[col.key] = val;
68
- }
69
- return data;
70
- }
71
- // loads all row data
72
- function loadData() {
73
- var rows = getTableBody().querySelectorAll('tr'),
74
- i;
75
-
76
- for (i = 0; i < rows.length; i += 1) {
77
- rows[i].data = loadRowData(rows[i]);
78
- }
79
- }
80
- // sorts the table using the data for the ith column
81
- function sortByIndex(index, desc) {
82
- var key = cols[index].key,
83
- sorter = function(a, b) {
84
- a = a.data[key];
85
- b = b.data[key];
86
- return a < b ? -1 : a > b ? 1 : 0;
87
- },
88
- finalSorter = sorter,
89
- tableBody = document.querySelector('.coverage-summary tbody'),
90
- rowNodes = tableBody.querySelectorAll('tr'),
91
- rows = [],
92
- i;
93
-
94
- if (desc) {
95
- finalSorter = function(a, b) {
96
- return -1 * sorter(a, b);
97
- };
98
- }
99
-
100
- for (i = 0; i < rowNodes.length; i += 1) {
101
- rows.push(rowNodes[i]);
102
- tableBody.removeChild(rowNodes[i]);
103
- }
104
-
105
- rows.sort(finalSorter);
106
-
107
- for (i = 0; i < rows.length; i += 1) {
108
- tableBody.appendChild(rows[i]);
109
- }
110
- }
111
- // removes sort indicators for current column being sorted
112
- function removeSortIndicators() {
113
- var col = getNthColumn(currentSort.index),
114
- cls = col.className;
115
-
116
- cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
117
- col.className = cls;
118
- }
119
- // adds sort indicators for current column being sorted
120
- function addSortIndicators() {
121
- getNthColumn(currentSort.index).className += currentSort.desc
122
- ? ' sorted-desc'
123
- : ' sorted';
124
- }
125
- // adds event listeners for all sorter widgets
126
- function enableUI() {
127
- var i,
128
- el,
129
- ithSorter = function ithSorter(i) {
130
- var col = cols[i];
131
-
132
- return function() {
133
- var desc = col.defaultDescSort;
134
-
135
- if (currentSort.index === i) {
136
- desc = !currentSort.desc;
137
- }
138
- sortByIndex(i, desc);
139
- removeSortIndicators();
140
- currentSort.index = i;
141
- currentSort.desc = desc;
142
- addSortIndicators();
143
- };
144
- };
145
- for (i = 0; i < cols.length; i += 1) {
146
- if (cols[i].sortable) {
147
- // add the click event handler on the th so users
148
- // dont have to click on those tiny arrows
149
- el = getNthColumn(i).querySelector('.sorter').parentElement;
150
- if (el.addEventListener) {
151
- el.addEventListener('click', ithSorter(i));
152
- } else {
153
- el.attachEvent('onclick', ithSorter(i));
154
- }
155
- }
156
- }
157
- }
158
- // adds sorting functionality to the UI
159
- return function() {
160
- if (!getTable()) {
161
- return;
162
- }
163
- cols = loadColumns();
164
- loadData();
165
- addSortIndicators();
166
- enableUI();
167
- };
168
- })();
169
-
170
- window.addEventListener('load', addSorting);
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- transformIgnorePatterns: ['node_modules'],
6
- testMatch: ['**/test/**/*.test.ts']
7
- };
package/lib/Contract.d.ts DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * Nullable type.
3
- */
4
- export declare type Nullable<Type> = Type | null;
5
- /**
6
- * Methods to express and check code contracts.
7
- */
8
- export declare class Contract {
9
- /**
10
- * The given predicate `condition` has to be satisfied.
11
- *
12
- * @param condition Condition predicate (boolean value)
13
- * @param message Message describing the condition.
14
- */
15
- static require(condition: boolean, message?: string): void;
16
- /**
17
- * Require that the given argument `obj` is defined.
18
- *
19
- * @param obj The object that has to be defined.
20
- * @param message The message describing this requirement.
21
- */
22
- static requireDefined<E>(obj: Nullable<E>, message?: string): E;
23
- /**
24
- * Require that the given string is not empty.
25
- *
26
- * @param text The string to check.
27
- * @param message The message that describes the requirement.
28
- */
29
- static requireNonEmpty(text: string, message?: string): string;
30
- /**
31
- * Require that the string adheres to a particular pattern.
32
- *
33
- * @param text The string to check.
34
- * @param regexp The regular expression to satisfy.
35
- * @param message The message describing the requirement.
36
- */
37
- static requireStringPattern(text: string, regexp: string, message?: string): string;
38
- }
39
- //# sourceMappingURL=Contract.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Contract.d.ts","sourceRoot":"","sources":["../src/Contract.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,QAAQ,CAAC,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC;AAEzC;;GAEG;AACH,qBAAa,QAAQ;IACpB;;;;;OAKG;WACW,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAMjE;;;;;OAKG;WACW,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC;IAqBtE;;;;;OAKG;WACW,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IASrE;;;;;;OAMG;WACW,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;CAU1F"}
package/lib/Contract.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Contract = void 0;
4
- const Exceptions_1 = require("./Exceptions");
5
- /**
6
- * Methods to express and check code contracts.
7
- */
8
- class Contract {
9
- /**
10
- * The given predicate `condition` has to be satisfied.
11
- *
12
- * @param condition Condition predicate (boolean value)
13
- * @param message Message describing the condition.
14
- */
15
- static require(condition, message) {
16
- if (!condition) {
17
- throw new Exceptions_1.IllegalArgumentException(message);
18
- }
19
- }
20
- /**
21
- * Require that the given argument `obj` is defined.
22
- *
23
- * @param obj The object that has to be defined.
24
- * @param message The message describing this requirement.
25
- */
26
- static requireDefined(obj, message) {
27
- if (obj) {
28
- return obj;
29
- }
30
- if (typeof obj === 'number' || typeof obj === 'boolean') {
31
- return obj;
32
- }
33
- if (typeof obj === 'string' || obj instanceof String) {
34
- // Deal with the case `obj === ""`
35
- return obj;
36
- }
37
- if (message) {
38
- throw new Exceptions_1.IllegalArgumentException(message);
39
- }
40
- else {
41
- throw new Exceptions_1.IllegalArgumentException('Reference must be defined.');
42
- }
43
- }
44
- /**
45
- * Require that the given string is not empty.
46
- *
47
- * @param text The string to check.
48
- * @param message The message that describes the requirement.
49
- */
50
- static requireNonEmpty(text, message) {
51
- this.requireDefined(text);
52
- if (text.length === 0) {
53
- throw new Exceptions_1.IllegalArgumentException(message);
54
- }
55
- return text;
56
- }
57
- /**
58
- * Require that the string adheres to a particular pattern.
59
- *
60
- * @param text The string to check.
61
- * @param regexp The regular expression to satisfy.
62
- * @param message The message describing the requirement.
63
- */
64
- static requireStringPattern(text, regexp, message) {
65
- this.requireDefined(text);
66
- this.requireDefined(regexp);
67
- if (!text.match(regexp)) {
68
- throw new Exceptions_1.IllegalArgumentException(message);
69
- }
70
- return text;
71
- }
72
- }
73
- exports.Contract = Contract;
74
- //# sourceMappingURL=Contract.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Contract.js","sourceRoot":"","sources":["../src/Contract.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAOxD;;GAEG;AACH,MAAa,QAAQ;IACpB;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,SAAkB,EAAE,OAAgB;QACzD,IAAI,CAAC,SAAS,EAAE;YACf,MAAM,IAAI,qCAAwB,CAAC,OAAO,CAAC,CAAC;SAC5C;IACF,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAI,GAAgB,EAAE,OAAgB;QACjE,IAAI,GAAG,EAAE;YACR,OAAO,GAAG,CAAC;SACX;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;YACxD,OAAO,GAAG,CAAC;SACX;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,MAAM,EAAE;YACrD,kCAAkC;YAClC,OAAO,GAAG,CAAC;SACX;QAED,IAAI,OAAO,EAAE;YACZ,MAAM,IAAI,qCAAwB,CAAC,OAAO,CAAC,CAAC;SAC5C;aAAM;YACN,MAAM,IAAI,qCAAwB,CAAC,4BAA4B,CAAC,CAAC;SACjE;IACF,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,IAAY,EAAE,OAAgB;QAC3D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,MAAM,IAAI,qCAAwB,CAAC,OAAO,CAAC,CAAC;SAC5C;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,oBAAoB,CAAC,IAAY,EAAE,MAAc,EAAE,OAAgB;QAChF,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAE5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YACxB,MAAM,IAAI,qCAAwB,CAAC,OAAO,CAAC,CAAC;SAC5C;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAxED,4BAwEC"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Excepting signaling that there is functionality that is supposed
3
- * to be implemented in case the exception is thrown.
4
- *
5
- * This is helpful for writing prototypes and not yet handling all possible cases.
6
- */
7
- export declare class ImplementMeException extends Error {
8
- private readonly _implementMeFor;
9
- constructor(implementMeFor?: string);
10
- get message(): string;
11
- }
12
- /**
13
- * Exception signaling that the application is in an invalid state.
14
- */
15
- export declare class IllegalStateException extends Error {
16
- }
17
- /**
18
- * Exception signaling that an invalid argument has been passed for a parameter.
19
- */
20
- export declare class IllegalArgumentException extends Error {
21
- }
22
- /**
23
- * Exception signaling that a component is mis-configured.
24
- */
25
- export declare class InvalidConfigurationException extends Error {
26
- }
27
- //# sourceMappingURL=Exceptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Exceptions.d.ts","sourceRoot":"","sources":["../src/Exceptions.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;gBAEvC,cAAc,CAAC,EAAE,MAAM;IAKnC,IAAI,OAAO,IAAI,MAAM,CAMpB;CACD;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AAEnD;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;CAAG;AAEtD;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;CAAG"}
package/lib/Exceptions.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidConfigurationException = exports.IllegalArgumentException = exports.IllegalStateException = exports.ImplementMeException = void 0;
4
- const typescript_optional_1 = require("typescript-optional");
5
- /**
6
- * Excepting signaling that there is functionality that is supposed
7
- * to be implemented in case the exception is thrown.
8
- *
9
- * This is helpful for writing prototypes and not yet handling all possible cases.
10
- */
11
- class ImplementMeException extends Error {
12
- constructor(implementMeFor) {
13
- super('Implement me!');
14
- this._implementMeFor = typescript_optional_1.Optional.ofNullable(implementMeFor);
15
- }
16
- get message() {
17
- if (this._implementMeFor.isPresent()) {
18
- return `Implement me for: ${this._implementMeFor.get()}`;
19
- }
20
- else {
21
- return 'Implement me!';
22
- }
23
- }
24
- }
25
- exports.ImplementMeException = ImplementMeException;
26
- /**
27
- * Exception signaling that the application is in an invalid state.
28
- */
29
- class IllegalStateException extends Error {
30
- }
31
- exports.IllegalStateException = IllegalStateException;
32
- /**
33
- * Exception signaling that an invalid argument has been passed for a parameter.
34
- */
35
- class IllegalArgumentException extends Error {
36
- }
37
- exports.IllegalArgumentException = IllegalArgumentException;
38
- /**
39
- * Exception signaling that a component is mis-configured.
40
- */
41
- class InvalidConfigurationException extends Error {
42
- }
43
- exports.InvalidConfigurationException = InvalidConfigurationException;
44
- //# sourceMappingURL=Exceptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Exceptions.js","sourceRoot":"","sources":["../src/Exceptions.ts"],"names":[],"mappings":";;;AAAA,6DAA+C;AAE/C;;;;;GAKG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAG9C,YAAY,cAAuB;QAClC,KAAK,CAAC,eAAe,CAAC,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,8BAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,OAAO;QACV,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,EAAE;YACrC,OAAO,qBAAqB,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC;SACzD;aAAM;YACN,OAAO,eAAe,CAAC;SACvB;IACF,CAAC;CACD;AAfD,oDAeC;AAED;;GAEG;AACH,MAAa,qBAAsB,SAAQ,KAAK;CAAG;AAAnD,sDAAmD;AAEnD;;GAEG;AACH,MAAa,wBAAyB,SAAQ,KAAK;CAAG;AAAtD,4DAAsD;AAEtD;;GAEG;AACH,MAAa,6BAA8B,SAAQ,KAAK;CAAG;AAA3D,sEAA2D"}
package/lib/Strings.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Remove the given prefix, if present, from the given string.
3
- *
4
- * @param prefix - The prefix to remove.
5
- * @param removeFrom - The string to remove the prefix from.
6
- *
7
- * @returns a new string where the prefix is removed.
8
- */
9
- export declare function removePrefix(prefix: string, removeFrom: string): string;
10
- //# sourceMappingURL=Strings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Strings.d.ts","sourceRoot":"","sources":["../src/Strings.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAKvE"}
package/lib/Strings.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removePrefix = void 0;
4
- /**
5
- * Remove the given prefix, if present, from the given string.
6
- *
7
- * @param prefix - The prefix to remove.
8
- * @param removeFrom - The string to remove the prefix from.
9
- *
10
- * @returns a new string where the prefix is removed.
11
- */
12
- function removePrefix(prefix, removeFrom) {
13
- if (removeFrom.startsWith(prefix)) {
14
- return removeFrom.substring(prefix.length);
15
- }
16
- return removeFrom;
17
- }
18
- exports.removePrefix = removePrefix;
19
- //# sourceMappingURL=Strings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Strings.js","sourceRoot":"","sources":["../src/Strings.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,MAAc,EAAE,UAAkB;IAC9D,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAClC,OAAO,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KAC3C;IACD,OAAO,UAAU,CAAC;AACnB,CAAC;AALD,oCAKC"}
package/lib/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /** Exports of this Node package / module */
2
- export * from './Contract';
3
- export * from './Exceptions';
4
- export * from './Strings';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA4C;AAC5C,6CAA2B;AAC3B,+CAA6B;AAC7B,4CAA0B"}
package/src/Contract.js DELETED
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Contract = void 0;
4
- const Exceptions_1 = require("./Exceptions");
5
- /**
6
- * Methods to express and check code contracts.
7
- */
8
- class Contract {
9
- /**
10
- * The given predicate `condition` has to be satisfied.
11
- *
12
- * @param condition Condition predicate (boolean value)
13
- * @param msg Message describing the condition.
14
- */
15
- static require(condition, msg) {
16
- if (!condition) {
17
- throw new Exceptions_1.IllegalArgumentException(msg);
18
- }
19
- }
20
- /**
21
- * Require that the given argument `obj` is defined.
22
- *
23
- * @param obj The object that has to be defined.
24
- * @param message The message describing this requirement.
25
- */
26
- static requireDefined(obj, message) {
27
- if (obj) {
28
- return obj;
29
- }
30
- if (typeof obj === 'number' || typeof obj === 'boolean') {
31
- return obj;
32
- }
33
- if (typeof obj === 'string' || obj instanceof String) {
34
- // Deal with the case `obj === ""`
35
- return obj;
36
- }
37
- if (message) {
38
- throw new Exceptions_1.IllegalArgumentException(message);
39
- }
40
- else {
41
- throw new Exceptions_1.IllegalArgumentException('Reference must not be undefined.');
42
- }
43
- }
44
- /**
45
- * Require that the given string is not empty.
46
- *
47
- * @param str The string to check.
48
- * @param msg The message that describes the requirement.
49
- */
50
- static requireNonEmpty(str, msg) {
51
- this.requireDefined(str);
52
- if (str.length === 0) {
53
- throw new Exceptions_1.IllegalArgumentException(msg);
54
- }
55
- return str;
56
- }
57
- /**
58
- * Require that the string adheres to a particular pattern.
59
- *
60
- * @param str The string to check.
61
- * @param regexp The regular expression to satisfy.
62
- * @param msg The message describing the requirement.
63
- */
64
- static requireStringPattern(str, regexp, msg) {
65
- this.requireDefined(str);
66
- this.requireDefined(regexp);
67
- if (!str.match(regexp)) {
68
- throw new Exceptions_1.IllegalArgumentException(msg);
69
- }
70
- return str;
71
- }
72
- }
73
- exports.Contract = Contract;
package/src/Contract.ts DELETED
@@ -1,83 +0,0 @@
1
- import { IllegalArgumentException } from './Exceptions';
2
-
3
- /**
4
- * Nullable type.
5
- */
6
- export type Nullable<Type> = Type | null;
7
-
8
- /**
9
- * Methods to express and check code contracts.
10
- */
11
- export class Contract {
12
- /**
13
- * The given predicate `condition` has to be satisfied.
14
- *
15
- * @param condition Condition predicate (boolean value)
16
- * @param message Message describing the condition.
17
- */
18
- public static require(condition: boolean, message?: string): void {
19
- if (!condition) {
20
- throw new IllegalArgumentException(message);
21
- }
22
- }
23
-
24
- /**
25
- * Require that the given argument `obj` is defined.
26
- *
27
- * @param obj The object that has to be defined.
28
- * @param message The message describing this requirement.
29
- */
30
- public static requireDefined<E>(obj: Nullable<E>, message?: string): E {
31
- if (obj) {
32
- return obj;
33
- }
34
-
35
- if (typeof obj === 'number' || typeof obj === 'boolean') {
36
- return obj;
37
- }
38
-
39
- if (typeof obj === 'string' || obj instanceof String) {
40
- // Deal with the case `obj === ""`
41
- return obj;
42
- }
43
-
44
- if (message) {
45
- throw new IllegalArgumentException(message);
46
- } else {
47
- throw new IllegalArgumentException('Reference must be defined.');
48
- }
49
- }
50
-
51
- /**
52
- * Require that the given string is not empty.
53
- *
54
- * @param text The string to check.
55
- * @param message The message that describes the requirement.
56
- */
57
- public static requireNonEmpty(text: string, message?: string): string {
58
- this.requireDefined(text);
59
- if (text.length === 0) {
60
- throw new IllegalArgumentException(message);
61
- }
62
-
63
- return text;
64
- }
65
-
66
- /**
67
- * Require that the string adheres to a particular pattern.
68
- *
69
- * @param text The string to check.
70
- * @param regexp The regular expression to satisfy.
71
- * @param message The message describing the requirement.
72
- */
73
- public static requireStringPattern(text: string, regexp: string, message?: string): string {
74
- this.requireDefined(text);
75
- this.requireDefined(regexp);
76
-
77
- if (!text.match(regexp)) {
78
- throw new IllegalArgumentException(message);
79
- }
80
-
81
- return text;
82
- }
83
- }
package/src/Exceptions.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidConfigurationException = exports.IllegalArgumentException = exports.IllegalStateException = exports.ImplementMeException = void 0;
4
- const typescript_optional_1 = require("typescript-optional");
5
- /**
6
- * Excepting signaling that there is functionality that is supposed
7
- * to be implemented in case the exception is thrown.
8
- *
9
- * This is helpful for writing prototypes and not yet handling all possible cases.
10
- */
11
- class ImplementMeException extends Error {
12
- constructor(implementMeFor) {
13
- super('Implement me!');
14
- this._implementMeFor = typescript_optional_1.Optional.ofNullable(implementMeFor);
15
- }
16
- get message() {
17
- if (this._implementMeFor.isPresent()) {
18
- return `Implement me for: ${this._implementMeFor.get()}`;
19
- }
20
- else {
21
- return 'Implement me!';
22
- }
23
- }
24
- }
25
- exports.ImplementMeException = ImplementMeException;
26
- /**
27
- * Exception signaling that the application is in an invalid state.
28
- */
29
- class IllegalStateException extends Error {
30
- constructor(message) {
31
- super(message);
32
- }
33
- }
34
- exports.IllegalStateException = IllegalStateException;
35
- /**
36
- * Exception signaling that an invalid argument has been passed for a parameter.
37
- */
38
- class IllegalArgumentException extends Error {
39
- constructor(message) {
40
- super(message);
41
- }
42
- }
43
- exports.IllegalArgumentException = IllegalArgumentException;
44
- /**
45
- * Exception signaling that a component is misconfigured.
46
- */
47
- class InvalidConfigurationException extends Error {
48
- constructor(message) {
49
- super(message);
50
- }
51
- }
52
- exports.InvalidConfigurationException = InvalidConfigurationException;
package/src/Exceptions.ts DELETED
@@ -1,39 +0,0 @@
1
- import { Optional } from 'typescript-optional';
2
-
3
- /**
4
- * Excepting signaling that there is functionality that is supposed
5
- * to be implemented in case the exception is thrown.
6
- *
7
- * This is helpful for writing prototypes and not yet handling all possible cases.
8
- */
9
- export class ImplementMeException extends Error {
10
- private readonly _implementMeFor: Optional<string>;
11
-
12
- constructor(implementMeFor?: string) {
13
- super('Implement me!');
14
- this._implementMeFor = Optional.ofNullable(implementMeFor);
15
- }
16
-
17
- get message(): string {
18
- if (this._implementMeFor.isPresent()) {
19
- return `Implement me for: ${this._implementMeFor.get()}`;
20
- } else {
21
- return 'Implement me!';
22
- }
23
- }
24
- }
25
-
26
- /**
27
- * Exception signaling that the application is in an invalid state.
28
- */
29
- export class IllegalStateException extends Error {}
30
-
31
- /**
32
- * Exception signaling that an invalid argument has been passed for a parameter.
33
- */
34
- export class IllegalArgumentException extends Error {}
35
-
36
- /**
37
- * Exception signaling that a component is mis-configured.
38
- */
39
- export class InvalidConfigurationException extends Error {}