@bgord/tools 1.2.15 → 1.2.16

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.
@@ -7,7 +7,12 @@ export declare class PackageVersion {
7
7
  static fromVersionString(candidate: string): PackageVersion;
8
8
  static fromVersionStringSafe(candidate: PackageVersionSchemaType): PackageVersion;
9
9
  static fromString(candidate: string): PackageVersion;
10
+ private compareTo;
11
+ equals(another: PackageVersion): boolean;
12
+ isGreaterThan(another: PackageVersion): boolean;
10
13
  isGreaterThanOrEqual(another: PackageVersion): boolean;
14
+ isSmallerThan(another: PackageVersion): boolean;
15
+ isSmallerThanOrEqual(another: PackageVersion): boolean;
11
16
  toString(): string;
12
17
  toJSON(): {
13
18
  major: number;
@@ -19,16 +19,35 @@ export class PackageVersion {
19
19
  const version = PackageVersionSchema.parse(`v${candidate}`);
20
20
  return new PackageVersion(version.major, version.minor, version.patch);
21
21
  }
22
- isGreaterThanOrEqual(another) {
22
+ compareTo(another) {
23
23
  if (this.major > another.major)
24
- return true;
24
+ return 1;
25
25
  if (this.major < another.major)
26
- return false;
26
+ return -1;
27
27
  if (this.minor > another.minor)
28
- return true;
28
+ return 1;
29
29
  if (this.minor < another.minor)
30
- return false;
31
- return this.patch >= another.patch;
30
+ return -1;
31
+ if (this.patch > another.patch)
32
+ return 1;
33
+ if (this.patch < another.patch)
34
+ return -1;
35
+ return 0;
36
+ }
37
+ equals(another) {
38
+ return this.compareTo(another) === 0;
39
+ }
40
+ isGreaterThan(another) {
41
+ return this.compareTo(another) === 1;
42
+ }
43
+ isGreaterThanOrEqual(another) {
44
+ return this.compareTo(another) !== -1;
45
+ }
46
+ isSmallerThan(another) {
47
+ return this.compareTo(another) === -1;
48
+ }
49
+ isSmallerThanOrEqual(another) {
50
+ return this.compareTo(another) !== 1;
32
51
  }
33
52
  toString() {
34
53
  return `${this.major}.${this.minor}.${this.patch}`;
@@ -8,7 +8,7 @@ export declare enum WeekdayFormatterEnum {
8
8
  ZERO_BASED_NUMBER = "ZERO_BASED_NUMBER"
9
9
  }
10
10
  export declare const WeekdayValueError: {
11
- readonly Invalid: "weekday.invalid";
11
+ Invalid: string;
12
12
  };
13
13
  export declare const WeekdayFormatters: Record<WeekdayFormatterEnum, WeekdayFormatter>;
14
14
  export declare class Weekday {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -28,7 +28,7 @@
28
28
  "@types/bun": "1.3.5",
29
29
  "@types/mime-types": "3.0.1",
30
30
  "cspell": "9.4.0",
31
- "knip": "5.79.0",
31
+ "knip": "5.80.0",
32
32
  "lefthook": "2.0.13",
33
33
  "lockfile-lint": "4.14.1",
34
34
  "only-allow": "1.2.2",
@@ -19,4 +19,4 @@ export const HourFormatters: Record<HourFormatterEnum, HourFormatter> = {
19
19
  },
20
20
  TWELVE_HOURS: (value) => (value % 12 || 12).toString().padStart(2, "0"),
21
21
  TWELVE_HOURS_WO_PADDING: (value) => (value % 12 || 12).toString(),
22
- } as const;
22
+ };
@@ -23,14 +23,37 @@ export class PackageVersion {
23
23
  return new PackageVersion(version.major, version.minor, version.patch);
24
24
  }
25
25
 
26
+ private compareTo(another: PackageVersion): -1 | 0 | 1 {
27
+ if (this.major > another.major) return 1;
28
+ if (this.major < another.major) return -1;
29
+
30
+ if (this.minor > another.minor) return 1;
31
+ if (this.minor < another.minor) return -1;
32
+
33
+ if (this.patch > another.patch) return 1;
34
+ if (this.patch < another.patch) return -1;
35
+
36
+ return 0;
37
+ }
38
+
39
+ equals(another: PackageVersion): boolean {
40
+ return this.compareTo(another) === 0;
41
+ }
42
+
43
+ isGreaterThan(another: PackageVersion): boolean {
44
+ return this.compareTo(another) === 1;
45
+ }
46
+
26
47
  isGreaterThanOrEqual(another: PackageVersion): boolean {
27
- if (this.major > another.major) return true;
28
- if (this.major < another.major) return false;
48
+ return this.compareTo(another) !== -1;
49
+ }
29
50
 
30
- if (this.minor > another.minor) return true;
31
- if (this.minor < another.minor) return false;
51
+ isSmallerThan(another: PackageVersion): boolean {
52
+ return this.compareTo(another) === -1;
53
+ }
32
54
 
33
- return this.patch >= another.patch;
55
+ isSmallerThanOrEqual(another: PackageVersion): boolean {
56
+ return this.compareTo(another) !== 1;
34
57
  }
35
58
 
36
59
  toString(): string {
package/src/weekday.vo.ts CHANGED
@@ -10,7 +10,7 @@ export enum WeekdayFormatterEnum {
10
10
  ZERO_BASED_NUMBER = "ZERO_BASED_NUMBER", // Sunday=0 ... Saturday=6 (JS)
11
11
  }
12
12
 
13
- export const WeekdayValueError = { Invalid: "weekday.invalid" } as const;
13
+ export const WeekdayValueError = { Invalid: "weekday.invalid" };
14
14
 
15
15
  const FULL_NAMES: readonly string[] = [
16
16
  "Sunday",