@wise-old-man/utils 1.0.9 → 1.0.10
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/{src → lib}/competitions.d.ts +0 -0
- package/dist/{src → lib}/competitions.js +0 -0
- package/dist/{src → lib}/competitions.js.map +1 -1
- package/dist/{src → lib}/countries.d.ts +0 -0
- package/dist/{src → lib}/countries.js +0 -0
- package/dist/{src → lib}/countries.js.map +1 -1
- package/dist/{src → lib}/experience.d.ts +0 -0
- package/dist/{src → lib}/experience.js +0 -0
- package/dist/{src → lib}/experience.js.map +1 -1
- package/dist/{src → lib}/groups.d.ts +0 -0
- package/dist/{src → lib}/groups.js +0 -0
- package/dist/{src → lib}/groups.js.map +1 -1
- package/dist/{src → lib}/index.d.ts +0 -0
- package/dist/{src → lib}/index.js +0 -0
- package/dist/{src → lib}/index.js.map +1 -1
- package/dist/{src → lib}/metrics.d.ts +0 -0
- package/dist/{src → lib}/metrics.js +0 -0
- package/dist/{src → lib}/metrics.js.map +1 -1
- package/dist/{src → lib}/numbers.d.ts +0 -0
- package/dist/{src → lib}/numbers.js +0 -0
- package/dist/{src → lib}/numbers.js.map +1 -1
- package/dist/{src → lib}/periods.d.ts +0 -0
- package/dist/{src → lib}/periods.js +0 -0
- package/dist/{src → lib}/periods.js.map +1 -1
- package/dist/{src → lib}/players.d.ts +0 -0
- package/dist/{src → lib}/players.js +0 -0
- package/dist/{src → lib}/players.js.map +1 -1
- package/dist/{src → lib}/strings.d.ts +0 -0
- package/dist/{src → lib}/strings.js +0 -0
- package/dist/{src → lib}/strings.js.map +1 -1
- package/package.json +6 -3
- package/.prettierrc +0 -7
- package/dist/jest.config.d.ts +0 -3
- package/dist/jest.config.js +0 -10
- package/dist/jest.config.js.map +0 -1
- package/jest.config.ts +0 -10
- package/src/competitions.ts +0 -54
- package/src/countries.ts +0 -275
- package/src/experience.ts +0 -86
- package/src/groups.ts +0 -556
- package/src/index.ts +0 -9
- package/src/metrics.ts +0 -628
- package/src/numbers.ts +0 -5
- package/src/periods.ts +0 -67
- package/src/players.ts +0 -77
- package/src/strings.ts +0 -31
- package/tests/competitions.test.ts +0 -32
- package/tests/countries.test.ts +0 -22
- package/tests/experience.test.ts +0 -23
- package/tests/groups.test.ts +0 -14
- package/tests/metrics.test.ts +0 -113
- package/tests/numbers.test.ts +0 -9
- package/tests/periods.test.ts +0 -49
- package/tests/players.test.ts +0 -44
- package/tests/strings.test.ts +0 -27
- package/tsconfig.json +0 -16
package/src/players.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
enum PlayerType {
|
|
2
|
-
UNKNOWN = 'unknown',
|
|
3
|
-
REGULAR = 'regular',
|
|
4
|
-
IRONMAN = 'ironman',
|
|
5
|
-
HARDCORE = 'hardcore',
|
|
6
|
-
ULTIMATE = 'ultimate'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
enum PlayerBuild {
|
|
10
|
-
MAIN = 'main',
|
|
11
|
-
F2P = 'f2p',
|
|
12
|
-
LVL3 = 'lvl3',
|
|
13
|
-
ZERKER = 'zerker',
|
|
14
|
-
DEF1 = '1def',
|
|
15
|
-
HP10 = '10hp'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const PlayerTypeProps = {
|
|
19
|
-
[PlayerType.UNKNOWN]: { name: 'Unknown' },
|
|
20
|
-
[PlayerType.REGULAR]: { name: 'Regular' },
|
|
21
|
-
[PlayerType.IRONMAN]: { name: 'Ironman' },
|
|
22
|
-
[PlayerType.HARDCORE]: { name: 'Hardcore' },
|
|
23
|
-
[PlayerType.ULTIMATE]: { name: 'Ultimate' }
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const PlayerBuildProps = {
|
|
27
|
-
[PlayerBuild.MAIN]: { name: 'Main' },
|
|
28
|
-
[PlayerBuild.F2P]: { name: 'F2P' },
|
|
29
|
-
[PlayerBuild.LVL3]: { name: 'Level 3' },
|
|
30
|
-
[PlayerBuild.ZERKER]: { name: 'Zerker Pure' },
|
|
31
|
-
[PlayerBuild.DEF1]: { name: '1 Defence Pure' },
|
|
32
|
-
[PlayerBuild.HP10]: { name: '10 Hitpoints Pure' }
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const PLAYER_TYPES = Object.values(PlayerType);
|
|
36
|
-
const PLAYER_BUILDS = Object.values(PlayerBuild);
|
|
37
|
-
|
|
38
|
-
function findPlayerType(typeName: string): PlayerType | null {
|
|
39
|
-
for (var [key, value] of Object.entries(PlayerTypeProps)) {
|
|
40
|
-
if (value.name.toUpperCase() === typeName.toUpperCase()) return key as PlayerType;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function findPlayerBuild(buildName: string): PlayerBuild | null {
|
|
47
|
-
for (var [key, value] of Object.entries(PlayerBuildProps)) {
|
|
48
|
-
if (value.name.toUpperCase() === buildName.toUpperCase()) return key as PlayerBuild;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function standardizeUsername(username) {
|
|
55
|
-
return sanitizeUsername(username).toLowerCase();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// TODO: should this also remove any non alphanumeric symbols?
|
|
59
|
-
function sanitizeUsername(username) {
|
|
60
|
-
return username.replace(/[-_\s]/g, ' ').trim();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
// Enums
|
|
65
|
-
PlayerType,
|
|
66
|
-
PlayerBuild,
|
|
67
|
-
PlayerTypeProps,
|
|
68
|
-
PlayerBuildProps,
|
|
69
|
-
// Lists
|
|
70
|
-
PLAYER_TYPES,
|
|
71
|
-
PLAYER_BUILDS,
|
|
72
|
-
// Functions
|
|
73
|
-
findPlayerType,
|
|
74
|
-
findPlayerBuild,
|
|
75
|
-
sanitizeUsername,
|
|
76
|
-
standardizeUsername
|
|
77
|
-
};
|
package/src/strings.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
function formatNumber(num: number, withLetters = false) {
|
|
2
|
-
if (num === undefined || num === null) return -1;
|
|
3
|
-
|
|
4
|
-
// If number is float
|
|
5
|
-
if (num % 1 !== 0) {
|
|
6
|
-
return (Math.round(num * 100) / 100).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if ((num < 10000 && num > -10000) || !withLetters) {
|
|
10
|
-
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// < 10 million
|
|
14
|
-
if (num < 10_000_000 && num > -10_000_000) {
|
|
15
|
-
return `${Math.floor(num / 1000)}k`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// < 1 billion
|
|
19
|
-
if (num < 1_000_000_000 && num > -1_000_000_000) {
|
|
20
|
-
return `${Math.round((num / 1000000 + Number.EPSILON) * 100) / 100}m`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return `${Math.round((num / 1000000000 + Number.EPSILON) * 100) / 100}b`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function padNumber(value: number): string {
|
|
27
|
-
if (!value) return '00';
|
|
28
|
-
return value < 10 ? `0${value}` : value.toString();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { formatNumber, padNumber };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findCompetitionType,
|
|
3
|
-
findCompetitionStatus,
|
|
4
|
-
CompetitionType,
|
|
5
|
-
CompetitionStatus,
|
|
6
|
-
CompetitionTypeProps,
|
|
7
|
-
COMPETITION_TYPES,
|
|
8
|
-
COMPETITION_STATUSES,
|
|
9
|
-
CompetitionStatusProps
|
|
10
|
-
} from '../src/competitions';
|
|
11
|
-
|
|
12
|
-
describe('Util - Competitions', () => {
|
|
13
|
-
test('Props', () => {
|
|
14
|
-
expect(COMPETITION_TYPES.some(t => !(t in CompetitionTypeProps))).toBe(false);
|
|
15
|
-
expect(Object.keys(CompetitionType).length).toBe(Object.keys(CompetitionTypeProps).length);
|
|
16
|
-
|
|
17
|
-
expect(COMPETITION_STATUSES.some(t => !(t in CompetitionStatusProps))).toBe(false);
|
|
18
|
-
expect(Object.keys(CompetitionStatus).length).toBe(Object.keys(CompetitionStatusProps).length);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('findCompetitionType', () => {
|
|
22
|
-
expect(findCompetitionType('Classic')).toBe(CompetitionType.CLASSIC);
|
|
23
|
-
expect(findCompetitionType('Team')).toBe(CompetitionType.TEAM);
|
|
24
|
-
expect(findCompetitionType('Other')).toBe(null);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('findCompetitionStatus', () => {
|
|
28
|
-
expect(findCompetitionStatus('Upcoming')).toBe(CompetitionStatus.UPCOMING);
|
|
29
|
-
expect(findCompetitionStatus('Ongoing')).toBe(CompetitionStatus.ONGOING);
|
|
30
|
-
expect(findCompetitionStatus('Other')).toBe(null);
|
|
31
|
-
});
|
|
32
|
-
});
|
package/tests/countries.test.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { findCountryByCode, findCountryByName, findCountry } from '../src/countries';
|
|
2
|
-
|
|
3
|
-
describe('Util - Countries', () => {
|
|
4
|
-
test('findCountryByCode', () => {
|
|
5
|
-
expect(findCountryByCode('UK')?.code).toBe('GB');
|
|
6
|
-
expect(findCountryByCode('USA')?.code).toBe('US');
|
|
7
|
-
expect(findCountryByCode('PT')?.name).toBe('Portugal');
|
|
8
|
-
expect(findCountryByCode('FR')?.name).toBe('France');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('findCountryByName', () => {
|
|
12
|
-
expect(findCountryByName('portugal')?.code).toBe('PT');
|
|
13
|
-
expect(findCountryByName('Italy')?.code).toBe('IT');
|
|
14
|
-
expect(findCountryByName('ANGOLA')?.name).toBe('Angola');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('findCountry', () => {
|
|
18
|
-
expect(findCountry('portugal')?.code).toBe('PT');
|
|
19
|
-
expect(findCountry('it')?.code).toBe('IT');
|
|
20
|
-
expect(findCountry('AO')?.name).toBe('Angola');
|
|
21
|
-
});
|
|
22
|
-
});
|
package/tests/experience.test.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getCombatLevel, getLevel, getExpForLevel, SKILL_EXP_AT_99 } from '../src/experience';
|
|
2
|
-
|
|
3
|
-
describe('Util - Experience', () => {
|
|
4
|
-
test('getExpForLevel', () => {
|
|
5
|
-
expect(getExpForLevel(1)).toBe(0);
|
|
6
|
-
expect(getExpForLevel(2)).toBe(83);
|
|
7
|
-
expect(getExpForLevel(10)).toBe(1154);
|
|
8
|
-
expect(getExpForLevel(99)).toBe(SKILL_EXP_AT_99);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('getLevel', () => {
|
|
12
|
-
expect(getLevel(SKILL_EXP_AT_99)).toBe(99);
|
|
13
|
-
expect(getLevel(110_000)).toBe(50);
|
|
14
|
-
expect(getLevel(getExpForLevel(67))).toBe(67);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('getCombatLevel', () => {
|
|
18
|
-
expect(getCombatLevel(1, 1, 1, 1, 1, 10, 1)).toBe(3);
|
|
19
|
-
expect(getCombatLevel(1, 1, 1, 1, 1, 10, 99)).toBe(15);
|
|
20
|
-
expect(getCombatLevel(99, 99, 99, 99, 99, 99, 99)).toBe(126);
|
|
21
|
-
expect(getCombatLevel(80, 87, 78, 80, 81, 85, 80)).toBe(105);
|
|
22
|
-
});
|
|
23
|
-
});
|
package/tests/groups.test.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { GroupRole, GROUP_ROLES, GroupRoleProps, findGroupRole } from '../src/groups';
|
|
2
|
-
|
|
3
|
-
describe('Util - Groups', () => {
|
|
4
|
-
test('Props', () => {
|
|
5
|
-
expect(GROUP_ROLES.some(t => !(t in GroupRoleProps))).toBe(false);
|
|
6
|
-
expect(Object.keys(GroupRole).length).toBe(Object.keys(GroupRoleProps).length);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('findGroupRole', () => {
|
|
10
|
-
expect(findGroupRole('artisan')).toBe(GroupRole.ARTISAN);
|
|
11
|
-
expect(findGroupRole('SCOUT')).toBe(GroupRole.SCOUT);
|
|
12
|
-
expect(findGroupRole('Other')).toBe(null);
|
|
13
|
-
});
|
|
14
|
-
});
|
package/tests/metrics.test.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
METRICS,
|
|
3
|
-
Metrics,
|
|
4
|
-
MetricProps,
|
|
5
|
-
findMetric,
|
|
6
|
-
Metric,
|
|
7
|
-
isSkill,
|
|
8
|
-
isBoss,
|
|
9
|
-
isActivity,
|
|
10
|
-
isVirtualMetric,
|
|
11
|
-
getMetricRankKey,
|
|
12
|
-
getMetricValueKey,
|
|
13
|
-
getMetricMeasure,
|
|
14
|
-
getMetricName,
|
|
15
|
-
getMinimumBossKc,
|
|
16
|
-
getParentVirtualMetric,
|
|
17
|
-
parseMetricAbbreviation,
|
|
18
|
-
MetricMeasure
|
|
19
|
-
} from '../src/metrics';
|
|
20
|
-
|
|
21
|
-
describe('Util - Metrics', () => {
|
|
22
|
-
test('Props', () => {
|
|
23
|
-
expect(METRICS.some(t => !(t in MetricProps))).toBe(false);
|
|
24
|
-
expect(Object.keys(Metrics).length).toBe(Object.keys(MetricProps).length);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('findMetric', () => {
|
|
28
|
-
expect(findMetric('AGILITY')).toBe(Metrics.AGILITY);
|
|
29
|
-
expect(findMetric('MAgiC')).toBe(Metrics.MAGIC);
|
|
30
|
-
expect(findMetric('Other')).toBe(null);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('isSkill', () => {
|
|
34
|
-
expect(isSkill('Other' as Metric)).toBe(false);
|
|
35
|
-
expect(isSkill(Metrics.ZULRAH)).toBe(false);
|
|
36
|
-
expect(isSkill(Metrics.LAST_MAN_STANDING)).toBe(false);
|
|
37
|
-
expect(isSkill(Metrics.WOODCUTTING)).toBe(true);
|
|
38
|
-
expect(isSkill(findMetric('Runecrafting') as Metric)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('isBoss', () => {
|
|
42
|
-
expect(isBoss('Other' as Metric)).toBe(false);
|
|
43
|
-
expect(isBoss(Metrics.WOODCUTTING)).toBe(false);
|
|
44
|
-
expect(isBoss(Metrics.LAST_MAN_STANDING)).toBe(false);
|
|
45
|
-
expect(isBoss(Metrics.ZULRAH)).toBe(true);
|
|
46
|
-
expect(isBoss(findMetric('Obor') as Metric)).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('isActivity', () => {
|
|
50
|
-
expect(isActivity('Other' as Metric)).toBe(false);
|
|
51
|
-
expect(isActivity(Metrics.WOODCUTTING)).toBe(false);
|
|
52
|
-
expect(isActivity(Metrics.ZULRAH)).toBe(false);
|
|
53
|
-
expect(isActivity(Metrics.LAST_MAN_STANDING)).toBe(true);
|
|
54
|
-
expect(isActivity(findMetric('Soul Wars Zeal') as Metric)).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('isVirtualMetric', () => {
|
|
58
|
-
expect(isVirtualMetric('Other' as Metric)).toBe(false);
|
|
59
|
-
expect(isVirtualMetric(Metrics.WOODCUTTING)).toBe(false);
|
|
60
|
-
expect(isVirtualMetric(Metrics.LAST_MAN_STANDING)).toBe(false);
|
|
61
|
-
expect(isVirtualMetric(Metrics.EHP)).toBe(true);
|
|
62
|
-
expect(isVirtualMetric(findMetric('EHB') as Metric)).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('getMetricRankKey', () => {
|
|
66
|
-
expect(getMetricRankKey(Metrics.EHP)).toBe('ehpRank');
|
|
67
|
-
expect(getMetricRankKey(Metrics.ZALCANO)).toBe('zalcanoRank');
|
|
68
|
-
expect(getMetricRankKey(Metrics.WOODCUTTING)).toBe('woodcuttingRank');
|
|
69
|
-
expect(getMetricRankKey(Metrics.SOUL_WARS_ZEAL)).toBe('soul_wars_zealRank');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('getMetricValueKey', () => {
|
|
73
|
-
expect(getMetricValueKey(Metrics.EHP)).toBe('ehpValue');
|
|
74
|
-
expect(getMetricValueKey(Metrics.ZALCANO)).toBe('zalcanoKills');
|
|
75
|
-
expect(getMetricValueKey(Metrics.WOODCUTTING)).toBe('woodcuttingExperience');
|
|
76
|
-
expect(getMetricValueKey(Metrics.SOUL_WARS_ZEAL)).toBe('soul_wars_zealScore');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('getMetricMeasure', () => {
|
|
80
|
-
expect(getMetricMeasure(Metrics.EHP)).toBe(MetricMeasure.VALUE);
|
|
81
|
-
expect(getMetricMeasure(Metrics.ZALCANO)).toBe(MetricMeasure.KILLS);
|
|
82
|
-
expect(getMetricMeasure(Metrics.WOODCUTTING)).toBe(MetricMeasure.EXPERIENCE);
|
|
83
|
-
expect(getMetricMeasure(Metrics.SOUL_WARS_ZEAL)).toBe(MetricMeasure.SCORE);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('getMetricName', () => {
|
|
87
|
-
expect(getMetricName(Metrics.EHP)).toBe('EHP');
|
|
88
|
-
expect(getMetricName(Metrics.ZALCANO)).toBe('Zalcano');
|
|
89
|
-
expect(getMetricName(Metrics.WOODCUTTING)).toBe('Woodcutting');
|
|
90
|
-
expect(getMetricName(Metrics.SOUL_WARS_ZEAL)).toBe('Soul Wars Zeal');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('getMinimumBossKc', () => {
|
|
94
|
-
expect(getMinimumBossKc(Metrics.ATTACK)).toBe(0);
|
|
95
|
-
expect(getMinimumBossKc(Metrics.ZALCANO)).toBe(50);
|
|
96
|
-
expect(getMinimumBossKc(Metrics.TZTOK_JAD)).toBe(10);
|
|
97
|
-
expect(getMinimumBossKc(Metrics.TZKAL_ZUK)).toBe(2);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('getParentVirtualMetric', () => {
|
|
101
|
-
expect(getParentVirtualMetric(Metrics.EHP)).toBe(null);
|
|
102
|
-
expect(getParentVirtualMetric(Metrics.ZALCANO)).toBe(Metrics.EHB);
|
|
103
|
-
expect(getParentVirtualMetric(Metrics.WOODCUTTING)).toBe(Metrics.EHP);
|
|
104
|
-
expect(getParentVirtualMetric(Metrics.SOUL_WARS_ZEAL)).toBe(null);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('parseMetricAbbreviation', () => {
|
|
108
|
-
expect(parseMetricAbbreviation('')).toBe(null);
|
|
109
|
-
expect(parseMetricAbbreviation('agility')).toBe(Metrics.AGILITY);
|
|
110
|
-
expect(parseMetricAbbreviation('SIRE')).toBe(Metrics.ABYSSAL_SIRE);
|
|
111
|
-
expect(parseMetricAbbreviation('corp')).toBe(Metrics.CORPOREAL_BEAST);
|
|
112
|
-
});
|
|
113
|
-
});
|
package/tests/numbers.test.ts
DELETED
package/tests/periods.test.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PERIODS,
|
|
3
|
-
Period,
|
|
4
|
-
PeriodProps,
|
|
5
|
-
findPeriod,
|
|
6
|
-
isValidPeriod,
|
|
7
|
-
parsePeriodExpression
|
|
8
|
-
} from '../src/periods';
|
|
9
|
-
|
|
10
|
-
describe('Util - Periods', () => {
|
|
11
|
-
test('Props', () => {
|
|
12
|
-
expect(PERIODS.some(t => !(t in PeriodProps))).toBe(false);
|
|
13
|
-
expect(Object.keys(Period).length).toBe(Object.keys(PeriodProps).length);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('findPeriod', () => {
|
|
17
|
-
expect(findPeriod('week')).toBe(Period.WEEK);
|
|
18
|
-
expect(findPeriod('MONTH')).toBe(Period.MONTH);
|
|
19
|
-
expect(findPeriod('Other')).toBe(null);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('isValidPeriod', () => {
|
|
23
|
-
expect(isValidPeriod('week')).toBe(true);
|
|
24
|
-
expect(isValidPeriod('WEEK')).toBe(false);
|
|
25
|
-
expect(isValidPeriod('Other')).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('parsePeriodExpression', () => {
|
|
29
|
-
expect(parsePeriodExpression('week')).toEqual({
|
|
30
|
-
expression: 'week',
|
|
31
|
-
durationMs: PeriodProps[Period.WEEK].milliseconds
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(parsePeriodExpression('3w')).toEqual({
|
|
35
|
-
expression: '3w',
|
|
36
|
-
durationMs: 3 * PeriodProps[Period.WEEK].milliseconds
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(parsePeriodExpression('1y2m3w')).toEqual({
|
|
40
|
-
expression: '1y2m3w',
|
|
41
|
-
durationMs:
|
|
42
|
-
PeriodProps[Period.YEAR].milliseconds +
|
|
43
|
-
2 * PeriodProps[Period.MONTH].milliseconds +
|
|
44
|
-
3 * PeriodProps[Period.WEEK].milliseconds
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(parsePeriodExpression('other')).toEqual(null);
|
|
48
|
-
});
|
|
49
|
-
});
|
package/tests/players.test.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PLAYER_TYPES,
|
|
3
|
-
PLAYER_BUILDS,
|
|
4
|
-
PlayerTypeProps,
|
|
5
|
-
PlayerBuildProps,
|
|
6
|
-
PlayerType,
|
|
7
|
-
PlayerBuild,
|
|
8
|
-
findPlayerType,
|
|
9
|
-
findPlayerBuild,
|
|
10
|
-
sanitizeUsername,
|
|
11
|
-
standardizeUsername
|
|
12
|
-
} from '../src/players';
|
|
13
|
-
|
|
14
|
-
describe('Util - Players', () => {
|
|
15
|
-
test('Props', () => {
|
|
16
|
-
expect(PLAYER_TYPES.some(t => !(t in PlayerTypeProps))).toBe(false);
|
|
17
|
-
expect(Object.keys(PlayerType).length).toBe(Object.keys(PlayerTypeProps).length);
|
|
18
|
-
|
|
19
|
-
expect(PLAYER_BUILDS.some(t => !(t in PlayerBuildProps))).toBe(false);
|
|
20
|
-
expect(Object.keys(PlayerBuild).length).toBe(Object.keys(PlayerBuildProps).length);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('findPlayerType', () => {
|
|
24
|
-
expect(findPlayerType('Hardcore')).toBe(PlayerType.HARDCORE);
|
|
25
|
-
expect(findPlayerType('ultimate')).toBe(PlayerType.ULTIMATE);
|
|
26
|
-
expect(findPlayerType('Other')).toBe(null);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('findPlayerBuild', () => {
|
|
30
|
-
expect(findPlayerBuild('F2P')).toBe(PlayerBuild.F2P);
|
|
31
|
-
expect(findPlayerBuild('level 3')).toBe(PlayerBuild.LVL3);
|
|
32
|
-
expect(findPlayerBuild('Other')).toBe(null);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('sanitizeUsername', () => {
|
|
36
|
-
expect(sanitizeUsername(' IRON Mammal_ ')).toBe('IRON Mammal');
|
|
37
|
-
expect(sanitizeUsername(' __PSIKOI')).toBe('PSIKOI');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('standardizeUsername', () => {
|
|
41
|
-
expect(standardizeUsername(' IRON Mammal_ ')).toBe('iron mammal');
|
|
42
|
-
expect(standardizeUsername(' __PSIKOI')).toBe('psikoi');
|
|
43
|
-
});
|
|
44
|
-
});
|
package/tests/strings.test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { formatNumber, padNumber } from '../src/strings';
|
|
2
|
-
|
|
3
|
-
describe('Util - Strings', () => {
|
|
4
|
-
test('formatNumber', () => {
|
|
5
|
-
expect(formatNumber(1.234)).toBe('1.23');
|
|
6
|
-
expect(formatNumber(5.1)).toBe('5.1');
|
|
7
|
-
|
|
8
|
-
expect(formatNumber(500)).toBe('500');
|
|
9
|
-
expect(formatNumber(1000)).toBe('1,000');
|
|
10
|
-
expect(formatNumber(10_000)).toBe('10,000');
|
|
11
|
-
expect(formatNumber(100_000)).toBe('100,000');
|
|
12
|
-
expect(formatNumber(1_000_000)).toBe('1,000,000');
|
|
13
|
-
|
|
14
|
-
expect(formatNumber(-1000, true)).toBe('-1,000');
|
|
15
|
-
expect(formatNumber(10_000, true)).toBe('10k');
|
|
16
|
-
expect(formatNumber(9_123_000, true)).toBe('9123k');
|
|
17
|
-
expect(formatNumber(-10_500_000, true)).toBe('-10.5m');
|
|
18
|
-
expect(formatNumber(1_123_456_000, true)).toBe('1.12b');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('padNumber', () => {
|
|
22
|
-
expect(padNumber(0)).toBe('00');
|
|
23
|
-
expect(padNumber(1)).toBe('01');
|
|
24
|
-
expect(padNumber(10)).toBe('10');
|
|
25
|
-
expect(padNumber(123)).toBe('123');
|
|
26
|
-
});
|
|
27
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["es6", "dom", "es2017"],
|
|
4
|
-
"target": "es5",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"noImplicitAny": false,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"outDir": "dist",
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"declaration": true
|
|
14
|
-
},
|
|
15
|
-
"exclude": ["node_modules", "dist", "tests"]
|
|
16
|
-
}
|