@bgord/tools 0.12.25 → 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/rate-limiter.service.js +1 -4
- package/dist/relative-date.vo.js +1 -4
- 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 +6 -6
- 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 +2 -11
- package/src/relative-date.vo.ts +1 -4
- 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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { TimestampType } from "./timestamp.vo";
|
|
2
|
+
|
|
3
|
+
export type WeekdayFormatter = (value: Weekday["value"]) => string;
|
|
4
|
+
|
|
5
|
+
export enum WeekdayFormatterEnum {
|
|
6
|
+
FULL = "FULL", // "Sunday"
|
|
7
|
+
SHORT = "SHORT", // "Sun"
|
|
8
|
+
ISO_NUMBER = "ISO_NUMBER", // Monday=1 ... Sunday=7
|
|
9
|
+
ZERO_BASED_NUMBER = "ZERO_BASED_NUMBER", // Sunday=0 ... Saturday=6 (JS)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const FULL_NAMES: readonly string[] = [
|
|
13
|
+
"Sunday",
|
|
14
|
+
"Monday",
|
|
15
|
+
"Tuesday",
|
|
16
|
+
"Wednesday",
|
|
17
|
+
"Thursday",
|
|
18
|
+
"Friday",
|
|
19
|
+
"Saturday",
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
const SHORT_NAMES: readonly string[] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] as const;
|
|
23
|
+
|
|
24
|
+
export const WeekdayFormatters: Record<WeekdayFormatterEnum, WeekdayFormatter> = {
|
|
25
|
+
FULL: (value) => FULL_NAMES[value],
|
|
26
|
+
SHORT: (value) => SHORT_NAMES[value],
|
|
27
|
+
ISO_NUMBER: (value) => (value === 0 ? 7 : value).toString(), // ISO-8601: Mon=1..Sun=7
|
|
28
|
+
ZERO_BASED_NUMBER: (value) => value.toString(), // JS getUTCDay(): Sun=0..Sat=6
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export class Weekday {
|
|
32
|
+
private readonly value: number;
|
|
33
|
+
|
|
34
|
+
private readonly formatter: WeekdayFormatter;
|
|
35
|
+
|
|
36
|
+
static readonly SUNDAY = new Weekday(0);
|
|
37
|
+
static readonly MONDAY = new Weekday(1);
|
|
38
|
+
static readonly TUESDAY = new Weekday(2);
|
|
39
|
+
static readonly WEDNESDAY = new Weekday(3);
|
|
40
|
+
static readonly THURSDAY = new Weekday(4);
|
|
41
|
+
static readonly FRIDAY = new Weekday(5);
|
|
42
|
+
static readonly SATURDAY = new Weekday(6);
|
|
43
|
+
|
|
44
|
+
constructor(candidate: number, formatter?: WeekdayFormatter) {
|
|
45
|
+
if (!Number.isInteger(candidate)) throw new Error("Invalid weekday");
|
|
46
|
+
if (candidate < 0) throw new Error("Invalid weekday");
|
|
47
|
+
if (candidate > 6) throw new Error("Invalid weekday");
|
|
48
|
+
|
|
49
|
+
this.value = candidate;
|
|
50
|
+
this.formatter = (formatter as WeekdayFormatter) ?? WeekdayFormatters.FULL;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static fromUtcTimestamp(timestamp: TimestampType, formatter?: WeekdayFormatter): Weekday {
|
|
54
|
+
const day = new Date(timestamp).getUTCDay(); // 0..6
|
|
55
|
+
return new Weekday(day, formatter);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get(formatter?: WeekdayFormatter) {
|
|
59
|
+
const format = formatter ?? this.formatter;
|
|
60
|
+
return { raw: this.value, formatted: format(this.value) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
equals(another: Weekday): boolean {
|
|
64
|
+
return this.value === another.get().raw;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
isAfter(another: Weekday): boolean {
|
|
68
|
+
return this.value > another.get().raw;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
isBefore(another: Weekday): boolean {
|
|
72
|
+
return this.value < another.get().raw;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
toIsoNumber(): number {
|
|
76
|
+
return this.value === 0 ? 7 : this.value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isWeekend(): boolean {
|
|
80
|
+
return this.value === 0 || this.value === 6;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
isMonday(): boolean {
|
|
84
|
+
return this.value === 1;
|
|
85
|
+
}
|
|
86
|
+
isTuesday(): boolean {
|
|
87
|
+
return this.value === 2;
|
|
88
|
+
}
|
|
89
|
+
isWednesday(): boolean {
|
|
90
|
+
return this.value === 3;
|
|
91
|
+
}
|
|
92
|
+
isThursday(): boolean {
|
|
93
|
+
return this.value === 4;
|
|
94
|
+
}
|
|
95
|
+
isFriday(): boolean {
|
|
96
|
+
return this.value === 5;
|
|
97
|
+
}
|
|
98
|
+
isSaturday(): boolean {
|
|
99
|
+
return this.value === 6;
|
|
100
|
+
}
|
|
101
|
+
isSunday(): boolean {
|
|
102
|
+
return this.value === 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static list(formatter?: WeekdayFormatter): Weekday[] {
|
|
106
|
+
return Array.from({ length: 7 }).map((_, index) => new Weekday(index, formatter));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static listMondayFirst(formatter?: WeekdayFormatter): Weekday[] {
|
|
110
|
+
const days = Weekday.list(formatter);
|
|
111
|
+
return [...days.slice(1), days[0]];
|
|
112
|
+
}
|
|
113
|
+
}
|
package/src/z-score.service.ts
CHANGED
|
@@ -10,9 +10,7 @@ export class ZScore {
|
|
|
10
10
|
values: number[],
|
|
11
11
|
private readonly rounding: RoundingStrategy = new RoundToDecimal(2),
|
|
12
12
|
) {
|
|
13
|
-
if (values.length < 2)
|
|
14
|
-
throw new Error("At least two values are needed");
|
|
15
|
-
}
|
|
13
|
+
if (values.length < 2) throw new Error("At least two values are needed");
|
|
16
14
|
|
|
17
15
|
this.mean = Mean.calculate(values);
|
|
18
16
|
this.standardDeviation = PopulationStandardDeviation.calculate(values);
|
package/dist/build-version.vo.js
DELETED
package/dist/filter.vo.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod/v4";
|
|
2
|
-
export type DefaultFilterSchemaType = z.ZodRawShape;
|
|
3
|
-
export type FilterValuesType = Record<string, unknown>;
|
|
4
|
-
export type FilterSchemaType<T extends DefaultFilterSchemaType> = z.ZodObject<T>;
|
|
5
|
-
export type FilterParseConfigType<T extends DefaultFilterSchemaType> = {
|
|
6
|
-
schema: FilterSchemaType<T>;
|
|
7
|
-
values: FilterValuesType;
|
|
8
|
-
};
|
|
9
|
-
export declare class Filter<T extends DefaultFilterSchemaType> {
|
|
10
|
-
private readonly schema;
|
|
11
|
-
constructor(schema: FilterSchemaType<T>);
|
|
12
|
-
parse(values: FilterValuesType): z.core.$InferObjectOutput<T, {}> | undefined;
|
|
13
|
-
default(): z.core.$InferObjectOutput<T, {}> | undefined;
|
|
14
|
-
static parse<T extends DefaultFilterSchemaType>(config: FilterParseConfigType<T>): z.core.$InferObjectOutput<T, {}> | undefined;
|
|
15
|
-
static default<T extends DefaultFilterSchemaType>(config: Omit<FilterParseConfigType<T>, "values">): z.core.$InferObjectOutput<T, {}> | undefined;
|
|
16
|
-
private static _parse;
|
|
17
|
-
}
|
package/dist/filter.vo.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export class Filter {
|
|
2
|
-
schema;
|
|
3
|
-
constructor(schema) {
|
|
4
|
-
this.schema = schema;
|
|
5
|
-
}
|
|
6
|
-
parse(values) {
|
|
7
|
-
return Filter._parse({ schema: this.schema, values });
|
|
8
|
-
}
|
|
9
|
-
default() {
|
|
10
|
-
return this.parse({});
|
|
11
|
-
}
|
|
12
|
-
static parse(config) {
|
|
13
|
-
return Filter._parse(config);
|
|
14
|
-
}
|
|
15
|
-
static default(config) {
|
|
16
|
-
return Filter._parse({ schema: config.schema, values: {} });
|
|
17
|
-
}
|
|
18
|
-
static _parse(config) {
|
|
19
|
-
const result = config.schema.safeParse(config.values);
|
|
20
|
-
return result.success ? result.data : undefined;
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/build-version.vo.ts
DELETED
package/src/filter.vo.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod/v4";
|
|
2
|
-
|
|
3
|
-
export type DefaultFilterSchemaType = z.ZodRawShape;
|
|
4
|
-
|
|
5
|
-
export type FilterValuesType = Record<string, unknown>;
|
|
6
|
-
|
|
7
|
-
export type FilterSchemaType<T extends DefaultFilterSchemaType> = z.ZodObject<T>;
|
|
8
|
-
|
|
9
|
-
export type FilterParseConfigType<T extends DefaultFilterSchemaType> = {
|
|
10
|
-
schema: FilterSchemaType<T>;
|
|
11
|
-
values: FilterValuesType;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export class Filter<T extends DefaultFilterSchemaType> {
|
|
15
|
-
constructor(private readonly schema: FilterSchemaType<T>) {}
|
|
16
|
-
|
|
17
|
-
parse(values: FilterValuesType) {
|
|
18
|
-
return Filter._parse({ schema: this.schema, values });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
default() {
|
|
22
|
-
return this.parse({});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static parse<T extends DefaultFilterSchemaType>(config: FilterParseConfigType<T>) {
|
|
26
|
-
return Filter._parse(config);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static default<T extends DefaultFilterSchemaType>(config: Omit<FilterParseConfigType<T>, "values">) {
|
|
30
|
-
return Filter._parse({ schema: config.schema, values: {} });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private static _parse<T extends DefaultFilterSchemaType>(config: FilterParseConfigType<T>) {
|
|
34
|
-
const result = config.schema.safeParse(config.values);
|
|
35
|
-
|
|
36
|
-
return result.success ? result.data : undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|