@bgord/tools 0.12.26 → 0.13.0
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/clock.vo.d.ts +4 -2
- package/dist/clock.vo.js +7 -1
- package/dist/hour.vo.d.ts +2 -0
- package/dist/hour.vo.js +11 -11
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/mean.service.js +1 -2
- package/dist/mime.vo.js +2 -4
- package/dist/min-max-scaler.service.js +5 -10
- package/dist/minute.vo.d.ts +1 -0
- package/dist/minute.vo.js +8 -10
- package/dist/money.vo.js +2 -4
- package/dist/outlier-detector.service.js +1 -2
- package/dist/percentage.service.js +1 -2
- package/dist/population-standard-deviation.service.js +1 -2
- package/dist/random.service.js +4 -8
- package/dist/reordering.service.js +3 -6
- package/dist/revision.vo.js +2 -4
- package/dist/simple-linear-regression.service.js +6 -12
- package/dist/stepper.service.js +2 -4
- package/dist/stopwatch.service.js +1 -2
- package/dist/timezone.vo.js +2 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/visually-unambiguous-characters-generator.service.js +1 -4
- package/dist/weekday.vo.d.ts +40 -0
- package/dist/weekday.vo.js +95 -0
- package/dist/z-score.service.js +1 -2
- package/package.json +1 -1
- package/readme.md +1 -2
- package/src/clock.vo.ts +9 -2
- package/src/hour.vo.ts +15 -13
- package/src/index.ts +1 -2
- package/src/mean.service.ts +1 -3
- package/src/mime.vo.ts +2 -9
- package/src/min-max-scaler.service.ts +5 -16
- package/src/minute.vo.ts +9 -15
- package/src/money.vo.ts +2 -6
- package/src/outlier-detector.service.ts +1 -3
- package/src/percentage.service.ts +1 -5
- package/src/population-standard-deviation.service.ts +1 -3
- package/src/random.service.ts +5 -19
- package/src/rate-limiter.service.ts +0 -3
- package/src/reordering.service.ts +5 -13
- package/src/revision.vo.ts +2 -6
- package/src/simple-linear-regression.service.ts +6 -19
- package/src/stepper.service.ts +2 -8
- package/src/stopwatch.service.ts +1 -3
- package/src/timezone.vo.ts +2 -8
- package/src/visually-unambiguous-characters-generator.service.ts +1 -4
- package/src/weekday.vo.ts +113 -0
- package/src/z-score.service.ts +1 -3
- package/dist/build-version.vo.d.ts +0 -3
- package/dist/build-version.vo.js +0 -2
- package/dist/filter.vo.d.ts +0 -17
- package/dist/filter.vo.js +0 -22
- package/src/build-version.vo.ts +0 -5
- package/src/filter.vo.ts +0 -38
package/dist/clock.vo.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Hour } from "./hour.vo";
|
|
2
|
+
import { Minute } from "./minute.vo";
|
|
3
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
3
4
|
export type ClockFormatter = (hour: Hour, minute: Minute) => string;
|
|
4
5
|
declare enum ClockFormatterEnum {
|
|
5
6
|
TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
|
|
@@ -11,6 +12,7 @@ export declare class Clock {
|
|
|
11
12
|
private readonly minute;
|
|
12
13
|
private readonly formatter;
|
|
13
14
|
constructor(hour: Hour, minute: Minute, formatter?: ClockFormatter);
|
|
15
|
+
static fromUtcTimestamp(timestamp: TimestampType, formatter?: ClockFormatter): Clock;
|
|
14
16
|
get(formatter?: ClockFormatter): {
|
|
15
17
|
raw: {
|
|
16
18
|
hour: number;
|
package/dist/clock.vo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { HourFormatters } from "./hour.vo";
|
|
1
|
+
import { Hour, HourFormatters } from "./hour.vo";
|
|
2
|
+
import { Minute } from "./minute.vo";
|
|
2
3
|
var ClockFormatterEnum;
|
|
3
4
|
(function (ClockFormatterEnum) {
|
|
4
5
|
ClockFormatterEnum["TWENTY_FOUR_HOURS"] = "TWENTY_FOUR_HOURS";
|
|
@@ -17,6 +18,11 @@ export class Clock {
|
|
|
17
18
|
this.minute = minute;
|
|
18
19
|
this.formatter = formatter ?? ClockFormatters.TWENTY_FOUR_HOURS;
|
|
19
20
|
}
|
|
21
|
+
static fromUtcTimestamp(timestamp, formatter) {
|
|
22
|
+
const hour = Hour.fromUtcTimestamp(timestamp);
|
|
23
|
+
const minute = Minute.fromUtcTimestamp(timestamp);
|
|
24
|
+
return new Clock(hour, minute, formatter);
|
|
25
|
+
}
|
|
20
26
|
get(formatter) {
|
|
21
27
|
const format = formatter ?? this.formatter;
|
|
22
28
|
return {
|
package/dist/hour.vo.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
1
2
|
export type HourFormatter = (value: Hour["value"]) => string;
|
|
2
3
|
export declare enum HourFormatterEnum {
|
|
3
4
|
TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
|
|
@@ -20,5 +21,6 @@ export declare class Hour {
|
|
|
20
21
|
equals(another: Hour): boolean;
|
|
21
22
|
isAfter(another: Hour): boolean;
|
|
22
23
|
isBefore(another: Hour): boolean;
|
|
24
|
+
static fromUtcTimestamp(timestamp: TimestampType, formatter?: HourFormatter): Hour;
|
|
23
25
|
static list(formatter?: HourFormatter): Hour[];
|
|
24
26
|
}
|
package/dist/hour.vo.js
CHANGED
|
@@ -10,12 +10,11 @@ export const HourFormatters = {
|
|
|
10
10
|
TWENTY_FOUR_HOURS: (value) => value.toString().padStart(2, "0"),
|
|
11
11
|
TWENTY_FOUR_HOURS_WO_PADDING: (value) => value.toString(),
|
|
12
12
|
AM_PM: (value) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return `${value.toString()} p.m.`;
|
|
13
|
+
const twelveHour = value % 12 || 12;
|
|
14
|
+
return `${twelveHour.toString()} ${value < 12 ? "a.m." : "p.m."}`;
|
|
16
15
|
},
|
|
17
|
-
TWELVE_HOURS: (value) => (value % 12).toString().padStart(2, "0"),
|
|
18
|
-
TWELVE_HOURS_WO_PADDING: (value) => (value % 12).toString(),
|
|
16
|
+
TWELVE_HOURS: (value) => (value % 12 || 12).toString().padStart(2, "0"),
|
|
17
|
+
TWELVE_HOURS_WO_PADDING: (value) => (value % 12 || 12).toString(),
|
|
19
18
|
};
|
|
20
19
|
export class Hour {
|
|
21
20
|
value;
|
|
@@ -23,15 +22,12 @@ export class Hour {
|
|
|
23
22
|
static ZERO = new Hour(0);
|
|
24
23
|
static MAX = new Hour(23);
|
|
25
24
|
constructor(candidate, formatter) {
|
|
26
|
-
if (!Number.isInteger(candidate))
|
|
25
|
+
if (!Number.isInteger(candidate))
|
|
27
26
|
throw new Error("Invalid hour");
|
|
28
|
-
|
|
29
|
-
if (candidate < 0) {
|
|
27
|
+
if (candidate < 0)
|
|
30
28
|
throw new Error("Invalid hour");
|
|
31
|
-
|
|
32
|
-
if (candidate >= 24) {
|
|
29
|
+
if (candidate >= 24)
|
|
33
30
|
throw new Error("Invalid hour");
|
|
34
|
-
}
|
|
35
31
|
this.value = candidate;
|
|
36
32
|
this.formatter = formatter ?? HourFormatters.TWENTY_FOUR_HOURS;
|
|
37
33
|
}
|
|
@@ -48,6 +44,10 @@ export class Hour {
|
|
|
48
44
|
isBefore(another) {
|
|
49
45
|
return this.value < another.get().raw;
|
|
50
46
|
}
|
|
47
|
+
static fromUtcTimestamp(timestamp, formatter) {
|
|
48
|
+
const hours = new Date(timestamp).getUTCHours();
|
|
49
|
+
return new Hour(hours, formatter);
|
|
50
|
+
}
|
|
51
51
|
static list(formatter) {
|
|
52
52
|
return Array.from({ length: 24 }).map((_, index) => new Hour(index, formatter));
|
|
53
53
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from "./api-key.vo";
|
|
2
2
|
export * from "./basename.vo";
|
|
3
|
-
export * from "./build-version.vo";
|
|
4
3
|
export * from "./clock.vo";
|
|
5
4
|
export * from "./date-calculator.service";
|
|
6
5
|
export * from "./date-formatter.service";
|
|
@@ -21,7 +20,6 @@ export * from "./file-path-relative-schema.vo";
|
|
|
21
20
|
export * from "./filename.vo";
|
|
22
21
|
export * from "./filename-from-string.vo";
|
|
23
22
|
export * from "./filename-suffix.vo";
|
|
24
|
-
export * from "./filter.vo";
|
|
25
23
|
export * from "./hour.vo";
|
|
26
24
|
export * from "./iban.vo";
|
|
27
25
|
export * from "./iban-mask.service";
|
|
@@ -63,4 +61,5 @@ export * from "./ts-utils";
|
|
|
63
61
|
export * from "./visually-unambiguous-characters-generator.service";
|
|
64
62
|
export * from "./week.vo";
|
|
65
63
|
export * from "./week-iso-id.vo";
|
|
64
|
+
export * from "./weekday.vo";
|
|
66
65
|
export * from "./z-score.service";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from "./api-key.vo";
|
|
2
2
|
export * from "./basename.vo";
|
|
3
|
-
export * from "./build-version.vo";
|
|
4
3
|
export * from "./clock.vo";
|
|
5
4
|
export * from "./date-calculator.service";
|
|
6
5
|
export * from "./date-formatter.service";
|
|
@@ -21,7 +20,6 @@ export * from "./file-path-relative-schema.vo";
|
|
|
21
20
|
export * from "./filename.vo";
|
|
22
21
|
export * from "./filename-from-string.vo";
|
|
23
22
|
export * from "./filename-suffix.vo";
|
|
24
|
-
export * from "./filter.vo";
|
|
25
23
|
export * from "./hour.vo";
|
|
26
24
|
export * from "./iban.vo";
|
|
27
25
|
export * from "./iban-mask.service";
|
|
@@ -63,4 +61,5 @@ export * from "./ts-utils";
|
|
|
63
61
|
export * from "./visually-unambiguous-characters-generator.service";
|
|
64
62
|
export * from "./week.vo";
|
|
65
63
|
export * from "./week-iso-id.vo";
|
|
64
|
+
export * from "./weekday.vo";
|
|
66
65
|
export * from "./z-score.service";
|
package/dist/mean.service.js
CHANGED
|
@@ -2,9 +2,8 @@ import { RoundToDecimal } from "./rounding.service";
|
|
|
2
2
|
import { Sum } from "./sum.service";
|
|
3
3
|
export class Mean {
|
|
4
4
|
static calculate(values, rounding = new RoundToDecimal(2)) {
|
|
5
|
-
if (values.length === 0)
|
|
5
|
+
if (values.length === 0)
|
|
6
6
|
throw new Error("Values should not be empty");
|
|
7
|
-
}
|
|
8
7
|
const mean = Sum.of(values) / values.length;
|
|
9
8
|
return rounding.round(mean);
|
|
10
9
|
}
|
package/dist/mime.vo.js
CHANGED
|
@@ -6,12 +6,10 @@ export class Mime {
|
|
|
6
6
|
subtype;
|
|
7
7
|
constructor(value) {
|
|
8
8
|
const [type, subtype] = value.split("/");
|
|
9
|
-
if (typeof type !== "string" || type.length === 0)
|
|
9
|
+
if (typeof type !== "string" || type.length === 0)
|
|
10
10
|
throw new InvalidMimeError();
|
|
11
|
-
|
|
12
|
-
if (typeof subtype !== "string" || subtype.length === 0) {
|
|
11
|
+
if (typeof subtype !== "string" || subtype.length === 0)
|
|
13
12
|
throw new InvalidMimeError();
|
|
14
|
-
}
|
|
15
13
|
this.raw = value;
|
|
16
14
|
this.type = type;
|
|
17
15
|
this.subtype = subtype;
|
|
@@ -9,12 +9,10 @@ export class MinMaxScaler {
|
|
|
9
9
|
const rounding = config.rounding ?? new RoundToDecimal(2);
|
|
10
10
|
const lower = config.bound?.lower ?? 0;
|
|
11
11
|
const upper = config.bound?.upper ?? 1;
|
|
12
|
-
if (config.max - config.min < 0)
|
|
12
|
+
if (config.max - config.min < 0)
|
|
13
13
|
throw new Error("Invalid MinMaxScaler min-max config");
|
|
14
|
-
|
|
15
|
-
if (upper - lower <= 0) {
|
|
14
|
+
if (upper - lower <= 0)
|
|
16
15
|
throw new Error("Invalid MinMaxScaler bound config");
|
|
17
|
-
}
|
|
18
16
|
this.rounding = rounding;
|
|
19
17
|
this.min = config.min;
|
|
20
18
|
this.max = config.max;
|
|
@@ -23,9 +21,8 @@ export class MinMaxScaler {
|
|
|
23
21
|
}
|
|
24
22
|
scale(value) {
|
|
25
23
|
const { min, max, lower, upper } = this;
|
|
26
|
-
if (value < min || value > max)
|
|
24
|
+
if (value < min || value > max)
|
|
27
25
|
throw new Error("Value out of min/max range");
|
|
28
|
-
}
|
|
29
26
|
if (min === max)
|
|
30
27
|
return {
|
|
31
28
|
original: value,
|
|
@@ -43,9 +40,8 @@ export class MinMaxScaler {
|
|
|
43
40
|
}
|
|
44
41
|
descale(scaled) {
|
|
45
42
|
const { min, max, lower, upper } = this;
|
|
46
|
-
if (scaled < lower || scaled > upper)
|
|
43
|
+
if (scaled < lower || scaled > upper)
|
|
47
44
|
throw new Error("Scaled value out of bounds");
|
|
48
|
-
}
|
|
49
45
|
const result = ((scaled - lower) / (upper - lower)) * (max - min) + min;
|
|
50
46
|
return {
|
|
51
47
|
original: this.rounding.round(result),
|
|
@@ -55,9 +51,8 @@ export class MinMaxScaler {
|
|
|
55
51
|
};
|
|
56
52
|
}
|
|
57
53
|
static getMinMax(values) {
|
|
58
|
-
if (values.length === 0)
|
|
54
|
+
if (values.length === 0)
|
|
59
55
|
throw new Error("An empty array supplied");
|
|
60
|
-
}
|
|
61
56
|
return { min: Math.min(...values), max: Math.max(...values) };
|
|
62
57
|
}
|
|
63
58
|
}
|
package/dist/minute.vo.d.ts
CHANGED
package/dist/minute.vo.js
CHANGED
|
@@ -3,22 +3,20 @@ export class Minute {
|
|
|
3
3
|
static ZERO = new Minute(0);
|
|
4
4
|
static MAX = new Minute(59);
|
|
5
5
|
constructor(candidate) {
|
|
6
|
-
if (!Number.isInteger(candidate))
|
|
6
|
+
if (!Number.isInteger(candidate))
|
|
7
7
|
throw new Error("Invalid minute");
|
|
8
|
-
|
|
9
|
-
if (candidate < 0) {
|
|
8
|
+
if (candidate < 0)
|
|
10
9
|
throw new Error("Invalid minute");
|
|
11
|
-
|
|
12
|
-
if (candidate >= 60) {
|
|
10
|
+
if (candidate >= 60)
|
|
13
11
|
throw new Error("Invalid minute");
|
|
14
|
-
}
|
|
15
12
|
this.value = candidate;
|
|
16
13
|
}
|
|
14
|
+
static fromUtcTimestamp(timestamp) {
|
|
15
|
+
const minutes = new Date(timestamp).getUTCMinutes();
|
|
16
|
+
return new Minute(minutes);
|
|
17
|
+
}
|
|
17
18
|
get() {
|
|
18
|
-
return {
|
|
19
|
-
raw: this.value,
|
|
20
|
-
formatted: this.value.toString().padStart(2, "0"),
|
|
21
|
-
};
|
|
19
|
+
return { raw: this.value, formatted: this.value.toString().padStart(2, "0") };
|
|
22
20
|
}
|
|
23
21
|
equals(another) {
|
|
24
22
|
return this.value === another.get().raw;
|
package/dist/money.vo.js
CHANGED
|
@@ -35,15 +35,13 @@ export class Money {
|
|
|
35
35
|
}
|
|
36
36
|
subtract(money) {
|
|
37
37
|
const result = this.rounding.round(this.amount - money.getAmount());
|
|
38
|
-
if (result < Money.ZERO)
|
|
38
|
+
if (result < Money.ZERO)
|
|
39
39
|
throw new Error("Less than zero");
|
|
40
|
-
}
|
|
41
40
|
return new Money(MoneyAmount.parse(result), this.rounding);
|
|
42
41
|
}
|
|
43
42
|
divide(factor) {
|
|
44
|
-
if (factor === 0)
|
|
43
|
+
if (factor === 0)
|
|
45
44
|
throw new Error("Cannot divide by zero");
|
|
46
|
-
}
|
|
47
45
|
const result = this.rounding.round(this.amount / factor);
|
|
48
46
|
return new Money(MoneyAmount.parse(result), this.rounding);
|
|
49
47
|
}
|
|
@@ -3,9 +3,8 @@ export class OutlierDetector {
|
|
|
3
3
|
zScore;
|
|
4
4
|
threshold;
|
|
5
5
|
constructor(values, threshold) {
|
|
6
|
-
if (values.length < 2)
|
|
6
|
+
if (values.length < 2)
|
|
7
7
|
throw new Error("At least two values are needed");
|
|
8
|
-
}
|
|
9
8
|
this.zScore = new ZScore(values);
|
|
10
9
|
this.threshold = Math.abs(threshold);
|
|
11
10
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { RoundToNearest } from "./rounding.service";
|
|
2
2
|
export class Percentage {
|
|
3
3
|
static of(numerator, denominator, rounding = new RoundToNearest()) {
|
|
4
|
-
if (denominator === 0)
|
|
4
|
+
if (denominator === 0)
|
|
5
5
|
throw new Error("Invalid denominator");
|
|
6
|
-
}
|
|
7
6
|
if (numerator === 0)
|
|
8
7
|
return 0;
|
|
9
8
|
return rounding.round((numerator / denominator) * 100);
|
|
@@ -3,9 +3,8 @@ import { RoundToDecimal } from "./rounding.service";
|
|
|
3
3
|
import { Sum } from "./sum.service";
|
|
4
4
|
export class PopulationStandardDeviation {
|
|
5
5
|
static calculate(values, rounding = new RoundToDecimal(2)) {
|
|
6
|
-
if (values.length < 2)
|
|
6
|
+
if (values.length < 2)
|
|
7
7
|
throw new Error("At least two values are needed");
|
|
8
|
-
}
|
|
9
8
|
const mean = Mean.calculate(values);
|
|
10
9
|
const n = values.length;
|
|
11
10
|
const squaredDifferences = values.map((value) => (value - mean) ** 2);
|
package/dist/random.service.js
CHANGED
|
@@ -2,18 +2,14 @@ export class Random {
|
|
|
2
2
|
static generate(config) {
|
|
3
3
|
const min = config?.min ?? 0;
|
|
4
4
|
const max = config?.max ?? 1;
|
|
5
|
-
if (!Number.isInteger(min))
|
|
5
|
+
if (!Number.isInteger(min))
|
|
6
6
|
throw new Error("Minimum value is not an integer");
|
|
7
|
-
|
|
8
|
-
if (!Number.isInteger(max)) {
|
|
7
|
+
if (!Number.isInteger(max))
|
|
9
8
|
throw new Error("Maximum value is not an integer");
|
|
10
|
-
|
|
11
|
-
if (min === max) {
|
|
9
|
+
if (min === max)
|
|
12
10
|
throw new Error("Minimum and maximum values cannot be equal");
|
|
13
|
-
|
|
14
|
-
if (min > max) {
|
|
11
|
+
if (min > max)
|
|
15
12
|
throw new Error("Minimum value cannot be greater than maximum value");
|
|
16
|
-
}
|
|
17
13
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
18
14
|
}
|
|
19
15
|
}
|
|
@@ -73,21 +73,18 @@ export class ReorderingCalculator {
|
|
|
73
73
|
}
|
|
74
74
|
delete(id) {
|
|
75
75
|
const item = this.dll.find((x) => x.data.eq(id));
|
|
76
|
-
if (!item)
|
|
76
|
+
if (!item)
|
|
77
77
|
throw new Error("Cannot find Item");
|
|
78
|
-
}
|
|
79
78
|
this.dll.remove(item);
|
|
80
79
|
this.recalculate();
|
|
81
80
|
}
|
|
82
81
|
transfer(transfer) {
|
|
83
82
|
const current = this.dll.find((node) => node.data.eq(transfer.id));
|
|
84
83
|
const target = this.dll.find((node) => node.data.position.eq(transfer.to));
|
|
85
|
-
if (!current)
|
|
84
|
+
if (!current)
|
|
86
85
|
throw new Error("Cannot find current Item");
|
|
87
|
-
|
|
88
|
-
if (!target) {
|
|
86
|
+
if (!target)
|
|
89
87
|
throw new Error("Cannot find target Item");
|
|
90
|
-
}
|
|
91
88
|
const direction = transfer.getDirection(current.data.position);
|
|
92
89
|
if (direction === ReorderingTransferDirection.noop)
|
|
93
90
|
return this.read();
|
package/dist/revision.vo.js
CHANGED
|
@@ -20,15 +20,13 @@ export class Revision {
|
|
|
20
20
|
return new Revision(this.value + 1);
|
|
21
21
|
}
|
|
22
22
|
static fromETag(etag) {
|
|
23
|
-
if (!etag)
|
|
23
|
+
if (!etag)
|
|
24
24
|
throw new InvalidRevisionError();
|
|
25
|
-
}
|
|
26
25
|
return new Revision(etag.revision);
|
|
27
26
|
}
|
|
28
27
|
static fromWeakETag(weakEtag) {
|
|
29
|
-
if (!weakEtag)
|
|
28
|
+
if (!weakEtag)
|
|
30
29
|
throw new InvalidRevisionError();
|
|
31
|
-
}
|
|
32
30
|
return new Revision(weakEtag.revision);
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -9,33 +9,27 @@ export class SimpleLinearRegression {
|
|
|
9
9
|
}
|
|
10
10
|
static fromPairs(pairs, rounding) {
|
|
11
11
|
const n = pairs.length;
|
|
12
|
-
if (n < 2)
|
|
12
|
+
if (n < 2)
|
|
13
13
|
throw new Error("At least two pairs needed");
|
|
14
|
-
}
|
|
15
14
|
const x = pairs.map((pair) => pair.x);
|
|
16
15
|
const y = pairs.map((pair) => pair.y);
|
|
17
16
|
const xx = x.map((x) => x ** 2);
|
|
18
17
|
const xy = pairs.map((pair) => pair.x * pair.y);
|
|
19
18
|
const sX = Sum.of(x);
|
|
20
|
-
if (sX >= Number.MAX_SAFE_INTEGER)
|
|
19
|
+
if (sX >= Number.MAX_SAFE_INTEGER)
|
|
21
20
|
throw new Error("Sum of x values is too big");
|
|
22
|
-
}
|
|
23
21
|
const sY = Sum.of(y);
|
|
24
|
-
if (sY >= Number.MAX_SAFE_INTEGER)
|
|
22
|
+
if (sY >= Number.MAX_SAFE_INTEGER)
|
|
25
23
|
throw new Error("Sum of y values is too big");
|
|
26
|
-
}
|
|
27
24
|
const sSX = Sum.of(xx);
|
|
28
|
-
if (sSX >= Number.MAX_SAFE_INTEGER)
|
|
25
|
+
if (sSX >= Number.MAX_SAFE_INTEGER)
|
|
29
26
|
throw new Error("Sum of x squared values is too big");
|
|
30
|
-
}
|
|
31
27
|
const sXY = Sum.of(xy);
|
|
32
|
-
if (sXY >= Number.MAX_SAFE_INTEGER)
|
|
28
|
+
if (sXY >= Number.MAX_SAFE_INTEGER)
|
|
33
29
|
throw new Error("Sum of x times y values is too big");
|
|
34
|
-
}
|
|
35
30
|
const bDenominator = sSX - sX ** 2 / n;
|
|
36
|
-
if (bDenominator === 0)
|
|
31
|
+
if (bDenominator === 0)
|
|
37
32
|
throw new Error("Unable to create the model");
|
|
38
|
-
}
|
|
39
33
|
const b = (sXY - (sX * sY) / n) / bDenominator;
|
|
40
34
|
const a = (sY - b * sX) / n;
|
|
41
35
|
return new SimpleLinearRegression({ a, b }, rounding);
|
package/dist/stepper.service.js
CHANGED
|
@@ -3,12 +3,10 @@ export class Stepper {
|
|
|
3
3
|
current = Stepper.DEFAULT_CURRENT;
|
|
4
4
|
total;
|
|
5
5
|
constructor(config) {
|
|
6
|
-
if (!Number.isInteger(config.total))
|
|
6
|
+
if (!Number.isInteger(config.total))
|
|
7
7
|
throw new Error("Total value is not an integer");
|
|
8
|
-
|
|
9
|
-
if (config.total <= Stepper.DEFAULT_CURRENT) {
|
|
8
|
+
if (config.total <= Stepper.DEFAULT_CURRENT)
|
|
10
9
|
throw new Error("Total value should be greater than one");
|
|
11
|
-
}
|
|
12
10
|
this.total = config.total;
|
|
13
11
|
}
|
|
14
12
|
continue() {
|
|
@@ -12,9 +12,8 @@ export class Stopwatch {
|
|
|
12
12
|
this.startMs = startMs;
|
|
13
13
|
}
|
|
14
14
|
stop() {
|
|
15
|
-
if (this.state === StopwatchState.stopped)
|
|
15
|
+
if (this.state === StopwatchState.stopped)
|
|
16
16
|
throw new Error("Stopwatch is already stopped");
|
|
17
|
-
}
|
|
18
17
|
this.state = StopwatchState.stopped;
|
|
19
18
|
this.stopMs = Timestamp.parse(Date.now());
|
|
20
19
|
return { durationMs: Timestamp.parse(this.stopMs - this.startMs) };
|
package/dist/timezone.vo.js
CHANGED
|
@@ -4,16 +4,12 @@ export const Timezone = z
|
|
|
4
4
|
.min(1)
|
|
5
5
|
.refine((value) => {
|
|
6
6
|
try {
|
|
7
|
-
|
|
8
|
-
const dummyDate = new Date();
|
|
7
|
+
const date = new Date();
|
|
9
8
|
const formatter = new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
10
|
-
|
|
11
|
-
formatter.format(dummyDate);
|
|
12
|
-
// If the formatting succeeds without throwing an error, the timezone is valid
|
|
9
|
+
formatter.format(date);
|
|
13
10
|
return true;
|
|
14
11
|
}
|
|
15
12
|
catch (_error) {
|
|
16
|
-
// An error occurred, indicating an invalid timezone
|
|
17
13
|
return false;
|
|
18
14
|
}
|
|
19
15
|
}, { message: "timezone.invalid" })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/api-key.vo.ts","../src/basename.vo.ts","../src/
|
|
1
|
+
{"root":["../src/api-key.vo.ts","../src/basename.vo.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/dates-of-the-week.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/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.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-from-string.vo.ts","../src/filename-suffix.vo.ts","../src/filename.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/leap-year-checker.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute.vo.ts","../src/money.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering.service.ts","../src/revision.vo.ts","../src/rounding.service.ts","../src/simple-linear-regression.service.ts","../src/size.vo.ts","../src/stepper.service.ts","../src/stopwatch.service.ts","../src/streak-calculator.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/time.service.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday.vo.ts","../src/z-score.service.ts"],"version":"5.9.2"}
|
|
@@ -26,10 +26,7 @@ export class VisuallyUnambiguousCharactersGenerator {
|
|
|
26
26
|
];
|
|
27
27
|
static generate(length = 1) {
|
|
28
28
|
return Array.from({ length })
|
|
29
|
-
.map(() => VisuallyUnambiguousCharactersGenerator.chars[Random.generate({
|
|
30
|
-
min: 0,
|
|
31
|
-
max: VisuallyUnambiguousCharactersGenerator.chars.length - 1,
|
|
32
|
-
})])
|
|
29
|
+
.map(() => VisuallyUnambiguousCharactersGenerator.chars[Random.generate({ min: 0, max: VisuallyUnambiguousCharactersGenerator.chars.length - 1 })])
|
|
33
30
|
.join("");
|
|
34
31
|
}
|
|
35
32
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
2
|
+
export type WeekdayFormatter = (value: Weekday["value"]) => string;
|
|
3
|
+
export declare enum WeekdayFormatterEnum {
|
|
4
|
+
FULL = "FULL",// "Sunday"
|
|
5
|
+
SHORT = "SHORT",// "Sun"
|
|
6
|
+
ISO_NUMBER = "ISO_NUMBER",// Monday=1 ... Sunday=7
|
|
7
|
+
ZERO_BASED_NUMBER = "ZERO_BASED_NUMBER"
|
|
8
|
+
}
|
|
9
|
+
export declare const WeekdayFormatters: Record<WeekdayFormatterEnum, WeekdayFormatter>;
|
|
10
|
+
export declare class Weekday {
|
|
11
|
+
private readonly value;
|
|
12
|
+
private readonly formatter;
|
|
13
|
+
static readonly SUNDAY: Weekday;
|
|
14
|
+
static readonly MONDAY: Weekday;
|
|
15
|
+
static readonly TUESDAY: Weekday;
|
|
16
|
+
static readonly WEDNESDAY: Weekday;
|
|
17
|
+
static readonly THURSDAY: Weekday;
|
|
18
|
+
static readonly FRIDAY: Weekday;
|
|
19
|
+
static readonly SATURDAY: Weekday;
|
|
20
|
+
constructor(candidate: number, formatter?: WeekdayFormatter);
|
|
21
|
+
static fromUtcTimestamp(timestamp: TimestampType, formatter?: WeekdayFormatter): Weekday;
|
|
22
|
+
get(formatter?: WeekdayFormatter): {
|
|
23
|
+
raw: number;
|
|
24
|
+
formatted: string;
|
|
25
|
+
};
|
|
26
|
+
equals(another: Weekday): boolean;
|
|
27
|
+
isAfter(another: Weekday): boolean;
|
|
28
|
+
isBefore(another: Weekday): boolean;
|
|
29
|
+
toIsoNumber(): number;
|
|
30
|
+
isWeekend(): boolean;
|
|
31
|
+
isMonday(): boolean;
|
|
32
|
+
isTuesday(): boolean;
|
|
33
|
+
isWednesday(): boolean;
|
|
34
|
+
isThursday(): boolean;
|
|
35
|
+
isFriday(): boolean;
|
|
36
|
+
isSaturday(): boolean;
|
|
37
|
+
isSunday(): boolean;
|
|
38
|
+
static list(formatter?: WeekdayFormatter): Weekday[];
|
|
39
|
+
static listMondayFirst(formatter?: WeekdayFormatter): Weekday[];
|
|
40
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export var WeekdayFormatterEnum;
|
|
2
|
+
(function (WeekdayFormatterEnum) {
|
|
3
|
+
WeekdayFormatterEnum["FULL"] = "FULL";
|
|
4
|
+
WeekdayFormatterEnum["SHORT"] = "SHORT";
|
|
5
|
+
WeekdayFormatterEnum["ISO_NUMBER"] = "ISO_NUMBER";
|
|
6
|
+
WeekdayFormatterEnum["ZERO_BASED_NUMBER"] = "ZERO_BASED_NUMBER";
|
|
7
|
+
})(WeekdayFormatterEnum || (WeekdayFormatterEnum = {}));
|
|
8
|
+
const FULL_NAMES = [
|
|
9
|
+
"Sunday",
|
|
10
|
+
"Monday",
|
|
11
|
+
"Tuesday",
|
|
12
|
+
"Wednesday",
|
|
13
|
+
"Thursday",
|
|
14
|
+
"Friday",
|
|
15
|
+
"Saturday",
|
|
16
|
+
];
|
|
17
|
+
const SHORT_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
18
|
+
export const WeekdayFormatters = {
|
|
19
|
+
FULL: (value) => FULL_NAMES[value],
|
|
20
|
+
SHORT: (value) => SHORT_NAMES[value],
|
|
21
|
+
ISO_NUMBER: (value) => (value === 0 ? 7 : value).toString(), // ISO-8601: Mon=1..Sun=7
|
|
22
|
+
ZERO_BASED_NUMBER: (value) => value.toString(), // JS getUTCDay(): Sun=0..Sat=6
|
|
23
|
+
};
|
|
24
|
+
export class Weekday {
|
|
25
|
+
value;
|
|
26
|
+
formatter;
|
|
27
|
+
static SUNDAY = new Weekday(0);
|
|
28
|
+
static MONDAY = new Weekday(1);
|
|
29
|
+
static TUESDAY = new Weekday(2);
|
|
30
|
+
static WEDNESDAY = new Weekday(3);
|
|
31
|
+
static THURSDAY = new Weekday(4);
|
|
32
|
+
static FRIDAY = new Weekday(5);
|
|
33
|
+
static SATURDAY = new Weekday(6);
|
|
34
|
+
constructor(candidate, formatter) {
|
|
35
|
+
if (!Number.isInteger(candidate))
|
|
36
|
+
throw new Error("Invalid weekday");
|
|
37
|
+
if (candidate < 0)
|
|
38
|
+
throw new Error("Invalid weekday");
|
|
39
|
+
if (candidate > 6)
|
|
40
|
+
throw new Error("Invalid weekday");
|
|
41
|
+
this.value = candidate;
|
|
42
|
+
this.formatter = formatter ?? WeekdayFormatters.FULL;
|
|
43
|
+
}
|
|
44
|
+
static fromUtcTimestamp(timestamp, formatter) {
|
|
45
|
+
const day = new Date(timestamp).getUTCDay(); // 0..6
|
|
46
|
+
return new Weekday(day, formatter);
|
|
47
|
+
}
|
|
48
|
+
get(formatter) {
|
|
49
|
+
const format = formatter ?? this.formatter;
|
|
50
|
+
return { raw: this.value, formatted: format(this.value) };
|
|
51
|
+
}
|
|
52
|
+
equals(another) {
|
|
53
|
+
return this.value === another.get().raw;
|
|
54
|
+
}
|
|
55
|
+
isAfter(another) {
|
|
56
|
+
return this.value > another.get().raw;
|
|
57
|
+
}
|
|
58
|
+
isBefore(another) {
|
|
59
|
+
return this.value < another.get().raw;
|
|
60
|
+
}
|
|
61
|
+
toIsoNumber() {
|
|
62
|
+
return this.value === 0 ? 7 : this.value;
|
|
63
|
+
}
|
|
64
|
+
isWeekend() {
|
|
65
|
+
return this.value === 0 || this.value === 6;
|
|
66
|
+
}
|
|
67
|
+
isMonday() {
|
|
68
|
+
return this.value === 1;
|
|
69
|
+
}
|
|
70
|
+
isTuesday() {
|
|
71
|
+
return this.value === 2;
|
|
72
|
+
}
|
|
73
|
+
isWednesday() {
|
|
74
|
+
return this.value === 3;
|
|
75
|
+
}
|
|
76
|
+
isThursday() {
|
|
77
|
+
return this.value === 4;
|
|
78
|
+
}
|
|
79
|
+
isFriday() {
|
|
80
|
+
return this.value === 5;
|
|
81
|
+
}
|
|
82
|
+
isSaturday() {
|
|
83
|
+
return this.value === 6;
|
|
84
|
+
}
|
|
85
|
+
isSunday() {
|
|
86
|
+
return this.value === 0;
|
|
87
|
+
}
|
|
88
|
+
static list(formatter) {
|
|
89
|
+
return Array.from({ length: 7 }).map((_, index) => new Weekday(index, formatter));
|
|
90
|
+
}
|
|
91
|
+
static listMondayFirst(formatter) {
|
|
92
|
+
const days = Weekday.list(formatter);
|
|
93
|
+
return [...days.slice(1), days[0]];
|
|
94
|
+
}
|
|
95
|
+
}
|
package/dist/z-score.service.js
CHANGED
|
@@ -7,9 +7,8 @@ export class ZScore {
|
|
|
7
7
|
standardDeviation;
|
|
8
8
|
constructor(values, rounding = new RoundToDecimal(2)) {
|
|
9
9
|
this.rounding = rounding;
|
|
10
|
-
if (values.length < 2)
|
|
10
|
+
if (values.length < 2)
|
|
11
11
|
throw new Error("At least two values are needed");
|
|
12
|
-
}
|
|
13
12
|
this.mean = Mean.calculate(values);
|
|
14
13
|
this.standardDeviation = PopulationStandardDeviation.calculate(values);
|
|
15
14
|
}
|