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