@cqse/commons 0.0.1-beta.25 → 0.0.1-beta.29
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/lib/Contract.d.ts +39 -0
- package/lib/Contract.d.ts.map +1 -0
- package/lib/Contract.js +74 -0
- package/lib/Contract.js.map +1 -0
- package/lib/Exceptions.d.ts +27 -0
- package/lib/Exceptions.d.ts.map +1 -0
- package/lib/Exceptions.js +44 -0
- package/lib/Exceptions.js.map +1 -0
- package/lib/Strings.d.ts +10 -0
- package/lib/Strings.d.ts.map +1 -0
- package/lib/Strings.js +19 -0
- package/lib/Strings.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,39 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA4C;AAC5C,6CAA2B;AAC3B,+CAA6B;AAC7B,4CAA0B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cqse/commons",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.29",
|
|
4
4
|
"description": "A collection of generic functionality for TypeScript projects.",
|
|
5
5
|
"author": "CQSE GmbH",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"url": "https://github.com/cqse/teamscale-javascript-profiler.git"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist/**/*"
|
|
13
|
+
"dist/**/*",
|
|
14
|
+
"lib/**/*"
|
|
14
15
|
],
|
|
15
16
|
"scripts": {
|
|
16
17
|
"build": "tsc",
|