@bgord/tools 1.2.4 → 1.2.6

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.
@@ -1,4 +1,5 @@
1
1
  import { type DurationMsType } from "./duration-ms.vo";
2
+ import type { MultiplicationFactorType } from "./multiplication-factor.vo";
2
3
  export declare class Duration {
3
4
  private static readonly rounding;
4
5
  private readonly internal;
@@ -25,5 +26,6 @@ export declare class Duration {
25
26
  equals(other: Duration): boolean;
26
27
  add(another: Duration): Duration;
27
28
  subtract(another: Duration): Duration;
29
+ times(factor: MultiplicationFactorType): Duration;
28
30
  toAbsolute(): Duration;
29
31
  }
@@ -1,5 +1,5 @@
1
1
  import { DurationMs } from "./duration-ms.vo";
2
- import { RoundToDecimal } from "./rounding.adapter";
2
+ import { RoundToDecimal, RoundToNearest } from "./rounding.adapter";
3
3
  export class Duration {
4
4
  static rounding = new RoundToDecimal(2);
5
5
  internal;
@@ -62,6 +62,10 @@ export class Duration {
62
62
  subtract(another) {
63
63
  return Duration.Ms(this.internal - another.internal);
64
64
  }
65
+ times(factor) {
66
+ const rounding = new RoundToNearest();
67
+ return Duration.Ms(rounding.round(this.internal * factor));
68
+ }
65
69
  toAbsolute() {
66
70
  return Duration.Ms(Math.abs(this.internal));
67
71
  }
package/dist/index.d.ts CHANGED
@@ -79,7 +79,6 @@ export * from "./rounding.port";
79
79
  export * from "./size.vo";
80
80
  export * from "./size-bytes.vo";
81
81
  export * from "./slug.service";
82
- export * from "./stopwatch.service";
83
82
  export * from "./sum.service";
84
83
  export * from "./thousands-separator.service";
85
84
  export * from "./time-zone-offset-value.vo";
package/dist/index.js CHANGED
@@ -79,7 +79,6 @@ export * from "./rounding.port";
79
79
  export * from "./size.vo";
80
80
  export * from "./size-bytes.vo";
81
81
  export * from "./slug.service";
82
- export * from "./stopwatch.service";
83
82
  export * from "./sum.service";
84
83
  export * from "./thousands-separator.service";
85
84
  export * from "./time-zone-offset-value.vo";
@@ -1 +1 @@
1
- {"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock-format.service.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/distance-value.vo.ts","../src/distance.vo.ts","../src/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/email.vo.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-affix.vo.ts","../src/filename-from-string.vo.ts","../src/filename.vo.ts","../src/height-milimiters.vo.ts","../src/height.vo.ts","../src/hour-format.service.ts","../src/hour-schema.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute-schema.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding.adapter.ts","../src/rounding.port.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/slug.service.ts","../src/stopwatch.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/timestamp-value.vo.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/url-with-slash.vo.ts","../src/url-without-slash.vo.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/weight-grams.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.3"}
1
+ {"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock-format.service.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/distance-value.vo.ts","../src/distance.vo.ts","../src/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/email.vo.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-affix.vo.ts","../src/filename-from-string.vo.ts","../src/filename.vo.ts","../src/height-milimiters.vo.ts","../src/height.vo.ts","../src/hour-format.service.ts","../src/hour-schema.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute-schema.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding.adapter.ts","../src/rounding.port.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/slug.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/timestamp-value.vo.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/url-with-slash.vo.ts","../src/url-without-slash.vo.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/weight-grams.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -28,7 +28,7 @@
28
28
  "@types/mime-types": "3.0.1",
29
29
  "cspell": "9.4.0",
30
30
  "knip": "5.77.1",
31
- "lefthook": "2.0.12",
31
+ "lefthook": "2.0.13",
32
32
  "lockfile-lint": "4.14.1",
33
33
  "only-allow": "1.2.2",
34
34
  "shellcheck": "4.1.0",
package/readme.md CHANGED
@@ -104,7 +104,6 @@ src/
104
104
  ├── size-bytes.vo.ts
105
105
  ├── size.vo.ts
106
106
  ├── slug.service.ts
107
- ├── stopwatch.service.ts
108
107
  ├── sum.service.ts
109
108
  ├── thousands-separator.service.ts
110
109
  ├── time-zone-offset-value.vo.ts
@@ -1,5 +1,6 @@
1
1
  import { DurationMs, type DurationMsType } from "./duration-ms.vo";
2
- import { RoundToDecimal } from "./rounding.adapter";
2
+ import type { MultiplicationFactorType } from "./multiplication-factor.vo";
3
+ import { RoundToDecimal, RoundToNearest } from "./rounding.adapter";
3
4
  import type { RoundingPort } from "./rounding.port";
4
5
 
5
6
  export class Duration {
@@ -73,6 +74,12 @@ export class Duration {
73
74
  return Duration.Ms(this.internal - another.internal);
74
75
  }
75
76
 
77
+ times(factor: MultiplicationFactorType): Duration {
78
+ const rounding = new RoundToNearest();
79
+
80
+ return Duration.Ms(rounding.round(this.internal * factor));
81
+ }
82
+
76
83
  toAbsolute(): Duration {
77
84
  return Duration.Ms(Math.abs(this.internal));
78
85
  }
package/src/index.ts CHANGED
@@ -79,7 +79,6 @@ export * from "./rounding.port";
79
79
  export * from "./size.vo";
80
80
  export * from "./size-bytes.vo";
81
81
  export * from "./slug.service";
82
- export * from "./stopwatch.service";
83
82
  export * from "./sum.service";
84
83
  export * from "./thousands-separator.service";
85
84
  export * from "./time-zone-offset-value.vo";
@@ -1,12 +0,0 @@
1
- import type { Duration } from "./duration.service";
2
- import { Timestamp } from "./timestamp.vo";
3
- export declare const StopwatchError: {
4
- AlreadyStopped: string;
5
- };
6
- export type StopwatchResultType = Duration;
7
- export declare class Stopwatch {
8
- private readonly start;
9
- private state;
10
- constructor(start: Timestamp);
11
- stop(): StopwatchResultType;
12
- }
@@ -1,20 +0,0 @@
1
- import { Timestamp } from "./timestamp.vo";
2
- export const StopwatchError = { AlreadyStopped: "stopwatch.already.stopped" };
3
- var StopwatchState;
4
- (function (StopwatchState) {
5
- StopwatchState["started"] = "started";
6
- StopwatchState["stopped"] = "stopped";
7
- })(StopwatchState || (StopwatchState = {}));
8
- export class Stopwatch {
9
- start;
10
- state = StopwatchState.started;
11
- constructor(start) {
12
- this.start = start;
13
- }
14
- stop() {
15
- if (this.state === StopwatchState.stopped)
16
- throw new Error(StopwatchError.AlreadyStopped);
17
- this.state = StopwatchState.stopped;
18
- return Timestamp.fromNumber(Date.now()).difference(this.start);
19
- }
20
- }
@@ -1,25 +0,0 @@
1
- import type { Duration } from "./duration.service";
2
- import { Timestamp } from "./timestamp.vo";
3
-
4
- export const StopwatchError = { AlreadyStopped: "stopwatch.already.stopped" };
5
-
6
- enum StopwatchState {
7
- started = "started",
8
- stopped = "stopped",
9
- }
10
-
11
- export type StopwatchResultType = Duration;
12
-
13
- export class Stopwatch {
14
- private state: StopwatchState = StopwatchState.started;
15
-
16
- constructor(private readonly start: Timestamp) {}
17
-
18
- stop(): StopwatchResultType {
19
- if (this.state === StopwatchState.stopped) throw new Error(StopwatchError.AlreadyStopped);
20
-
21
- this.state = StopwatchState.stopped;
22
-
23
- return Timestamp.fromNumber(Date.now()).difference(this.start);
24
- }
25
- }