sahab-utils 1.7.3 → 1.7.4
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/ts/utils.d.ts +7 -0
- package/dist/ts/utils.js +30 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/ts/utils.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
export declare function preventNaN(x?: number | string): number;
|
|
2
2
|
export declare const toFixed: (num: any) => string;
|
|
3
3
|
export declare const isEmpty: (text: any) => boolean;
|
|
4
|
+
export declare const compareVersions: (version1: string, version2: string) => number;
|
|
5
|
+
/**
|
|
6
|
+
* Fails open (no block) on a missing or malformed version — the admin UI that writes `minVer`
|
|
7
|
+
* validates the same shape before saving, so this is a second, independent guard against a hand
|
|
8
|
+
* edit (or a future write path) briefly bricking every install with a typo'd value.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldForceUpdate(minVer?: string, currentVersion?: string): boolean;
|
package/dist/ts/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEmpty = exports.toFixed = void 0;
|
|
3
|
+
exports.compareVersions = exports.isEmpty = exports.toFixed = void 0;
|
|
4
4
|
exports.preventNaN = preventNaN;
|
|
5
|
+
exports.shouldForceUpdate = shouldForceUpdate;
|
|
5
6
|
function preventNaN(x) {
|
|
6
7
|
if (x === undefined || x === null || isNaN(x)) {
|
|
7
8
|
return 0;
|
|
@@ -22,3 +23,31 @@ const isEmpty = (text) => {
|
|
|
22
23
|
return false;
|
|
23
24
|
};
|
|
24
25
|
exports.isEmpty = isEmpty;
|
|
26
|
+
const compareVersions = (version1, version2) => {
|
|
27
|
+
const v1Parts = version1.split('.').map(Number);
|
|
28
|
+
const v2Parts = version2.split('.').map(Number);
|
|
29
|
+
const maxLength = Math.max(v1Parts.length, v2Parts.length);
|
|
30
|
+
for (let i = 0; i < maxLength; i++) {
|
|
31
|
+
const v1Part = v1Parts[i] || 0;
|
|
32
|
+
const v2Part = v2Parts[i] || 0;
|
|
33
|
+
if (v1Part > v2Part)
|
|
34
|
+
return 1;
|
|
35
|
+
if (v1Part < v2Part)
|
|
36
|
+
return -1;
|
|
37
|
+
}
|
|
38
|
+
return 0;
|
|
39
|
+
};
|
|
40
|
+
exports.compareVersions = compareVersions;
|
|
41
|
+
const VERSION_RE = /^\d+(\.\d+)*$/;
|
|
42
|
+
/**
|
|
43
|
+
* Fails open (no block) on a missing or malformed version — the admin UI that writes `minVer`
|
|
44
|
+
* validates the same shape before saving, so this is a second, independent guard against a hand
|
|
45
|
+
* edit (or a future write path) briefly bricking every install with a typo'd value.
|
|
46
|
+
*/
|
|
47
|
+
function shouldForceUpdate(minVer, currentVersion) {
|
|
48
|
+
if (!minVer || !currentVersion)
|
|
49
|
+
return false;
|
|
50
|
+
if (!VERSION_RE.test(minVer) || !VERSION_RE.test(currentVersion))
|
|
51
|
+
return false;
|
|
52
|
+
return (0, exports.compareVersions)(minVer, currentVersion) > 0;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sahab-utils",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "This package contains types and utils functions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"deploy": "npm run build && npm publish",
|
|
10
|
-
"test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js"
|
|
10
|
+
"test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|