@algoux/standard-ranklist-utils 0.1.1 → 0.2.1

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.
@@ -0,0 +1,102 @@
1
+ import * as srk from '@algoux/standard-ranklist';
2
+
3
+ declare const MIN_REGEN_SUPPORTED_VERSION = "0.3.0";
4
+
5
+ declare enum EnumTheme {
6
+ light = "light",
7
+ dark = "dark"
8
+ }
9
+
10
+ interface RankValue {
11
+ /** Rank value initially. If the user is unofficial and rank value equals null, it will be rendered as unofficial mark such as '*'. */
12
+ rank: number | null;
13
+ /**
14
+ * Series segment index which this rank belongs to initially. `null` means this rank does not belong to any segment. `undefined` means it will be calculated automatically (only if the segment's count property exists).
15
+ * @defaultValue null
16
+ */
17
+ segmentIndex?: number | null;
18
+ }
19
+ type StaticRanklist = Omit<srk.Ranklist, 'rows'> & {
20
+ rows: Array<srk.RanklistRow & {
21
+ rankValues: RankValue[];
22
+ }>;
23
+ };
24
+ type CalculatedSolutionTetrad = [
25
+ /** user id */ string,
26
+ /** problem index */ number,
27
+ /** result */ Exclude<srk.SolutionResultFull, null> | srk.SolutionResultCustom,
28
+ /** solution submitted time */ srk.TimeDuration
29
+ ];
30
+ interface ThemeColor {
31
+ [EnumTheme.light]: string | undefined;
32
+ [EnumTheme.dark]: string | undefined;
33
+ }
34
+
35
+ declare function formatTimeDuration(time: srk.TimeDuration, targetUnit?: srk.TimeUnit, fmt?: (num: number) => number): number;
36
+ declare function preZeroFill(num: number, size: number): string;
37
+ /**
38
+ * format seconds to time string
39
+ * @param {number} second
40
+ * @param {{ fillHour?: boolean, showDay?: boolean }} options
41
+ * @returns {string}
42
+ */
43
+ declare function secToTimeStr(second: number, options?: {
44
+ fillHour?: boolean;
45
+ showDay?: boolean;
46
+ }): string;
47
+ /**
48
+ * Format number index to alphabet index
49
+ * 0 => 'A'
50
+ * 2 => 'C'
51
+ * 25 => 'Z'
52
+ * 26 => 'AA'
53
+ * 28 => 'AC
54
+ * @param {number | string} number
55
+ * @returns {string}
56
+ */
57
+ declare function numberToAlphabet(number: number | string): string;
58
+ /**
59
+ * Format alphabet index to number index
60
+ * 'A' => 0
61
+ * 'C' => 2
62
+ * 'Z' => 25
63
+ * 'AA' => 26
64
+ * 'AC' => 28
65
+ * @param {string} alphabet
66
+ * @returns {number}
67
+ */
68
+ declare function alphabetToNumber(alphabet: string): number;
69
+
70
+ declare function resolveText(text: srk.Text | undefined): string;
71
+ /**
72
+ * Parse contributor string to an object which contains name, email (optional) and url (optional).
73
+ * @param contributor
74
+ * @returns parsed contributor object
75
+ * @example
76
+ * 'name <mail@example.com> (http://example.com)' -> { name: 'name', email: 'mail@example.com', url: 'http://example.com' }
77
+ * 'name' -> { name: 'name' }
78
+ * 'name <mail@example.com>' -> { name: 'name', email: 'mail@example.com' }
79
+ * 'name (http://example.com)' -> { name: 'name', url: 'http://example.com' }
80
+ * 'John Smith (http://example.com)' -> { name: 'John Smith', url: 'http://example.com' }
81
+ */
82
+ declare function resolveContributor(contributor: srk.Contributor | undefined): {
83
+ name: string;
84
+ email?: string;
85
+ url?: string;
86
+ } | null;
87
+ declare function resolveColor(color: srk.Color): string | undefined;
88
+ declare function resolveThemeColor(themeColor: srk.ThemeColor): ThemeColor;
89
+ declare function resolveStyle(style: srk.Style): {
90
+ textColor: ThemeColor;
91
+ backgroundColor: ThemeColor;
92
+ };
93
+
94
+ declare function canRegenerateRanklist(ranklist: srk.Ranklist): boolean;
95
+ declare function getSortedCalculatedRawSolutions(rows: srk.RanklistRow[]): CalculatedSolutionTetrad[];
96
+ declare function filterSolutionsUntil(solutions: CalculatedSolutionTetrad[], time: srk.TimeDuration): CalculatedSolutionTetrad[];
97
+ declare function sortRows(rows: srk.RanklistRow[]): srk.RanklistRow[];
98
+ declare function regenerateRanklistBySolutions(originalRanklist: srk.Ranklist, solutions: CalculatedSolutionTetrad[]): srk.Ranklist;
99
+ declare function regenerateRowsByIncrementalSolutions(originalRanklist: srk.Ranklist, solutions: CalculatedSolutionTetrad[]): srk.RanklistRow[];
100
+ declare function convertToStaticRanklist(ranklist: srk.Ranklist): StaticRanklist;
101
+
102
+ export { type CalculatedSolutionTetrad, EnumTheme, MIN_REGEN_SUPPORTED_VERSION, type RankValue, type StaticRanklist, type ThemeColor, alphabetToNumber, canRegenerateRanklist, convertToStaticRanklist, filterSolutionsUntil, formatTimeDuration, getSortedCalculatedRawSolutions, numberToAlphabet, preZeroFill, regenerateRanklistBySolutions, regenerateRowsByIncrementalSolutions, resolveColor, resolveContributor, resolveStyle, resolveText, resolveThemeColor, secToTimeStr, sortRows };
@@ -0,0 +1,102 @@
1
+ import * as srk from '@algoux/standard-ranklist';
2
+
3
+ declare const MIN_REGEN_SUPPORTED_VERSION = "0.3.0";
4
+
5
+ declare enum EnumTheme {
6
+ light = "light",
7
+ dark = "dark"
8
+ }
9
+
10
+ interface RankValue {
11
+ /** Rank value initially. If the user is unofficial and rank value equals null, it will be rendered as unofficial mark such as '*'. */
12
+ rank: number | null;
13
+ /**
14
+ * Series segment index which this rank belongs to initially. `null` means this rank does not belong to any segment. `undefined` means it will be calculated automatically (only if the segment's count property exists).
15
+ * @defaultValue null
16
+ */
17
+ segmentIndex?: number | null;
18
+ }
19
+ type StaticRanklist = Omit<srk.Ranklist, 'rows'> & {
20
+ rows: Array<srk.RanklistRow & {
21
+ rankValues: RankValue[];
22
+ }>;
23
+ };
24
+ type CalculatedSolutionTetrad = [
25
+ /** user id */ string,
26
+ /** problem index */ number,
27
+ /** result */ Exclude<srk.SolutionResultFull, null> | srk.SolutionResultCustom,
28
+ /** solution submitted time */ srk.TimeDuration
29
+ ];
30
+ interface ThemeColor {
31
+ [EnumTheme.light]: string | undefined;
32
+ [EnumTheme.dark]: string | undefined;
33
+ }
34
+
35
+ declare function formatTimeDuration(time: srk.TimeDuration, targetUnit?: srk.TimeUnit, fmt?: (num: number) => number): number;
36
+ declare function preZeroFill(num: number, size: number): string;
37
+ /**
38
+ * format seconds to time string
39
+ * @param {number} second
40
+ * @param {{ fillHour?: boolean, showDay?: boolean }} options
41
+ * @returns {string}
42
+ */
43
+ declare function secToTimeStr(second: number, options?: {
44
+ fillHour?: boolean;
45
+ showDay?: boolean;
46
+ }): string;
47
+ /**
48
+ * Format number index to alphabet index
49
+ * 0 => 'A'
50
+ * 2 => 'C'
51
+ * 25 => 'Z'
52
+ * 26 => 'AA'
53
+ * 28 => 'AC
54
+ * @param {number | string} number
55
+ * @returns {string}
56
+ */
57
+ declare function numberToAlphabet(number: number | string): string;
58
+ /**
59
+ * Format alphabet index to number index
60
+ * 'A' => 0
61
+ * 'C' => 2
62
+ * 'Z' => 25
63
+ * 'AA' => 26
64
+ * 'AC' => 28
65
+ * @param {string} alphabet
66
+ * @returns {number}
67
+ */
68
+ declare function alphabetToNumber(alphabet: string): number;
69
+
70
+ declare function resolveText(text: srk.Text | undefined): string;
71
+ /**
72
+ * Parse contributor string to an object which contains name, email (optional) and url (optional).
73
+ * @param contributor
74
+ * @returns parsed contributor object
75
+ * @example
76
+ * 'name <mail@example.com> (http://example.com)' -> { name: 'name', email: 'mail@example.com', url: 'http://example.com' }
77
+ * 'name' -> { name: 'name' }
78
+ * 'name <mail@example.com>' -> { name: 'name', email: 'mail@example.com' }
79
+ * 'name (http://example.com)' -> { name: 'name', url: 'http://example.com' }
80
+ * 'John Smith (http://example.com)' -> { name: 'John Smith', url: 'http://example.com' }
81
+ */
82
+ declare function resolveContributor(contributor: srk.Contributor | undefined): {
83
+ name: string;
84
+ email?: string;
85
+ url?: string;
86
+ } | null;
87
+ declare function resolveColor(color: srk.Color): string | undefined;
88
+ declare function resolveThemeColor(themeColor: srk.ThemeColor): ThemeColor;
89
+ declare function resolveStyle(style: srk.Style): {
90
+ textColor: ThemeColor;
91
+ backgroundColor: ThemeColor;
92
+ };
93
+
94
+ declare function canRegenerateRanklist(ranklist: srk.Ranklist): boolean;
95
+ declare function getSortedCalculatedRawSolutions(rows: srk.RanklistRow[]): CalculatedSolutionTetrad[];
96
+ declare function filterSolutionsUntil(solutions: CalculatedSolutionTetrad[], time: srk.TimeDuration): CalculatedSolutionTetrad[];
97
+ declare function sortRows(rows: srk.RanklistRow[]): srk.RanklistRow[];
98
+ declare function regenerateRanklistBySolutions(originalRanklist: srk.Ranklist, solutions: CalculatedSolutionTetrad[]): srk.Ranklist;
99
+ declare function regenerateRowsByIncrementalSolutions(originalRanklist: srk.Ranklist, solutions: CalculatedSolutionTetrad[]): srk.RanklistRow[];
100
+ declare function convertToStaticRanklist(ranklist: srk.Ranklist): StaticRanklist;
101
+
102
+ export { type CalculatedSolutionTetrad, EnumTheme, MIN_REGEN_SUPPORTED_VERSION, type RankValue, type StaticRanklist, type ThemeColor, alphabetToNumber, canRegenerateRanklist, convertToStaticRanklist, filterSolutionsUntil, formatTimeDuration, getSortedCalculatedRawSolutions, numberToAlphabet, preZeroFill, regenerateRanklistBySolutions, regenerateRowsByIncrementalSolutions, resolveColor, resolveContributor, resolveStyle, resolveText, resolveThemeColor, secToTimeStr, sortRows };