@nu-art/ts-common 0.204.143 → 0.204.145
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/package.json +1 -1
- package/utils/version-tools.d.ts +5 -0
- package/utils/version-tools.js +14 -4
package/package.json
CHANGED
package/utils/version-tools.d.ts
CHANGED
|
@@ -8,3 +8,8 @@
|
|
|
8
8
|
* 1 if second is greater
|
|
9
9
|
*/
|
|
10
10
|
export declare function compareVersions(firstVersion: string, secondVersion: string): 0 | 1 | -1;
|
|
11
|
+
/**
|
|
12
|
+
* Expects a version of XXX.YYY.ZZZ and nothing else
|
|
13
|
+
* @param version
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateVersion(version: string): string | undefined;
|
package/utils/version-tools.js
CHANGED
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.compareVersions = compareVersions;
|
|
21
|
+
exports.validateVersion = validateVersion;
|
|
21
22
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
23
|
+
const validator_core_1 = require("../validator/validator-core");
|
|
24
|
+
const validators_1 = require("../validator/validators");
|
|
22
25
|
/**
|
|
23
26
|
*
|
|
24
27
|
* @param firstVersion a version
|
|
@@ -30,11 +33,11 @@ const exceptions_1 = require("../core/exceptions/exceptions");
|
|
|
30
33
|
*/
|
|
31
34
|
function compareVersions(firstVersion, secondVersion) {
|
|
32
35
|
if (!firstVersion)
|
|
33
|
-
throw new exceptions_1.BadImplementationException(
|
|
36
|
+
throw new exceptions_1.BadImplementationException('First version is undefined');
|
|
34
37
|
if (!secondVersion)
|
|
35
|
-
throw new exceptions_1.BadImplementationException(
|
|
36
|
-
const firstVersionAsArray = firstVersion.split(
|
|
37
|
-
const secondVersionAsArray = secondVersion.split(
|
|
38
|
+
throw new exceptions_1.BadImplementationException('Second version is undefined');
|
|
39
|
+
const firstVersionAsArray = firstVersion.split('\.');
|
|
40
|
+
const secondVersionAsArray = secondVersion.split('\.');
|
|
38
41
|
for (let i = 0; i < firstVersionAsArray.length; i++) {
|
|
39
42
|
const secondVal = +secondVersionAsArray[i];
|
|
40
43
|
const firstVal = +firstVersionAsArray[i];
|
|
@@ -47,3 +50,10 @@ function compareVersions(firstVersion, secondVersion) {
|
|
|
47
50
|
}
|
|
48
51
|
return 0;
|
|
49
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Expects a version of XXX.YYY.ZZZ and nothing else
|
|
55
|
+
* @param version
|
|
56
|
+
*/
|
|
57
|
+
function validateVersion(version) {
|
|
58
|
+
return (0, validator_core_1.tsValidateResult)(version, validators_1.tsValidateVersion);
|
|
59
|
+
}
|